php 运行php脚本的Supervisord“预期退出状态1”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28937722/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Supervisord "exit status 1 not expected" running php script
提问by Luciano
I'm having issue try to configure supervisor to run a php script. Running supervisor in debug mode gives me this:
我在尝试配置主管以运行 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
The supervisord configuration:
监管者配置:
[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"
For this test myScript.php just print out echo "test".PHP_EOL;
对于这个测试 myScript.php 只需打印出来 echo "test".PHP_EOL;
There are no logs reporting errors from php, and if I run the script thru cli it works as expected. The supervisord log just report the same output as debuggin.
没有日志报告来自 php 的错误,如果我通过 cli 运行脚本,它会按预期工作。supervisord 日志只报告与 debuggin 相同的输出。
I've also tried using absolute paths like /usr/bin/php /home/path/to/script/myScript.php
but nothing changes.
我也试过使用绝对路径,/usr/bin/php /home/path/to/script/myScript.php
但没有任何变化。
File permission for myScript.php are set to -rwxrwxr-x 1 root apache
myScript.php 的文件权限设置为 -rwxrwxr-x 1 root apache
Really don't know what else i could check. Thanks for support!
真的不知道我还能检查什么。感谢你的支持!
UPDATE_1
更新_1
I've also tried to monitor other program like /bin/cat or a bash script and works like a charm. The problem seems to be limited to php.
我还尝试监视其他程序,如 /bin/cat 或 bash 脚本,并且效果很好。问题似乎仅限于php。
UPDATE_2
更新_2
As N.B. pointed out in the comments i've changed the test script to look more like long-running-job:
正如 NB 在评论中指出的那样,我已将测试脚本更改为看起来更像长期运行的工作:
while(true){
echo "test".PHP_EOL;
sleep(10);
}
Same as before, it enters in FATAL state.
和以前一样,它进入 FATAL 状态。
回答by skroczek
The only way I could reproduce this behaviour with exit code 1 is to use a invalid path to the file. So first please double check if the path is correct. But I think you have done this before.
我可以使用退出代码 1 重现此行为的唯一方法是使用无效的文件路径。所以首先请仔细检查路径是否正确。但我认为你以前已经这样做了。
I more assume that the file is located under your home directory and the root user is not able access and run it. So I would try to change the location of the script.
我更假设该文件位于您的主目录下,并且 root 用户无法访问和运行它。所以我会尝试更改脚本的位置。
For testing, you can place your script under /tmp/myScript.php
:
为了进行测试,您可以将脚本放在以下位置/tmp/myScript.php
:
cp /home/path/to/script/myScript.php /tmp/myScript.php
and modify your supervisord config like this:
并像这样修改您的 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"
Now supervisored should be able to run your script.
现在 supervisord 应该能够运行你的脚本。
If this is working, you should check which folder prevent root from accessing the script. This could be caused by an encypted (and mounted) folder (home dir?), or if the location is mounted from else where (samba, nfs ...). To solve the issue you can try to change the user from root to your user (I would not recommend this) or change the project location to another folder, which is not located under your home dir.
如果这有效,您应该检查哪个文件夹阻止 root 访问脚本。这可能是由加密(并安装)的文件夹(主目录?)引起的,或者如果该位置是从其他位置(samba、nfs ...)安装的。要解决此问题,您可以尝试将用户从 root 更改为您的用户(我不建议这样做)或将项目位置更改为另一个文件夹,该文件夹不在您的主目录下。
回答by N.B.
I've been using Supervisord for a while and this is what I have in my config:
我已经使用 Supervisord 一段时间了,这就是我的配置:
[program:worker1]
command=php /absolute/path/to/myScript.php
Reason I'm writing this as an anwser is due to formatting.
我写这个作为 anwser 的原因是由于格式。
Also, try this script:
另外,试试这个脚本:
for(i = 0; i < 10; i++)
{
printf("\nIteration: %d", $i);
usleep(1000 * 200); // 200 milliseconds between each printf
}
exit;
And add it to supervision. It should be restarted after it does its echoing.
并将其添加到监督中。它应该在完成回显后重新启动。
回答by Andy Wong
Try to set startsecs = 0
:
尝试设置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.
启动秒数
启动后程序需要保持运行以认为启动成功的总秒数。如果程序在启动后没有停留这么多秒,即使它以“预期的”退出代码(参见退出代码)退出,也会认为启动失败。设置为 0 表示程序不需要在任何特定的时间内保持运行。