Supervisord “exit status 1 not expected”运行PHP脚本。

10 浏览
0 Comments

Supervisord “exit status 1 not expected”运行PHP脚本。

我正在尝试配置supervisor运行php脚本,但遇到了问题。以debug模式运行supervisor会出现以下结果:

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

我的supervisord配置为:

[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

真的不知道还有什么可以检查的。感谢支持!

更新_1

我还尝试监视其他程序,例如/bin/cat或bash脚本,表现出色。问题似乎仅限于php。

更新_2

正如N.B.在评论中提到的那样,我已更改测试脚本以看起来更像长时间运行的作业:

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

与之前相同,它进入致命状态。

admin 更改状态以发布 2023年5月24日
0
0 Comments

尝试将startsecs = 0设置为:

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

startsecs

程序启动后必须保持运行的总秒数,以使启动成功被认为是成功的。如果程序在启动后未能保持运行超过此秒数,即使它以“预期”的退出代码(参见exitcodes)退出,启动也将被视为失败。将它设置为0表示程序不需要保持运行任何特定的时间。

0
0 Comments

我唯一能通过退出代码1来复现这种行为的方式是使用无效的文件路径。所以首先请仔细检查路径是否正确。但我觉得你之前已经这样做了。

我更认为文件位于你的主目录下,而根用户无法访问和运行它。因此,我会尝试更改脚本的位置。

进行测试,你可以把你的脚本放在/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"

现在supervisored应该能够运行你的脚本。

如果这个方法可以解决,你应该检查哪个文件夹阻止了根用户访问脚本。这可能是由加密(和挂载的)文件夹(主目录?)引起的,或者位置从其他地方(samba,nfs…)挂载。

要解决此问题,您可以尝试将用户从root更改为您的用户(我不建议这样做),或将项目位置更改为另一个文件夹,该文件夹不位于您的主目录下。

0