Upstart 进程被列为停止/等待

Upstart 进程被列为停止/等待

我有这个新贵脚本

当我运行时:sudo start poxa它启动了该过程,但是当我运行时:initctl list它显示它是,stop/waiting但是当我检查ps aux | grep poxa它时显示该过程。

并且,正如预期的那样,当我尝试停止它时,sudo stop poxa它返回:stop: unknown instance:

# Upstart Configuration
# put on /etc/init
description     "Poxa"
author          "Poxa"

start on (filesystem or runlevel [2345])
stop on runlevel [!2345]

#respawn
#respawn limit 10 5
umask 022

console none

pre-start script
    test -x /home/ec2-user/poxa/rel/poxa/bin/poxa || { stop; exit 0; }
end script

pre-stop script
        echo "[`date -u +%Y-%m-%dT%T.%3NZ`] Stoping..." >> /var/log/poxa.log 2>&1
end script

script
        export HOME=/home/ec2-user
        echo "[`date -u +%Y-%m-%dT%T.%3NZ`] Starting..." >> /var/log/poxa.log 2>&1
        exec /home/ec2-user/poxa/rel/poxa/bin/poxa start >> /var/log/poxa.log 2>&1
end script

ps aux | grep poxa

root     29032  0.0  0.1  13656  1720 ?        S    11:42   0:00 /usr/local/lib/erlang/erts-7.0/bin/run_erl -daemon /home/ec2-user/poxa/rel/poxa/tmp/erl_pipes/poxa/ /home/ec2-user/poxa/rel/poxa/log exec "/home/ec2-user/poxa/rel/poxa/bin/poxa" "console"
root     29033  0.3  2.0 318992 21100 pts/1    Ssl+ 11:42   0:00 /usr/local/lib/erlang/erts-7.0/bin/beam -- -root /home/ec2-user/poxa/rel/poxa -progname home/ec2-user/poxa/rel/poxa/releases/0.4.3/poxa.sh -- -home /home/ec2-user -- -boot /home/ec2-user/poxa/rel/poxa/releases/0.4.3/poxa -boot_var ERTS_LIB_DIR /usr/local/lib/erlang/erts-7.0/../lib -config /home/ec2-user/poxa/rel/poxa/running-config/sys.config -pa /home/ec2-user/poxa/rel/poxa/lib/consolidated -name [email protected] -setcookie
poxa -user Elixir.IEx.CLI -extra --no-halt +iex -- console

我做了这个:http://upstart.ubuntu.com/cookbook/#how-to-establish-fork-count得到叉数但它返回44

答案1

Upstart守护进程有三种守护进程模式no expectexpect forkexpect daemon6.13.5 错误指定预期的影响

正如您在那里看到的,您需要检查进程分叉数。

如果插入expect fork,则该"exec /home/ec2-user/poxa/rel/poxa/bin/poxa start"进程需要fork一次和exit。此外,它还需要fork两次和exit。upstartexpect daemon将使用trace最后一个子进程的 pid。

要使用 upstart 脚本正确运行守护进程,您需要检查fork进程poxa

以下是我针对 upstart 和简单守护进程的示例。

新贵脚本/etc/init

# egservice - eg daemon
#
# This is an example
# upstart script.

description    "egservice"

start on runlevel [2345]
stop on runlevel [!2345]
#LOOK Following line, So egdaemon needs to fork just once.
expect fork
respawn

exec /sbin/egdaemon

egdaemon.c为了/sbin/egdaemon

#include <stdio.h>

int main()
{
    /* LOOK following line, just once fork and main does not wait child and die, 
    so new child will be changed to a init's child and also a daemon. */
    int pid = fork();
    if (pid == 0) {
        while (1) {
            printf("Example daemon\n");
            sleep(1);
        }
    }
    return 0;
}

并且可以使用以下命令将该 C 源文件编译为可执行二进制文件。

$ gcc -o egdaemon egdaemon.c

答案2

您可以检查添加expect fork(以下umask 022行)是否有帮助。如果 poxa 二进制文件进入后台,这应该有助于 upstart 跟踪 pid。

相关内容