Possible Duplicate:
Keep SSH Sessions running after disconnection.
I have a process which is basically a web-server, I start it during an SSH session. However, when I leave the session (by closing the PuTTY windows), it stops running and responding to requests. This is true even if I end the command with a &. With Apache, I don’t have this problem, it comes with a stop, a start, and a restart script. I’d like to create something like that for this program.
How can I start a process, so that it will continue running even after I end the SSH session I started it in?
Also how can I set it to restart itself if it stops for some reason?
Thanks!
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Start it in a screen session.
screen
Now start the process:
myprocess
Then, detach the screen session with Ctrl+a d.
You can reattach to the screen session again by typing:
screen -r
If you have more sessions running you can list them with:
screen -ls
Method 2
You can make it a daemon (fork it twice or have it started by the system’s init daemon) or for temporary stuff use screen.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0