I've got a couple of servers on my Ubuntu that need to be restart-proof daemonized. How can I do that with generic init first process? Should I swap to upstart or some other replacement?
6 Answers
The existing SysInit system would handle that for you just fine. Ubuntu has docs on what they are doing with these. Yes, they are switching to upstart.

- 14,536
- 1
- 51
- 88
If your programs are running in the foreground, I suggest Runit, which is a replacement for the previously-mentioned daemontools, and is also a replacement for Sys-V style init. On Ubuntu, Runit is available as a package and has the necessary scripts to be started at system boot by Upstart.
We use Runit for all non-system-installed packages, such as Rails applications, so we don't have to manage init scripts; we just pop the startup command in the appropriate 'run' script, and let it go. This simplifies deployment of arbitrary new programs that need to start at boot time, and is a very robust and reliable system, eschewing the need to manage PID and lockfiles, since Runit handles that.

- 7,587
- 2
- 34
- 42
-
As an aside, runit has much better documentation than Ubuntu's "upstart" init system and thus I find it much easier to work with. – jtimberman Sep 13 '10 at 16:05
Daemontools is absolutely awesome for this sort of thing. KISS-grade simple, robust, and encourages good practices in related areas (logging, etc).
You can use xinetd for this, if the process is network based. Otherwise, upstart and sysvinit are your tools.

- 14,342
- 20
- 77
- 129
daemonize : www.clapper.org/software/daemonize/ can handle this by wrapping your code in a C wrapper that daemonizes before executing.
You can also simply add them to the /etc/inittab . Many will (perhaps rightly) say this is evil because no-one will think to look there, I have seen production systems that use this technique and the truth is it works well.
Maybe you could look into monit as well, it can make sure processes are running and restart them if necessary. It was built with the Linux-HA environment in mind though.
Normally I hand make a new init script for each new process but I don't normally deploy 4 or 5 scripts at once like that. Maybe think about how they are structured and put them under one init script which is the service that they provide.

- 2,172
- 2
- 18
- 23
"@reboot" is a valid macro in Ubuntu's default cron daemon (vixie-cron 4.x if I remember correctly). So launching a daemon can be as simple as
crontab -e
@reboot /usr/local/bin/daemon
That will make your daemon come up after a reboot, but assumes that your daemon doesn't die of its own accord. You could also make use of "keep-one-running" which I think is going to be a default package included as of 11.10 ("@reboot /usr/bin/keep-one-running /usr/local/bin/daemon").
edit - oh, old question which reappeared on the active tab for whatever reason...

- 459
- 2
- 8