Supervisord "exit status 1 not expected" 运行 php 脚本

Supervisord "exit status 1 not expected" running php script

我在尝试将主管配置为 运行 php 脚本时遇到问题。 运行 调试模式下的主管给我这个:

2015-03-09 08:53:06,342 INFO supervisord started with pid 2030
2015-03-09 08:53:06,358 INFO spawned: 'worker1' with pid 2031
2015-03-09 08:53:06,423 INFO exited: worker1 (exit status 1; not expected)
2015-03-09 08:53:06,424 INFO received SIGCLD indicating a child quit
2015-03-09 08:53:07,440 INFO spawned: 'worker1' with pid 2032
2015-03-09 08:53:07,587 INFO exited: worker1 (exit status 1; not expected)
2015-03-09 08:53:07,589 INFO received SIGCLD indicating a child quit
2015-03-09 08:53:09,604 INFO spawned: 'worker1' with pid 2033
2015-03-09 08:53:09,756 INFO exited: worker1 (exit status 1; not expected)
2015-03-09 08:53:09,758 INFO received SIGCLD indicating a child quit
2015-03-09 08:53:12,775 INFO spawned: 'worker1' with pid 2034
2015-03-09 08:53:12,973 INFO exited: worker1 (exit status 1; not expected)
2015-03-09 08:53:12,974 INFO received SIGCLD indicating a child quit
2015-03-09 08:53:13,976 INFO gave up: worker1 entered FATAL state, too many start retries too quickly

监督配置:

[program:worker1]
command=php myScript.php
directory=/home/path/to/script/
user=root
autostart=true
autorestart=true
stderr_logfile=/var/log/worker1.err.log
stdout_logfile=/var/log/worker1.out.log
redirect_stderr=true
environment=PATH="/usr/bin"

对于此测试myScript.php 只需打印出echo "test".PHP_EOL;

php 没有报告错误的日志,如果我 运行 通过 cli 脚本,它会按预期工作。 supervisord 日志只报告与 debuggin 相同的输出。

我也试过使用像 /usr/bin/php /home/path/to/script/myScript.php 这样的绝对路径,但没有任何改变。

myScript.php 的文件权限设置为 -rwxrwxr-x 1 root apache

真的不知道我还能检查什么。感谢支持!

UPDATE_1

我也尝试过监控其他程序,例如 /bin/cat 或 bash 脚本,效果非常好。问题似乎仅限于 php.

UPDATE_2

为N.B。在评论中指出,我已经将测试脚本更改为看起来更像 long-运行ning-job:

while(true){
    echo "test".PHP_EOL;
    sleep(10);
}

和之前一样,进入FATAL状态

我使用 Supervisord 有一段时间了,这是我的配置:

[program:worker1]
command=php /absolute/path/to/myScript.php

我之所以将其写成答案是因为格式问题。

另外,试试这个脚本:

for(i = 0; i < 10; i++)
{
    printf("\nIteration: %d", $i);
    usleep(1000 * 200); // 200 milliseconds between each printf
}

exit;

并将其添加到监督中。它应该在回显后重新启动。

我可以使用退出代码 1 重现此行为的唯一方法是使用无效的文件路径。所以首先请仔细检查路径是否正确。但我想你以前做过。

我更假设该文件位于您的主目录下并且 root 用户无法访问并且 运行 它。所以我会尝试更改脚本的位置。

为了测试,您可以将脚本放在 /tmp/myScript.php:

cp /home/path/to/script/myScript.php /tmp/myScript.php

并像这样修改你的 supervisord 配置:

[program:worker1]
command=php myScript.php
directory=/tmp/
user=root
autostart=true
autorestart=true
stderr_logfile=/var/log/worker1.err.log
stdout_logfile=/var/log/worker1.out.log
redirect_stderr=true
environment=PATH="/usr/bin"

现在监督者应该可以运行你的脚本了。

如果这有效,您应该检查哪个文件夹阻止 root 访问该脚本。这可能是由加密(和挂载)的文件夹(主目录?)引起的,或者如果该位置是从其他位置(samba、nfs ...)挂载的。 要解决此问题,您可以尝试将用户从 root 更改为您的用户(我不建议这样做)或将项目位置更改为另一个文件夹,该文件夹不在您的主目录下。

尝试设置startsecs = 0:

[program:foo]
command = ls
startsecs = 0
autorestart = false
http://supervisord.org/configuration.html

startsecs

The total number of seconds which the program needs to stay running after a startup to consider the start successful. If the program does not stay up for this many seconds after it has started, even if it exits with an “expected” exit code (see exitcodes), the startup will be considered a failure. Set to 0 to indicate that the program needn’t stay running for any particular amount of time.

如果您 运行 主管命令 docker -it exec ... 并得到 exit status 1; not expected,您应该尝试删除 -it。更多内容