我制作了一个 LSBized 初始化脚本,它在启动时运行一些脚本,然后在脚本被杀死或关闭时重新启动它。
起初一切看起来都很好,但几分钟后 init 脚本停止,另一个脚本继续运行。
我在 /var/log/syslog 中收到此错误
Jun 9 14:53:49 debian systemd[1]: test.service start operation timed out. Terminating.
Jun 9 14:53:49 debian systemd[1]: Failed to start LSB: Start some script on boot and restarts it if it stops..
Jun 9 14:53:49 debian systemd[1]: Unit test.service entered failed state.
我的脚本如下所示:
#! /bin/sh
# /etc/init.d/test
#
### BEGIN INIT INFO
# Provides: $parentscript
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start some script on boot and restarts it if it stops.
# Description: Start some script on boot and restarts it if it stops.
### END INIT INFO
start() {
until /home/user/runthis; do
echo "Process crashed with exit code $?. Respawning.." >&2
sleep 1
done
}
# Carry out specific functions when asked to by the system
case "$1" in
start)
start
;;
stop)
echo "Stopping script test"
;;
*)
echo "Usage: /etc/init.d/test {start|stop}"
exit 1
;;
esac
exit 0
我在 Debian 8.0 x64 和 x86 上试过,这两种情况都会发生同样的事情。
有什么我做错了吗?或者有没有其他方法可以达到同样的效果?谢谢!