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?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
1 answer

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