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?

1
  • 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, 2012 at 0:08

3 Answers 3

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

1
  • I use screen but the script seems to be killed without any error.
    – donald
    Feb 26, 2012 at 22:35
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).

1
  • I use screen but the script seems to be killed without any error.
    – donald
    Feb 26, 2012 at 22:35
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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .