Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a VPS running a simple python scripts. However, sometimes the script crashes. How can I make sure the script starts agian?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

Run it via daemontools. It's a very simple, straightforward framework for doing exactly what you want -- it'll run the script and wait until it exits, and then start it again. It even takes care of the daemonisation, so you only have to write the script to run in the foreground, and daemontools handles all the tricky stuff. Comes with a neat stdout/stderr logging system, too, which handles the other usually-painful part of running a custom daemon.

share|improve this answer
    
I don't see how to use daemontools with a python script. It seems to work with bash scripts? cr.yp.to/daemontools/supervise.html –  donald Mar 21 '12 at 20:05
    
@donald - scripts in *nix are identified by the interpreter you ask it to use in the first line. Eg: #!/bin/sh, #!/bin/env ruby, etc. –  Shyam Sundar C S Mar 21 '12 at 20:22
    
@donald: As @CS3 mentioned, you can use anything you like -- daemontools just wants to run a file named run in the service directory. I usually use a bash wrapper script to set the user and redirect stderr, then run the program (in whatever language it's written in) via exec. –  womble Mar 22 '12 at 1:41
add comment

Your Answer

 
discard

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.