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.
Auto restart apps on file change If an application is started with the --watch option, stopping the app will not prevent it to be restarted on file change. To totally disable the watch feature, do: pm2 stop app --watch or toggle the watch option on application restart via pm2 restart app --watch .
PM2 allows to reload (auto fallback to restart if not in cluster) an application based on a memory limit/ Please note that the PM2 internal worker (which checks memory), starts every 30 seconds, so you may have to wait a bit before your process gets restarted automatically after reaching the memory threshold.
PM2 will keep your application forever alive, auto-restarting across crashes and machine restarts.
Check if your app modifies a file in the project folder (such as a log file). A change to any of the files triggers restart if watch
flag is enabled.
To prevent this, use a process
file and add watch_ignore
flag in it.
Here's a documentation on how to use the process file: PM2 - Process File
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With