Running python app in the background on linux
Weird question here, but I'm playing with a python chat server/client combo on my Linux server. Currently, if I do this:
$: cd /path/to/chat/server
$: sudo python ChatServer_Listen.py
This starts the python app run loop and the server listens for incoming TCP connections.
My problem is, if I close my terminal window, the ssh session quits and the python app stops running, and clients can no longer connect. I'd rather not run a terminal instance 24/7 locally. Can I set up this python app as something that can run in the background on Linux? If so, how? Ideally it would be sort of like Apache which just runs as a service.
Thanks for helping me out!
You can use nohup python ChatServer_Listen.py &
nohup
will log your program output to nohup.out
file.
To stop your program you have to use kill your_pid
command.
You want to use Supervisor. It's made exactly for this purpose, plus it will do things like restart the process if it dies, provide a web-based GUI to control it, etc.
An easy way to keep a process alive after you log off is to use screen.
Like explained here :
https://stackoverflow.com/questions/625409/how-do-i-put-an-already-running-process-under-nohup
"
Using the Job Control of bash to send the process into the background:
[crtl]+z
bg
And as Sam/Jan mentioned you have to execute disown to avoid killing the process after you close the terminal.
disown -h
"