Hi all
We have all seen the problem that some script or bot we have come to rely upon suddenly dies. Or fails to restart when the toolserver is rebooted. Putting something into cron to be run on @reboot sadly doesn't always work, for example because the home directory may not yet be mounted when cron runs reboot jobs.
So, after a short discussion on IRC, i wrote a script to take care of this. I called if phoenix, it's available in the system path on nightshade and hemlock.
Phonix just starts whatever command you give to it, but it first checks if that command is already running. If it is already running, phoenix does nothing. So, just call phonix from cron every few minutes to make sure your bot is restarted when it dies.
For example, if you want to run 'mybot', call this every few minutes from cron:
phoenix /tmp/yourname-mybot /home/mydir/bin/mybot someparam
The path /tmp/yourname-mybot is the base fir the PID and output files - output fill be written to /tmp/yourname-mybot.out, the processes pid will be stored in /tmp/yourname-mybot.pid.
The second parameter, /home/mydir/bin/mybot, is the program to run. Anything following that are parameters to pass to this program.
Please try it out and tell me about any problems! phoenix also prints a short help message when called without any parameters.
-- daniel
PS: I'm sure this wheel has been invented before... any pointers?
On Sat, Oct 18, 2008 at 7:26 AM, Daniel Kinzler daniel@brightbyte.de wrote:
Hi all
We have all seen the problem that some script or bot we have come to rely upon suddenly dies. Or fails to restart when the toolserver is rebooted. Putting something into cron to be run on @reboot sadly doesn't always work, for example because the home directory may not yet be mounted when cron runs reboot jobs.
We should have a per-user initialisation script that are all run during startup by rc.local.
So, after a short discussion on IRC, i wrote a script to take care of this. I called if phoenix, it's available in the system path on nightshade and hemlock.
Phonix just starts whatever command you give to it, but it first checks if that command is already running. If it is already running, phoenix does nothing. So, just call phonix from cron every few minutes to make sure your bot is restarted when it dies.
For example, if you want to run 'mybot', call this every few minutes from cron:
phoenix /tmp/yourname-mybot /home/mydir/bin/mybot someparam
The path /tmp/yourname-mybot is the base fir the PID and output files - output fill be written to /tmp/yourname-mybot.out, the processes pid will be stored in /tmp/yourname-mybot.pid.
The second parameter, /home/mydir/bin/mybot, is the program to run. Anything following that are parameters to pass to this program.
Please try it out and tell me about any problems! phoenix also prints a short help message when called without any parameters.
-- daniel
PS: I'm sure this wheel has been invented before... any pointers?
[[init]] is the original program given this task, and is still often used for this purpose. The wiki page lists other tools that have been written to help with this.
svscan from [[daemontools]] is a good one.
-- John Vandenberg
John Vandenberg schrieb:
We should have a per-user initialisation script that are all run during startup by rc.local.
You can get the same result using the @boot trigger in cron. In reality, though, this often fails, because home dirs may bit yet be mounted (or may have failed to mount) when this is run.
[[init]] is the original program given this task, and is still often used for this purpose. The wiki page lists other tools that have been written to help with this.
Init can be used to automatically relaunch programs that died, or that failed to start during boot? How?
svscan from [[daemontools]] is a good one.
supervise from daemontools seems to be the closer match. It seems to provide the functionality I was looking for, however, it appears to require a specific setup, specifically, one directory per service, with a ./run script in it. That's a bit inconvenient.
The closest match yet was start-stop-daemon, which Multichil suggested on IRC. That does pretty much the same thing as phoenix does, with a heap more options. I wish I had found it earlier :) Oh well, reinventing wheels is educational.
In any case, I don't care much which tools you use -- of you have bots that should be "always up", please use supervise run it from cron via start-stop-daemon or phoenix, so it gets (re)launched automatically.
-- daniel
Hi,
2008/10/18 Daniel Kinzler daniel@brightbyte.de:
John Vandenberg schrieb:
[[init]] is the original program given this task, and is still often used for this purpose. The wiki page lists other tools that have been written to help with this.
Init can be used to automatically relaunch programs that died, or that failed to start during boot? How?
"respawn - The process will be restarted whenever it terminates"
Bye, Tim.
PS: I still owe you a reply for another mail. Haven't forget it.
toolserver-l@lists.wikimedia.org