I've been looking up information on running background processes on Linux. The basic requirements are:
- Start the process and keep it running no matter what happens
- If the process quits for whatever reason, immediately relaunch it
- Be able to launch the process as a specific user
Additionally, some processes need to be run not continuously, but periodically. This is of course a job for cron, and more than likely it's what I'll use for that. But for continuous processes, it's a different story.
On Mac OS X, I use launchd for this purpose. Launchd is the canonical method for launching processes on Mac OS X. The operating system uses it for ALL system services, so I have no qualms about relying on it. So far I haven't found a similar system for Linux. Various distros all seem to have their own methods (Ubuntu's upstart, etc.) and I still can't find a straight answer on how /etc/rc.local, /etc/init.d/rc.local, /etc/initd/rc.local, or /etc/init all relate and what the difference is between them. They're different on every system. Add to that the fact that "service start/stop x" doesn't work on all systems (and Google hasn't helped here) and you have what I'd call a mess.
What I want is ONE place I can save my scripts where I can reboot the system and have them launched as daemons at boot (before any user logs in), then have them automatically restarted if they ever terminate. And I want it to be rock solid reliable and fully compatible with multiple distros, not some afterthought like upstart.
Is this even possible?
/etc/init.d/yourdaemon stop
then the daemon should automatically restart without any intervention of the administrator?