Does PM2 have a command to start a new process or restart existing one if the process's name is the same?

2k Views Asked by At

I'm using codeship to autodeploy my nextjs app from github. My deployment script is as follows

ssh user@SERVER_IP 'cd projectfolder/; git checkout master; git pull; npm run build; pm2 delete app; pm2 start npm --name "app" -- start;'

If I don't delete the process first the app will be duplicated with the next push.

This config works fine, but I'm kinda not sure about that deleting thing, since I found that there is a cleaner command like startOrRestart that will start a new one or restart existing process with the same name. I couldn't get it working though.

2

There are 2 best solutions below

2
Rico Chen On

It should be very easy with pm2 restart appName, in your case you only need to run

npm restart app

every time you need to restart your application, given that you initially start your application with

pm2 start npm --name app -- start
0
Michelle On

If you're still having issue, feel free to contact CodeShip Support!

Best, -M