我有一个我在linux中创建的守护进程。我创建了init.d文件并使用
成功启动了守护进程/etc/init.d/mydaemon start
当我试图阻止它(使用/etc/init.d/mydaemon停止)时,它会成功停止,但启动 - 停止 - 守护程序似乎永远不会完成,因为在调用启动后没有立即出现回声-stop-守护程序
详细模式显示它停止了该过程,并且查看系统监视器,它确实停止了该过程。
Stopped mydaemon (pid 13292 13310).
这是我的init.d文件的停止功能。
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 --name $NAME -v
echo "stopped"#This is never printed and the script never formally gives shell back.
RETVAL="$?"
[ "$RETVAL" = 2 ] && return 2
# Wait for children to finish too if this is a daemon that forks
# and if the daemon is only ever run from this initscript.
# If the above conditions are not satisfied then add some other code
# that waits for the process to drop all resources that could be
# needed by services started subsequently. A last resort is to
# sleep for some time.
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.
return "$RETVAL"
}
我在虚拟机上运行它,这会影响到什么吗?
答案 0 :(得分:0)
在虚拟机上运行不应该影响这一点 我不知道为什么会发生这种情况或者它是如何接管父脚本的。
然而,我刚刚遇到这个问题并发现如果我这样做:
start-stop-daemon ...&& echo -n
它将按预期工作并放弃对shell的控制。
我不知道为什么会这样,但它似乎有效。