Supervisord "exit status 1 not expected" running PHP script

I have a problem setting up a supervisor to run a php script. Running the supervisor in debug mode gives me the following:

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 

Supervisor 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 echo "test".PHP_EOL;

Logs do not report errors from php, and if I run thru cli script, it works as expected. The supervisor log just reports the same output as debuggin.

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

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

I don’t really know what else I could check. Thanks for the support!

UPDATE_1

I also tried to control another program like / bin / cat, or bash script and it works like a charm. The problem is apparently limited to php.

UPDATE_2

As NB in ​​the comments, I modified the test script to look more like a long run:

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

As before, it enters the FATAL state.

+5
source share
3 answers

The only way to reproduce this behavior with exit code 1 is to use an invalid file path. So first check if the path is correct. But I think you did it before.

I assume the file is under your home directory and the root user cannot access and run it. So I will try to change the location of the script.

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

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

and reconfigure your supervisor as follows:

 [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 the supervisor should be able to run the script.

If this works, you should check in which folder root access to the script is denied. This can be caused by an encrypted (and installed) folder (home dir?), Or if the location is set from another location (samba, nfs ...). To solve the problem, you can try changing the user from root to user (I would not recommend this) or changing the location of the project in another folder that is not under your home registry.

+8
source

I have been using Supervisord for a while, and this is what I have in my configuration:

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

Reason I write this as anwser due to formatting.

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 the supervision. It must be restarted after its echo.

0
source

try setting startecs = 0:

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

startsecs

The total number of seconds during which the program must remain on after starting to consider the start successful. If the program does not stop for many seconds after its launch, even if it exits with the "expected" exit code (see Exit Codes), the start will be considered a failure. Set to 0 to indicate that the program should not run for a certain period of time.

0
source

All Articles