I have a VPS running a simple python scripts. However, sometimes the script crashes. How can I make sure the script starts agian?
Asked
Active
Viewed 2,437 times
1 Answers
2
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.

womble
- 96,255
- 29
- 175
- 230
-
I don't see how to use daemontools with a python script. It seems to work with bash scripts? http://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 01:41