[MTOS-dev] Daemonizing a process?

Finn Smith fcsmith at gmail.com
Fri Jan 18 19:06:24 PST 2008


On Jan 17, 2008 10:09 PM, Byrne Reese <byrne at sixapart.com> wrote:
> Does anyone know how I can bootstrap publish queue with a daemon monitoring
> service or tool? Doesn't linux have some way that I can allow for the
> process to be restarted if for some reason it dies?
>
> What is this called? And is there a link that you can share that can show me
> how to do it?

(1) Daemonizing some perl code: The perl modules posted earlier are
probably a good start to this.
(2) Integrating said daemon into the standard Linux run levels: Each
Linux distribution handles this a little bit differently, but usually
what happens is you write a start/stop script that can be used to
manage the daemon in step (1), you put this script somewhere under
/etc/ (often init.d) and then you use whatever tool the distribution
includes to place the correct symlinks in the various rc.d directories
under /etc. Then as the system enters and leaves run levels, the
daemon is turned stopped/started accordingly. You should check the
docs for whatever distro you're running.
(3) Restarting a daemon/process that dies: Usually done with some sort
of a monitoring script or utility. One method, as mentioned, would be
to run a cron job that checks every few minutes and relaunches the
daemon if needed. monit (http://www.tildeslash.com/monit/) is a great
monitoring utility which can do things like monitor a specific pid,
check that ports are open and accepting connections, check memory and
cpu usage, etc. and then take a specified response. I'd note that if a
daemon is regularly dying, that's usually considered a bug.

-F


More information about the MTOS-dev mailing list