我试图复制 /etc/init.d/skeleton 并对其进行修改以在后台启动程序。我想出了以下内容:
do_start()
{
# Return
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
start-stop-daemon --start --quiet --pidfile $PIDFILE -b --make-pidfile --exec $DAEMON --test > /dev/null \
|| return 1
start-stop-daemon --start --quiet --pidfile $PIDFILE -b --make-pidfile --exec $DAEMON -- \
$DAEMON_ARGS \
|| return 2
}
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
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
RETVAL="$?"
[ "$RETVAL" = 2 ] && return 2
start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
[ "$?" = 2 ] && return 2
# Many daemons don't delete their pidfiles when they exit.
rm -f $PIDFILE
return "$RETVAL"
}
我对此有一个问题和几个问题。我的问题是,无论该守护程序是否已经运行,启动函数都会启动一个守护程序并返回 0。我的问题是在第一次 --test 开始时是否需要 -b 和 --make-pidfile 。我是否正确假设 do_stop 中的第一个命令向守护进程发送一个 TERM 信号,而第二个命令强制杀死守护进程?在这种情况下,我将不得不等待守护进程退出。