2

I have an Ubuntu 12.04 installation and a PHP script I want to re-run as soon as it terminates. I'm using upstart and this myscript.conf in /etc/init/:

start on startup
stop on shutdown
exec php5 /var/myscript.php
respawn

I can run my script using start myscript, which works fine one-time, but I can't get the script to respawn once it terminates.

Is there something special I have to pay attention to when trying to respawn a PHP script?

Max Min
  • 121
  • 3
  • 1
    I just added sleep(5) to the beginning of my PHP script and it now respawns as expected. I'm not sure why this help, but it does. – Max Min Feb 18 '13 at 17:27
  • Had the same experience, and `sleep(5)` is exactly how I fixed it as well. I actually answered another question with a [more thorough example](http://stackoverflow.com/questions/2036654/run-php-script-as-daemon-process/16577806#16577806) of my Upstart script. – Jonathan May 16 '13 at 02:13

1 Answers1

2

You can update your script very easy when you have a startscript under /etc/init.d

update-rc.d myscript defaults

But then you need a startscript. You can checkout the skeleton script (/etc/init.d/skeleton) and copy the script. Then you can change the params and run your programm.

like this: /etc/init.d/myscript start

In the startscript you can kill the process if its not terminating correct.

René Höhle
  • 26,716
  • 22
  • 73
  • 82