By lidistat67
So as I said in the title it’s very simple. I connect to my droplet with SSH then, I start a process for example with PM2 and I close the SSH connection. Will the PM2 process still run or will it get terminated?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hi @lidistat67,
The PM2 process shouldn’t terminate itself upon your exit.
Having said that, there is another solution which I believe it’s always considered good practice to be executed and that’s using SCREEN.
This is for situations where you perform a long-running task on a remote machine, and suddenly your connection drops, the SSH session is terminated, and your work is lost.
Starting Linux Screen To start a screen session, simply type screen in your console:
screen
This will open a screen session, create a new window, and start a shell in that window.
You can start any command there as with your normal shell. Once you do start it and you want to leave the command as it is, you just need to press
CTRL + A
CTRL + D
This will detach your screen session and return you to your initial bash window.
To return to your screen session, you’ll first need to check it’s ID. You can see the ID by executing the below
screen -ls
Then to re-enter your screen session type in
screen -r IDNumberHere
Alternatively, PM2 is the tool for some long-running tasks. I just wanted to present you with an example.
Regards, KFSys
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.