Python daemon

Joseph A Knapka jknapka at earthlink.net
Wed Jun 26 23:25:26 CEST 2002


Steve Holden wrote:
> 
> "Cameron Laird" <claird at starbase.neosoft.com> wrote ...
> > In article <mailman.1024999953.15765.python-list at python.org>,
> > Roman Suzi  <rnd at onego.ru> wrote:
> > .
> > .
> > .
> > >> 3. restarting of the program if it fails, or the watchdog doesn't
> trigg=
> > >er
> > >
> > >Run the program from the /etc/inittab - if it terminates,=20
> > >init will restart it for you.
> > .
> > .
> > .
> > This is one of the great FMMs under Unix--the under-utilization
> > of init(1).  From everything I know, Roman's exactly right, that
> > /etc/inittab is the right way to set up a process that you truly
> > want to keep running.  However, many, MANY Unix hosts have all
> > kinds of ugly home-brewed hacks to duplicate this functionality.
> > I don't have an explanation, beyond the rather tautologous ob-
> > servation that init(1) simply isn't as widely understood as it
> > deserves to be.
> 
> You're probably right. Don't forget you need to specify "respawn" to have
> the process restarted when it terminates.
> 
> Of course, this doesn't address the issue of if the controlled process stops
> making progress but doesn't die.

Normally I'd allow wiser heads to address such issues,
but surprisingly none of them have directly answered
this question thus far, so here goes:

Just ensure that your daemon touches a file, say
/var/run/<daemonname>.doggy, every N seconds. Another
job run from cron attempts to delete
/var/run/<daemonname>.doggy every 2*N seconds. If
that fails, it does

"kill `cat /var/run/<daemonname>.pid`"

and then init restarts the daemon.

-- Joe
   "They call them the Diamond Dogs."
   -- David Bowie, "Diamond Dogs"



More information about the Python-list mailing list