[Baypiggies] Dumb "keep it running" script
Seth Friedman
sfseth at gmail.com
Wed Sep 23 22:01:57 CEST 2009
has anyone around here looked at the linux 'supervise' stuff to accomplish
this?
http://cr.yp.to/daemontools.html
~s
On Wed, Sep 23, 2009 at 12:43 PM, Brent Pedersen <bpederse at gmail.com> wrote:
> On Wed, Sep 23, 2009 at 12:02 PM, Benjamin Sergeant <bsergean at gmail.com>
> wrote:
> > Hi there,
> >
> > I figured out this morning that I had a long-running process that died
> > one week ago for some obscure reasons. I made a little script that
> > restarts a script when the called script die. I know there are already
> > existing stuff doing that but I could not remember the name / find any
> > existing ones ... so why not re-inventing the wheel one more time :)
> >
> > Thanks for any feedback,
> > - Benjamin
> >
> > http://code.activestate.com/recipes/576911/
> > #!/usr/bin/env python
> >
> > import sys
> > import time
> > import subprocess
> >
> > """
> > Keep a process up and running
> >
> > If you have a long running process that can be killed for strange and
> unknown
> > reason, you might want it to be restarted ... this script does that.
> >
> > $ cat alive.sh
> > #!/bin/sh
> >
> > while `true`; do echo Alive && sleep 3 ; done
> >
> > Use it like this:
> > $ keepup.py ./alive.sh
> > """
> >
> > cmd = ' '.join(sys.argv[1:])
> >
> > def start_subprocess():
> > return subprocess.Popen(cmd, shell=True)
> >
> > p = start_subprocess()
> >
> > while True:
> >
> > res = p.poll()
> > if res is not None:
> > print p.pid, 'was killed, restarting it'
> > p = start_subprocess()
> >
> > time.sleep(1)
> > _______________________________________________
> > Baypiggies mailing list
> > Baypiggies at python.org
> > To change your subscription options or unsubscribe:
> > http://mail.python.org/mailman/listinfo/baypiggies
> >
>
> there's also the monitor option in paste serve. check out
> restart_with_monitor() in
> http://svn.pythonpaste.org/Paste/Script/trunk/paste/script/serve.py
> which you could crib from or use directly.
> _______________________________________________
> Baypiggies mailing list
> Baypiggies at python.org
> To change your subscription options or unsubscribe:
> http://mail.python.org/mailman/listinfo/baypiggies
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/baypiggies/attachments/20090923/a5890ff3/attachment.htm>
More information about the Baypiggies
mailing list