[Baypiggies] Dumb "keep it running" script

Ryan Bowlby rbowlby83 at yahoo.com
Wed Sep 23 22:34:58 CEST 2009


*nix:  http://cr.yp.to/daemontools.html - the original
Mac:   Launchd - daemon monitoring perfected
Linux: inittab (respawn) - already running, so no additional process overhead. Includes logging, etc.

You thought you would be safe from these replies with your "reinventing wheel" disclaimer...sorry I couldn't help it.

-Ryan


--- On Wed, 9/23/09, Benjamin Sergeant <bsergean at gmail.com> wrote:

> From: Benjamin Sergeant <bsergean at gmail.com>
> Subject: [Baypiggies] Dumb "keep it running" script
> To: "Baypiggies" <baypiggies at python.org>
> Date: Wednesday, September 23, 2009, 3:02 PM
> 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
> 


      


More information about the Baypiggies mailing list