当前位置:网站首页>systemd如何使用/etc/init.d脚本
systemd如何使用/etc/init.d脚本
2022-04-21 06:19:00 【lingedeng】
1. 以apport为例,将/etc/init.d/apport拷贝并生成新的myapport, 内容如下:
#! /bin/sh
### BEGIN INIT INFO
# Provides: myapport
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop:
# Short-Description: myapport init.d with systemd test"
### END INIT INFO
DESC="myapport init.d with systemd test"
NAME=myapport
SCRIPTNAME=/etc/init.d/$NAME
# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions
#
# Function that starts the daemon/service
#
do_start()
{
# Return
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
echo "myapport started"
return 0
}
#
# Function that stops the daemon/service
#
do_stop()
{
# Return
# 0 if daemon has been stopped
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred
echo "myapport stopped"
return 0
}
case "$1" in
start)
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC:" "$NAME"
do_start
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
stop)
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC:" "$NAME"
do_stop
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
restart|force-reload)
$0 stop || true
$0 start
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
exit 3
;;
esac
2. 在/etc/rc?.d任意一个中(?取值2 3 4 5),建立符号链接,指向/etc/init.d/myapport
lrwxrwxrwx 1 root root 18 9月 29 16:43 S01myapport -> ../init.d/myapport
注:如果不建立相关的符号链接,则表示该SysV服务没有启用,则在系统启动时不会执行。
3. 重启机器后查看myapport服务相关的信息
$ systemctl status myapport
● myapport.service - LSB: myapport init.d with systemd test"
Loaded: loaded (/etc/init.d/myapport; generated)
Active: inactive (dead) since Wed 2021-09-29 16:56:23 CST; 6s ago
Docs: man:systemd-sysv-generator(8)
Process: 2771 ExecStop=/etc/init.d/myapport stop (code=exited, status=0/SUCCESS)
Process: 979 ExecStart=/etc/init.d/myapport start (code=exited, status=0/SUCCESS)
9月 29 16:54:25 eric-vm-dev systemd[1]: Starting LSB: myapport init.d with systemd test"...
9月 29 16:54:29 eric-vm-dev myapport[979]: * Starting myapport init.d with systemd test: myapport
9月 29 16:54:29 eric-vm-dev myapport[979]: myapport started
9月 29 16:54:29 eric-vm-dev myapport[979]: ...done.
9月 29 16:54:29 eric-vm-dev systemd[1]: Started LSB: myapport init.d with systemd test".
$ systemctl list-unit-files | grep myapport
myapport.service generated
注:generated表示该服务单元是由systemd-sysv-generator应用程序生成。
$ systemctl cat myapport
# /run/systemd/generator.late/myapport.service
# Automatically generated by systemd-sysv-generator
[Unit]
Documentation=man:systemd-sysv-generator(8)
SourcePath=/etc/init.d/myapport
Description=LSB: myapport init.d with systemd test"
Before=graphical.target
After=remote-fs.target
[Service]
Type=forking
Restart=no
TimeoutSec=5min
IgnoreSIGPIPE=no
KillMode=process
GuessMainPID=no
RemainAfterExit=yes
SuccessExitStatus=5 6
ExecStart=/etc/init.d/myapport start
ExecStop=/etc/init.d/myapport stop
参考:
版权声明
本文为[lingedeng]所创,转载请带上原文链接,感谢
https://blog.csdn.net/lingedeng/article/details/120552350
边栏推荐
- 语义的特征提取及简单词频展示(WordCloud)
- 用JS函數形式實現一個Array.prototype.forEach(),.map(),.filter()
- stm32mp157 wm8960音频驱动调试笔记
- If I use Monet's color matching in scientific research pictures?
- canvas 绘制路飞
- Reproduce the 3D density function diagram in the top issue of SCI
- 【Labview】记录下做Labview项目的一些坑点
- Write tweets for one year and share five commonly used writing software
- How to quickly "liver" high-quality slides? Recommend a latex typesetting artifact
- 【STM32&LWIP】记录一次诡异的ping不通的解决方法
猜你喜欢

win10的jupyter notebook使用pyspark2.3.2解决的报错问题

数据异构方案

用JS函數形式實現一個Array.prototype.forEach(),.map(),.filter()

Making books with bookdown

R language drawing | drawing mixed density function diagram and adding quantile line

【KSZ8863】KSZ8863交换机芯片的信息汇总与打板验证结果

记一次mySQL慢sql优化

"Fundamentals of digital electronic technology" 4.3 learning notes of some commonly used combinational logic circuits

How does excel form become latex format?

手势识别调研
随机推荐
vee-validate 验证
记一次mySQL慢sql优化
Chapter 5 support vector machine (SVM)
TP下载文件夹,压缩文件夹并下载
uniapp中动态底部导航栏tabbar实现,权限管理
Sql 按照指定内容排序
利用Jlink命令行进行程序下载和数据提取
Tensorflow实例3: 验证码图片的识别训练,每张图片有4个字母
R communication | typora font color setting
If I use Monet's color matching in scientific research pictures?
vscode 自定义注释
导jstl标签库uri没有提示
How does excel form become latex format?
做一款自己的小程序
const关键字、变量、函数用const修饰
3. Date command problem in bat
SQL数据库语法学习笔记
[w5500] STM32 h743 drives w5500 for UDP transceiver
MySQL Workbench cannot use clear text authentication over non-ssl connections 问题解决
Write tweets for one year and share five commonly used writing software
https://unix.stackexchange.com/questions/233468/how-does-systemd-use-etc-init-d-scripts