![]() You can add a line in there to have myserver start at a certain init level and be respawned automatically. Then add a rule to start your monitor script: /usr/local/bin/myservermonitorĪlternatively look at inittab(5) and /etc/inittab. Open your cron rules with crontab: crontab -e If you want to start the monitor on boot (making the server "survive" reboots), you can schedule it in your user's cron(1) with an rule. Now all you need to do is start this bash script (asynchronously, probably), and it will monitor myserver and restart it as necessary. The sleep 1 takes away the strain from that. Why do we wait a second? Because if something's wrong with the startup sequence of myserver and it crashes immediately, you'll have a very intensive loop of constant restarting and crashing on your hands. If the exit status is not 0, until will run the loop body, which emits an error message on STDERR and restarts the loop (back to line 1) after 1 second. In that case we don't want to restart it (we just asked it to shut down!). If the exit status is 0, it means it ended gracefully (which means you asked it to shut down somehow, and it did so successfully). When it ends, until checks its exit status. The first line starts myserver and waits for it to end. The above piece of bash code runs myserver in an until loop. until myserver doĮcho "Server 'myserver' crashed with exit code $?. What does this mean? It means only the process that starts your process can reliably wait for it to end. Instead you need the process that monitors your process to be the process' parent. ) that tries to work around that is flawed and has gaping holes in it. Any method (ps parsing, pgrep, storing a PID. There is a very good reason why in UNIX, you can ONLY wait on your children. Avoid PID-files, crons, or anything else that tries to evaluate processes that aren't their children.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |