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


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.

  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.