0

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.

Andrei
  • 1
  • 4

2 Answers2

0

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
Rico Chen
  • 2,260
  • 16
  • 18
  • This command won't work if I don't have the app running. I was looking for a solution with the logic "start the app if there is no app with the same name; if there is is then restart". – Andrei Sep 03 '19 at 14:29
  • 1
    After you start your app with `pm2 start npm --name app -- start`, run `pm2 save`, from that on your can keep using `npm restart app` – Rico Chen Sep 03 '19 at 19:40
0

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

Best, -M

Michelle
  • 31
  • 1