10

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

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;

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.

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

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

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

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);
}

Same as before, it enters in FATAL state.

Luciano
  • 1,455
  • 8
  • 22
  • 52
  • You saying nothing in "worker1.err.log" ? – MegaAppBear Mar 09 '15 at 08:29
  • Nope, nothing. It's not even created... – Luciano Mar 09 '15 at 08:40
  • have you tried the full path to script in the "command" line? – MegaAppBear Mar 09 '15 at 08:42
  • Yep, tried running it like: /usr/bin/php /home/path/to/script/myScript.php. No difference. – Luciano Mar 09 '15 at 08:45
  • redirect_stderr is redirecting to you stdout, I take it there's nothing in your stdout as well? – MegaAppBear Mar 09 '15 at 08:49
  • Nothing even on stdout. :( – Luciano Mar 09 '15 at 08:52
  • Your script just echoes something and then it stops. Supervisord is supposed to monitor long-running programs, like web servers and similar which read data from a socket and they don't exit immediately. Your script echoes and exits instantly. Supervisor tries to boot it back, just so the script can exit again - and Supervisord correctly stops doing so because otherwise it would hammer your CPU forever. What's the point of such a script and having it supervised? – N.B. Mar 10 '15 at 09:06
  • @N.B.: i've updated the question, nothing even with a while(true) loop. – Luciano Mar 10 '15 at 10:43
  • verify the file permissions for /usr/bin/php, and with which user the Supervisord is running – Halayem Anis Mar 17 '15 at 19:11

4 Answers4

14

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.

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.

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

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

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.

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.

skroczek
  • 2,289
  • 2
  • 16
  • 23
  • your solution works, i've just moved the file in the tmp directory! But even if i run supervisor with my user under the original location, it doesn't work. I'll try to figure out moving the script outside the home folder... Thanks for help! – Luciano Mar 21 '15 at 20:05
  • This was very helpful thank you! I was using the supervisor conf to run a bash script (to avoid path problems) and was missing both change user and change directory – Rich Ross Jun 03 '17 at 10:55
1

Try to set 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.

lloiacono
  • 4,714
  • 2
  • 30
  • 46
Andy Wong
  • 3,676
  • 1
  • 21
  • 18
0

I've been using Supervisord for a while and this is what I have in my config:

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

Reason I'm writing this as an anwser is 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 supervision. It should be restarted after it does its echoing.

N.B.
  • 13,688
  • 3
  • 45
  • 55
0

If you run supervisor command like docker -it exec ... and got exit status 1; not expected you should try to remove -it. More here https://stackoverflow.com/a/43099210/3664772

sha
  • 1
  • 1