Supervisord“预期退出状态 1"运行php脚本 [英] Supervisord "exit status 1 not expected" running php script

查看:18
本文介绍了Supervisord“预期退出状态 1"运行php脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试配置主管以运行 php 脚本时遇到问题.在调试模式下运行主管给了我这个:

I'm having issue try to configure supervisor to run a php script. Running supervisor in debug mode gives me this:

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 配置:

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"

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

For this test myScript.php just print out echo "test".PHP_EOL;

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

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.

我也尝试过使用绝对路径,如 /usr/bin/php/home/path/to/script/myScript.php 但没有任何变化.

I've also tried using absolute paths like /usr/bin/php /home/path/to/script/myScript.php but nothing changes.

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

File permission for myScript.php are set to -rwxrwxr-x 1 root apache

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

Really don't know what else i could check. Thanks for support!

UPDATE_1

我还尝试监视其他程序,例如/bin/cat 或 bash 脚本,并且效果很好.问题似乎仅限于php.

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.

UPDATE_2

作为 N.B.在评论中指出我已经将测试脚本更改为看起来更像长期运行的工作:

As N.B. pointed out in the comments i've changed the test script to look more like long-running-job:

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

和之前一样,进入FATAL状态.

Same as before, it enters in FATAL state.

推荐答案

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

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.

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

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.

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

For testing, you can place your script under /tmp/myScript.php:

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

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

and modify your supervisord config like this:

[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.

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

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.

这篇关于Supervisord“预期退出状态 1"运行php脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆