3

I have a script running python script.py in a new screen but sometimes the script gets killed:

18
21
Restarting processes... done
2
Killed

How can I protect the script from being killed even when I close the console? Shall I use & or nohup?

donald
  • 453
  • 1
  • 6
  • 17
  • Are you the sole administrator of the system? I just did a quick test and that "Killed" output is not what is displayed when you send Python a `SIGKILL` or `SIGTERM`. – Kyle Smith Feb 27 '12 at 00:08

3 Answers3

1

I would recommend adding this code to your script http://code.activestate.com/recipes/278731-creating-a-daemon-the-python-way/

Or use screen.

Edit: This is a little more modern but I haven't used it(I use something custom) http://pypi.python.org/pypi/python-daemon

Publiccert
  • 1,110
  • 1
  • 8
  • 22
0

Do you mean it is running inside a GNU screen session? In this case, it shouldn't get killed unless there is some problem with the script and it terminates due to this problem.

If you don't use screen, use start using it or tmux (which I like more).

Sven
  • 97,248
  • 13
  • 177
  • 225
0

A modern way to do it is using of the systemd. You just create the unit of service with type=Simple without any screen/tmux, and set the restart=always option to restart script at any unexpected exits.

Instead of the screen/tmux you also can use the start-stop-daemon - native tool for debian based systems to demonize applications. But restarting at exit you should implement with third-party tools like the monit.

Anton Danilov
  • 4,874
  • 2
  • 11
  • 20