I have deployed an express.js app on a Azure server. I use pm2 for process management.
The issue is pm2 keeps restarting almost every seconds.
staging@Server:/srv/apps/myapp/current$ pm2 list
┌──────────┬────┬──────┬───────┬────────┬─────────┬────────┬─────────────┬──────────┐
│ App name │ id │ mode │ pid │ status │ restart │ uptime │ memory │ watching │
├──────────┼────┼──────┼───────┼────────┼─────────┼────────┼─────────────┼──────────┤
│ app │ 0 │ fork │ 35428 │ online │ 0 │ 0s │ 20.465 MB │ disabled │
└──────────┴────┴──────┴───────┴────────┴─────────┴────────┴─────────────┴──────────┘
Use `pm2 show <id|name>` to get more details about an app
staging@Server:/srv/apps/myapp/current$ pm2 list
┌──────────┬────┬──────┬───────┬────────┬─────────┬────────┬─────────────┬──────────┐
│ App name │ id │ mode │ pid │ status │ restart │ uptime │ memory │ watching │
├──────────┼────┼──────┼───────┼────────┼─────────┼────────┼─────────────┼──────────┤
│ app │ 0 │ fork │ 35492 │ online │ 7 │ 0s │ 59.832 MB │ disabled │
└──────────┴────┴──────┴───────┴────────┴─────────┴────────┴─────────────┴──────────┘
Use `pm2 show <id|name>` to get more details about an app
staging@Server:/srv/apps/myapp/current$ pm2 list
┌──────────┬────┬──────┬───────┬────────┬─────────┬────────┬─────────────┬──────────┐
│ App name │ id │ mode │ pid │ status │ restart │ uptime │ memory │ watching │
├──────────┼────┼──────┼───────┼────────┼─────────┼────────┼─────────────┼──────────┤
│ app │ 0 │ fork │ 35557 │ online │ 13 │ 0s │ 21.816 MB │ disabled │
└──────────┴────┴──────┴───────┴────────┴─────────┴────────┴─────────────┴──────────┘
~/.pm2/pm2.log
2016-05-10 17:39:34: Starting execution sequence in -fork mode- for app name:start id:0
2016-05-10 17:39:34: App name:start id:0 online
2016-05-10 17:39:35: App [start] with id [0] and pid [3149], exited with code [255] via signal [SIGINT]
2016-05-10 17:39:35: Starting execution sequence in -fork mode- for app name:start id:0
2016-05-10 17:39:35: App name:start id:0 online
2016-05-10 17:39:35: App [start] with id [0] and pid [3158], exited with code [255] via signal [SIGINT]
2016-05-10 17:39:35: Starting execution sequence in -fork mode- for app name:start id:0
2016-05-10 17:39:35: App name:start id:0 online
2016-05-10 17:39:36: App [start] with id [0] and pid [3175], exited with code [255] via signal [SIGINT]
2016-05-10 17:39:36: Starting execution sequence in -fork mode- for app name:start id:0
I am using coffee script in my application. And starting the app using pm2 start app.coffee
package.json
{
"name": "myapp",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "gulp start-server"
},
"dependencies": {
"bcrypt-nodejs": "0.0.3",
"body-parser": "~1.13.2",
"co": "^4.6.0",
"coffee-script": "^1.10.0",
"connect-mongo": "^1.1.0",
"cookie-parser": "~1.3.5",
"debug": "~2.2.0",
"express": "~4.13.1",
"express-session": "^1.13.0",
"gulp": "^3.9.1",
"mongoose": "^4.4.14",
"morgan": "~1.6.1",
"newrelic": "^1.26.2",
"passport": "^0.3.2",
"passport-local": "^1.0.0",
"pm2": "^1.1.3",
"pug": "^2.0.0-alpha6",
"request": "^2.72.0",
"serve-favicon": "~2.3.0"
},
"devDependencies": {
"shipit-cli": "^1.4.1",
"shipit-deploy": "^2.1.3",
"shipit-npm": "^0.2.0",
"shipit-pm2-nginx": "^0.1.8"
}
}
I am new to node.js. May be I am not seeing the obvious. Please help me out.
pm2 writes application logs to ~/.pm2/logs
and pm2 specific logs to pm2.log
by default. We need to check both the locations to debug the issue.
One other way to debug application is by starting the application manually, ie., something like npm run start
or node path/yo/your/bin.js
It should give you the missing piece of information to fix the problem and move on.