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?
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?
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
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).
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.