I have Python script bgservice.py
and I want it to run all the time, because it is part of the web service I build. How can I make it run continuously even after I logout SSH?
views:
95answers:
5Run nohup python bgservice.py &
to get the script to ignore the hangup signal and keep running. Output will be put in nohup.out
.
Ideally, you'd run your script with something like supervise
so that it can be restarted if (when) it dies.
You could also use GNU screen which just about every Linux/Unix system should have.
If you are on Ubuntu/Debian, its enhanced variant byobu is rather nice too.
The zsh shell has an option to make all background processes run with nohup.
In ~/.zshrc
add the lines:
setopt nocheckjobs #don't warn about bg processes on exit
setopt nohup #don't kill bg processes on exit
Then you just need to run a process like so: python bgservice.py &
, and you no longer need to use the nohup command.
I know not many people use zsh, but it's a really cool shell which I would recommend.
If you've already started the process, and don't want to kill it and restart under nohup, you can send it to the background, then disown it.
Ctrl+Z
(suspend the process)
bg
(restart the process in the background
disown %1
(assuming this is job #1, use jobs
to determine)