Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

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.

share|improve this answer

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.

share|improve this answer
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).

share|improve this answer

You can use xinetd for this, if the process is network based. Otherwise, upstart and sysvinit are your tools.

share|improve this answer

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.

share|improve this answer

"@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...

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.