service – How to run a Python script in the background even after I logout SSH?

service – How to run a Python script in the background even after I logout SSH?

Run nohup python bgservice.py & to get the script to ignore the hangup signal and keep running. Output will be put in nohup.out.

Ideally, youd run your script with something like supervise so that it can be restarted if (when) it dies.

If youve already started the process, and dont 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)

service – How to run a Python script in the background even after I logout SSH?

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.

Leave a Reply

Your email address will not be published. Required fields are marked *