我試圖更新我的應用程序以將其與systemd結合使用。 當我用暴發戶,我剛剛創建/etc/init.d/myService腳本:systemd在ExecStop完成之前殺死我的進程
#!/bin/bash
#chkconfig: 2345 90 10
#description: myDescription
### BEGIN INIT INFO
# Provides: myService
# Required-Start: sshd
# Required-Stop: sshd
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start myService
# Description:
### END INIT INFO
SCRIPT=$(readlink -f $0)
lockfile="/var/lock/subsys/myService"
do_start() {
if [ -d "/var/lock/subsys" ]; then
touch $lockfile
fi
...
}
do_stop() {
...
if [ -d "/var/lock/subsys" ]; then
if [ -f "$lockfile" ]; then
rm -f $lockfile
fi
fi
}
do_status() {
...
}
case "$1" in
start)
do_start
exit 0
;;
stop)
do_stop
exit 0
;;
status)
do_status
exit 0
;;
restart)
do_stop
do_start
exit 0
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|status|restart}" >&2
exit 3
;;
esac
和所有被罰款。
通知,該腳本生成一些將在後臺執行的子進程。 要使用systemd使用它,我做了後續的服務文件(myService.service):
[Unit]
Description=My Description
Requires=sshd.service
After=sshd.service
Before=shutdown.target reboot.target halt.target
[Service]
Type=oneshot
ExecStart=/etc/init.d/myService start
ExecStop=/etc/init.d/myService stop
RemainAfterExit=yes
KillMode=none
[Install]
WantedBy=multi-user.target
如果我運行
systemctl stop myService.service
所有做工精細。我的應用程序通過/etc/init.d/myService stop命令成功停止。
但我已經得到了如下問題: 當我重新啓動系統,並/etc/init.d/myService停止正在執行的過程,我應該停止爲myService已經殺腳本。我應該控制許多流程(大約7個流程),而系統本身不應該終止它。
我試過使用Type = forking,並將PIDFile指定爲進程的pidfile,它具有最長的生命週期(應該先開始第一個結束),但是我的所有進程都被終止了。
是否有任何簡單的方法來避免殺死我的子進程?
您可以從非編程問題(例如Unix和Linux)中選擇一個更好的StackExchange WWW站點開始:http://unix.stackexchange.com/questions/204922/ – JdeBP
謝謝,我會試一試。 – Sild
這不是創建systemd單元的正確方法。你並不是想要調用你舊式的init/upstart腳本。做得對,你不會有任何問題。 –