pm2 running on EC2 using jenkins not working?

I am running my node application on AWS EC2 server. For continuous integration I installed Jenkins, on EC2, jenkins polls a code commit continuously and when a commit occurs executes some commands written in a script.

The last command is

pm2 start server.js

Everything works fine and the build is shown successful but later when I access the URL the site doesn't show.

I have a nginx server in front of node server, it gives 502 Bad Gateway

On checking I realised the node application is not running, so I cehcked pm2 logs and found this happening -

2016-08-12 07:53:28: [[[[ PM2/God daemon launched ]]]]

2016-08-12 07:53:28: BUS system [READY] on port /var/lib/jenkins/.pm2/pub.sock

2016-08-12 07:53:28: RPC interface [READY] on port /var/lib/jenkins/.pm2/rpc.sock

2016-08-12 07:53:28: Starting execution sequence in -fork mode- for app name:server id:0

2016-08-12 07:53:28: App name:server id:0 online

2016-08-12 07:53:28: pm2 has been killed by signal, dumping process list before exit...

2016-08-12 07:53:28: Deleting process 0

2016-08-12 07:53:28: Stopping app:server id:0

2016-08-12 07:53:28: App [server] with id [0] and pid [25822], exited with code [0] via signal [SIGTERM]

2016-08-12 07:53:28: Proc is not defined anymore or is being killed

2016-08-12 07:53:28: [PM2] Exited peacefully

pm2 is getting killed as soon as starting, don't know why, tried reinstalling pm2 from npm didn't work.

Ubuntu 14.04 LTS

Node v4.4.7 LTS

npm v2.15.8

pm2 v1.1.3

Work is halted, need help immediately, please.


  • The answer is in the comments given by Dusan Bajic, if anyone is doing continous integration with jenkins on EC2 using a node application and similar thing happens with pm2 just add this line in script before starting pm2.

    export BUILD_ID=dontKillMePlease

    and instead of

    pm2 start server.js


    pm2 restart server.js

    server.js being your application or else build will fail if in jenkins if you commit and it runs script again cause pm2 is already running server.js and won't stop.