Upstart 作业无法重生,并且在尝试停止/重新启动时挂起

Upstart 作业无法重生,并且在尝试停止/重新启动时挂起

我在 Ubuntu 12.04 中使用 Upstart 1.5 来管理某个用户创建的进程,但需要作为系统作业进行管理,如在启动时启动、如果失败则重新启动,并且我们能够在任何需要的时间启动/停止它,因此我在 /etc/init 中创建了它的 .conf 文件,如下所示:

description "Start face services recognition and monitors it"
version "1.0"
start on runlevel[5]
stop on runlevel[06]
respawn
expect fork
normal exit 0 TERM STOP
script
exec sh -c /home/verstand/facefeatures
end script
post-stop script
if [ ! $EXIT_STATUS && ! $EXIT_SIGNAL ]
then
exec sudo -u $USER "/sbin/shutdown -r now"  
fi
end script

这里的信号旨在当 Upstart 无法重生进程时,紧急情况下重新启动系统。

现在,问题是当我们启动该进程时,它运行良好,sudo initctl start facefeatures但是当我们尝试停止它时,它会挂起,我们需要使用 Ctl+C 来返回 tty 控制。甚至,如果我们尝试再次启动它或重新启动它,Upstart 会报告它已在运行:start/running facefeatures但是,如果我们使用initctl listUpstart 报告,就好像该进程已被终止一样:stop/killed facefeatures

另外,如果我们第一次重新启动,它会正常运行该过程,但如果我们第二次重新启动,它就不会再运行该过程......

我的 conf 文件有什么问题?正确的做法是什么?

答案1

如果面部特征不是脚本,那么我相信这是因为 upstart 不知道要监视哪个进程。请使用以下命令启动它:执行而不是脚本节:

description "Start face services recognition and monitors it"
version "1.0"
start on runlevel[5]
stop on runlevel[06]
normal exit 0 TERM STOP
expect fork
respawn
exec /home/verstand/facefeatures
post-stop script
    if [ ! $EXIT_STATUS && ! $EXIT_SIGNAL ]
    then
        exec sudo -u $USER "/sbin/shutdown -r now"  
    fi
end script

当停止服务时,您的程序将收到一个 TERM,如果它对该信号没有反应,它将在五秒后被杀死。

相关内容