Node app stops responding after some time - node.js

I recently pushed my node js and express server to the production.
After a few days of working on the production, I realized that sometimes with no reason my server stops responding for requests.
[31/Dec/2018:09:55:39 +0000] "GET /vehicles?user_lat=52.458876&user_lng=16.9006237 HTTP/1.1" - - ms
I was looking for an answer here but the only advice I found was to debug server and find out what is causing it crashes. Unfortunately, I am not able to find out where is the problem. I added listeners to the process to find unhandled promises rejection and uncaught exception but nothing was caught.
What I also found is when the server stops responding the CPU usage is
running high. Normally it takes 1-5%, but when it hangs it is around 20%.
The next strange thing for me is the output of pm2.log file. According to it, my server often restarts but I don't understand why.
pm2.log file:
2018-12-22T10:12:10: PM2 log: pid=28427 msg=process killed
2018-12-22T10:12:10: PM2 log: App [server:0] starting in -fork mode-
2018-12-22T10:12:10: PM2 log: App [server:0] online
2018-12-24T13:33:40: PM2 log: Stopping app:server id:0
2018-12-24T13:33:40: PM2 log: App [server:0] exited with code [0] via signal [SIGINT]
2018-12-24T13:33:41: PM2 log: pid=31380 msg=process killed
2018-12-24T13:33:41: PM2 log: App [server:0] starting in -fork mode-
2018-12-24T13:33:41: PM2 log: App [server:0] online
2018-12-24T13:45:29: PM2 log: Stopping app:server id:0
2018-12-24T13:45:29: PM2 log: App [server:0] exited with code [0] via signal [SIGINT]
2018-12-24T13:45:29: PM2 log: pid=5521 msg=process killed
2018-12-24T13:45:29: PM2 log: App [server:0] starting in -fork mode-
2018-12-24T13:45:29: PM2 log: App [server:0] online
2018-12-25T03:11:40: PM2 log: Stopping app:server id:0
2018-12-25T03:11:40: PM2 log: App [server:0] exited with code [0] via signal [SIGINT]
2018-12-25T03:11:40: PM2 log: pid=6049 msg=process killed
2018-12-25T03:11:40: PM2 log: App [server:0] starting in -fork mode-
2018-12-25T03:11:40: PM2 log: App [server:0] online
2018-12-27T05:07:30: PM2 log: Stopping app:server id:0
2018-12-27T05:07:30: PM2 log: App [server:0] exited with code [0] via signal [SIGINT]
2018-12-27T05:07:30: PM2 log: pid=11531 msg=process killed
2018-12-27T05:07:30: PM2 log: App [server:0] starting in -fork mode-
2018-12-27T05:07:30: PM2 log: App [server:0] online
2018-12-29T08:08:27: PM2 log: Stopping app:server id:0
2018-12-29T08:08:27: PM2 log: App [server:0] exited with code [0] via signal [SIGINT]
2018-12-29T08:08:27: PM2 log: pid=28263 msg=process killed
2018-12-29T08:08:27: PM2 log: App [server:0] starting in -fork mode-
2018-12-29T08:08:27: PM2 log: App [server:0] online
2018-12-29T09:41:23: PM2 log: Stopping app:server id:0
2018-12-29T09:41:23: PM2 log: App [server:0] exited with code [0] via signal [SIGINT]
2018-12-29T09:41:23: PM2 log: pid=11341 msg=process killed
2018-12-29T09:41:23: PM2 log: App [server:0] starting in -fork mode-
2018-12-29T09:41:23: PM2 log: App [server:0] online
2018-12-31T10:03:33: PM2 log: Stopping app:server id:0
2018-12-31T10:03:33: PM2 log: App [server:0] exited with code [0] via signal [SIGINT]
2018-12-31T10:03:33: PM2 log: pid=12337 msg=process killed
2018-12-31T10:03:33: PM2 log: App [server:0] starting in -fork mode-
2018-12-31T10:03:33: PM2 log: App [server:0] online
2018-12-31T10:48:51: PM2 log: Stopping app:server id:0
2018-12-31T10:48:51: PM2 log: App [server:0] exited with code [0] via signal [SIGINT]
2018-12-31T10:48:51: PM2 log: pid=28552 msg=process killed
2018-12-31T10:48:51: PM2 log: App [server:0] starting in -fork mode-
2018-12-31T10:48:51: PM2 log: App [server:0] online
On the production, I use pm2 to start my server.
Here is my server.js file:
var express = require('express'),
app = express(),
port = process.env.PORT || 3000;
const morgan = require('morgan');
const routes = require('./api/routes/main_routes');
const authMiddleware = require('./api/authorization/auth');
bodyParser = require('body-parser');
app.use(morgan(':remote-addr - :remote-user [:date[clf]] ":method :url
HTTP/:http-version" :status :response-time ms'))
app.use('/images', express.static(__dirname + '/markers'));
app.use('/cars', express.static(__dirname + '/cars'));
app.use('/video', express.static(__dirname + '/video'));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(authMiddleware)
routes(app); //register the routes
app.use(function (err, req, res, next) {
res.status(err.status || 500);
res.send(err.message);
});
process.on('unhandledRejection', (reason, p) => {
console.log("Unhandled Rejection at: Promise ", p, " reason: ",
reason);
});
process.on('uncaughtException', function (exception) {
console.log(exception);
});
app.listen(port);
console.log('server started on:' + port);
And package.json file:
{
"name": "api",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"start": "nodemon server.js"
},
"author": "",
"license": "ISC",
"devDependencies": {
"nodemon": "^1.11.0"
},
"dependencies": {
"axios": "^0.18.0",
"axios-cache-adapter": "^2.1.1",
"body-parser": "^1.17.2",
"cachios": "^2.0.0",
"cors": "^2.8.4",
"express": "^4.15.4",
"file-system": "^2.2.2",
"form-data": "^2.3.3",
"geolib": "^2.0.24",
"lodash": "^4.17.4",
"morgan": "^1.9.1",
"nodemon": "^1.18.6",
"path": "^0.12.7",
"sharp": "^0.18.4",
"websocket": "^1.0.28"
}
}
Full pm2 logs
/root/.pm2/pm2.log last 15 lines:
PM2 | 2018-12-29T09:41:23: PM2 log: Stopping app:server id:0
PM2 | 2018-12-29T09:41:23: PM2 log: App [server:0] exited with code [0] via signal [SIGINT]
PM2 | 2018-12-29T09:41:23: PM2 log: pid=11341 msg=process killed
PM2 | 2018-12-29T09:41:23: PM2 log: App [server:0] starting in -fork mode-
PM2 | 2018-12-29T09:41:23: PM2 log: App [server:0] online
PM2 | 2018-12-31T10:03:33: PM2 log: Stopping app:server id:0
PM2 | 2018-12-31T10:03:33: PM2 log: App [server:0] exited with code [0] via signal [SIGINT]
PM2 | 2018-12-31T10:03:33: PM2 log: pid=12337 msg=process killed
PM2 | 2018-12-31T10:03:33: PM2 log: App [server:0] starting in -fork mode-
PM2 | 2018-12-31T10:03:33: PM2 log: App [server:0] online
PM2 | 2018-12-31T10:48:51: PM2 log: Stopping app:server id:0
PM2 | 2018-12-31T10:48:51: PM2 log: App [server:0] exited with code [0] via signal [SIGINT]
PM2 | 2018-12-31T10:48:51: PM2 log: pid=28552 msg=process killed
PM2 | 2018-12-31T10:48:51: PM2 log: App [server:0] starting in -fork mode-
PM2 | 2018-12-31T10:48:51: PM2 log: App [server:0] online
/root/.pm2/logs/server-error.log last 15 lines:
/root/.pm2/logs/server-out.log last 15 lines:
0|server | ::ffff:127.0.0.1 - - [31/Dec/2018:16:11:27 +0000] "GET /images/marker_active.png HTTP/1.1" 200 0.849 ms
0|server | ::ffff:127.0.0.1 - - [31/Dec/2018:16:11:27 +0000] "GET /images/marker_active.png HTTP/1.1" 200 0.667 ms
0|server | ::ffff:127.0.0.1 - - [31/Dec/2018:16:11:27 +0000] "GET /images/marker_active.png HTTP/1.1" 200 0.567 ms
0|server | ::ffff:127.0.0.1 - - [31/Dec/2018:16:11:28 +0000] "GET /images/marker_inactive.png HTTP/1.1" 200 1.065 ms
0|server | ::ffff:127.0.0.1 - - [31/Dec/2018:16:11:28 +0000] "GET /images/marker_inactive.png HTTP/1.1" 200 1.302 ms
0|server | ::ffff:127.0.0.1 - - [31/Dec/2018:16:11:28 +0000] "GET /images/marker_inactive.png HTTP/1.1" 200 0.550 ms
0|server | ::ffff:127.0.0.1 - - [31/Dec/2018:16:11:28 +0000] "GET /images/marker_inactive.png HTTP/1.1" 200 0.566 ms
0|server | 211
0|server | ::ffff:127.0.0.1 - - [31/Dec/2018:16:11:30 +0000] "GET /vehicles?user_lat=52.14601814935841&user_lng=21.04796773265618&center_lng=21.047964502570746&center_lat=52.14602095031964 HTTP/1.1" 200 5357.940 ms
0|server | ::ffff:127.0.0.1 - - [31/Dec/2018:16:11:31 +0000] "GET /images/marker_active.png HTTP/1.1" 200 0.624 ms
0|server | ::ffff:127.0.0.1 - - [31/Dec/2018:16:11:31 +0000] "GET /images/marker_active.png HTTP/1.1" 200 0.613 ms
0|server | ::ffff:127.0.0.1 - - [31/Dec/2018:16:11:31 +0000] "GET /images/marker_inactive.png HTTP/1.1" 200 0.600 ms
0|server | ::ffff:127.0.0.1 - - [31/Dec/2018:16:11:31 +0000] "GET /images/marker_inactive.png HTTP/1.1" 200 0.520 ms
0|server | ::ffff:127.0.0.1 - - [31/Dec/2018:16:11:31 +0000] "GET /images/marker_active.png HTTP/1.1" 200 0.567 ms
0|server | ::ffff:127.0.0.1 - - [31/Dec/2018:16:11:31 +0000] "GET /images/marker_inactive.png HTTP/1.1" 200 0.416 ms

Related

PM2 doesn't fully run signal event handler

I have a graceful shut down function in my Express application to handle receipt of signals. If I run the application not using PM2, the function works as expected. When I start the application in cluster mode using PM2, the function only executes the first line before dying.
As far as I can see in the logs SIGKILL isn't being sent, but it's also not fully executing the event handler callback before dying. I have been unable to determine why the event handler doesn't finish, but I have been able to figure out that this issue is unique to PM2. I tried updating the kill timeout, I tried using no-killtree, nothing has worked.
The relevant pm2.log section:
2022-11-09T15:23:28: PM2 log: App [server:7] starting in -cluster mode-
2022-11-09T15:23:28: PM2 log: App [server:7] online
2022-11-09T15:23:28: PM2 log: App [server:8] starting in -cluster mode-
2022-11-09T15:23:28: PM2 log: App [server:8] online
2022-11-09T15:23:28: PM2 log: App [server:9] starting in -cluster mode-
2022-11-09T15:23:28: PM2 log: App [server:9] online
2022-11-09T15:23:28: PM2 log: App [server:10] starting in -cluster mode-
2022-11-09T15:23:28: PM2 log: App [server:10] online
2022-11-09T15:39:26: PM2 log: Stopping app:server id:7
2022-11-09T15:39:26: PM2 log: Stopping app:server id:8
2022-11-09T15:39:27: PM2 log: App name:server id:8 disconnected
2022-11-09T15:39:27: PM2 log: App [server:8] exited with code [0] via signal [SIGINT]
2022-11-09T15:39:27: PM2 log: App name:server id:7 disconnected
2022-11-09T15:39:27: PM2 log: App [server:7] exited with code [0] via signal [SIGINT]
2022-11-09T15:39:27: PM2 log: pid=50526 msg=process killed
2022-11-09T15:39:27: PM2 log: pid=50533 msg=process killed
2022-11-09T15:39:27: PM2 log: Stopping app:server id:9
2022-11-09T15:39:27: PM2 log: Stopping app:server id:10
2022-11-09T15:39:27: PM2 log: App name:server id:9 disconnected
2022-11-09T15:39:27: PM2 log: App [server:9] exited with code [0] via signal [SIGINT]
2022-11-09T15:39:27: PM2 log: App name:server id:10 disconnected
2022-11-09T15:39:27: PM2 log: App [server:10] exited with code [0] via signal [SIGINT]
2022-11-09T15:39:27: PM2 log: pid=50540 msg=process killed
2022-11-09T15:39:27: PM2 log: pid=50547 msg=process killed
The event handler and process calls:
const onSignal = (signal) => {
console.log('test');
console.log(`${signal} signal received. Cleaning up and shutting down.`);
console.log('test');
console.log("Closing HTTPS server to new connections");
httpsServer.close(error => {
if (error) {
console.log(`Error closing HTTPS server: ${error.message}`);
console.log("Process cleanup did not occur due to error.");
process.exit(1);
}
});
console.log("Closing SQL Connection Pool");
db.end().then(() => {
console.log("SQL Connection Pool successfully ended");
})
.catch(reason => {
console.error(`Failed to close SQL Connection Pool. Error: ${reason.message}`);
})
.finally(() => {
process.exit(0);
});
};
process.on('SIGINT', onSignal);
process.on('SIGQUIT', onSignal);
process.on('SIGTERM', onSignal);
The only thing that shows up in the application log is the first console log, once for each pid of the cluster. I don't understand why the process is dying before the graceful shut down can finish. If it was a kill timeout issue, then when I set the kill timeout to one minute that should've been enough time, but it still killed the pid within seconds. I'm at a loss here what is causing this behavior.
I solved this by eliminating most of the logging. There seems to be a bug in PM2 cluster mode that affects all loggers. In cluster mode specifically PM2 only logs one statement then ignores all other log statements. The function still executes properly, but the logging does not happen.
Essentially I only log one statement at any point of finality that describes how the function finished. I don't consider this an answer, but more of a jimmy rigged solution to get around a bug.
Reference point for this bug: https://github.com/Unitech/pm2/issues/3691
const onSignal = (signal) => {
httpsServer.close(error => {
if (error) {
logger.error(`Signal ${signal} was received and there was an error closing HTTPS server: ${error.message} Graceful shut down process did not finish due to error.`);
//exit with error
process.exit(1);
}
});
db.end().then(() => {
logger.info(`Signal ${signal} was received and graceful shut down process finished.`);
})
.catch(reason => {
logger.error(`Signal ${signal} was received and there was an error closing the SQL Connection Pool. Error: ${reason.message}`);
})
.finally(() => {
process.exit(0);
});
};

How to tell to pm2 to ignore all errors in scripts locpated at node_modules and subfolders?

I am testing an APP under server enviroment:
Use of aaPanel or btPanel under ubuntu
Use of pm2 module
The app is running but restart on error
I am using custom error managment and log functions
I want pm2 just ignore all console.log(error) and errors ocurred in scripts located at node_modules and subfolder
Anny idea?
Thanks for your time and for any help
This is a example of some error log from pm2:
2021-03-12T01:52:51: PM2 log: App [MyApp] exited with code [0] via signal [SIGINT]
And this is a example of error in out log from pm2:
Error: /www/wwwroot/apps/MyApp/1.0.0.2/node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node: invalid ELF header
at Object.Module._extensions..node (internal/modules/cjs/loader.js:1122:18)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19)
at Module.Hook._require.Module.require (/www/server/nvm/versions/node/v14.16.0/lib/node_modules/pm2/node_modules/require-in-the-middle/index.js:80:39)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (/www/wwwroot/apps/MyApp/1.0.0.2/node_modules/bcrypt/bcrypt.js:6:16)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
This is a log from console pm2 console in aaPanel or btPanel:
2021-03-12T00:05:50: PM2 log: ===============================================================================
2021-03-12T00:05:50: PM2 log: --- New PM2 Daemon started ----------------------------------------------------
2021-03-12T00:05:50: PM2 log: Time : Fri Mar 12 2021 00:05:50 GMT+0000 (Coordinated Universal Time)
2021-03-12T00:05:50: PM2 log: PM2 version : 4.5.5
2021-03-12T00:05:50: PM2 log: Node.js version : 14.16.0
2021-03-12T00:05:50: PM2 log: Current arch : x64
2021-03-12T00:05:50: PM2 log: PM2 home : /root/.pm2
2021-03-12T00:05:50: PM2 log: PM2 PID file : /root/.pm2/pm2.pid
2021-03-12T00:05:50: PM2 log: RPC socket file : /root/.pm2/rpc.sock
2021-03-12T00:05:50: PM2 log: BUS socket file : /root/.pm2/pub.sock
2021-03-12T00:05:50: PM2 log: Application log path : /root/.pm2/logs
2021-03-12T00:05:50: PM2 log: Worker Interval : 30000
2021-03-12T00:05:50: PM2 log: Process dump file : /root/.pm2/dump.pm2
2021-03-12T00:05:50: PM2 log: Concurrent actions : 2
2021-03-12T00:05:50: PM2 log: SIGTERM timeout : 1600
2021-03-12T00:05:50: PM2 log: ===============================================================================
2021-03-12T00:20:11: PM2 log: App [MyApp] starting in -fork mode-
2021-03-12T00:20:11: PM2 log: App [MyApp] online
2021-03-12T00:21:59: PM2 log: Stopping app:1.0.0.2 id:0
2021-03-12T00:21:59: PM2 log: App [MyApp] exited with code [0] via signal [SIGINT]
2021-03-12T00:21:59: PM2 log: pid=95350 msg=process killed
2021-03-12T00:22:24: PM2 log: App [MyApp] starting in -fork mode-
2021-03-12T00:22:24: PM2 log: App [MyApp] online
2021-03-12T00:40:41: PM2 log: Stopping app:MyApp id:0
2021-03-12T00:40:41: PM2 log: App [MyApp] exited with code [0] via signal [SIGINT]
2021-03-12T00:40:41: PM2 log: pid=96990 msg=process killed
Aditional Notes:
The app run flawless under local enviroment
The pm2 is the problem some awfull bad config maybe!
I run and test the app using 'nodemon index.js' all ok
I run and test the app using 'node index.js' all ok
I run and test the app using 'npm start' all ok
I run npm update all ok
I run npm audit all ok

Build folder not recognized in pm2 service

I'm running my node+react app on vps ubuntu machine using ssh.
I used nginx, pm2 for running my node js server, but when I check my logs it shows the following error:
App [server:0] starting in -fork mode-
PM2 | 2020-09-16T07:05:03: PM2 log: App [server:0] online
PM2 | 2020-09-16T07:06:18: PM2 log: Reloading logs...
PM2 | 2020-09-16T07:06:18: PM2 log: Reloading logs for process id 0
PM2 | 2020-09-16T07:38:58: PM2 log: Stopping app:server id:0
PM2 | 2020-09-16T07:38:58: PM2 log: App [server:0] exited with code [0] via signal [SIGINT]
PM2 | 2020-09-16T07:38:58: PM2 log: pid=6888 msg=process killed
PM2 | 2020-09-16T07:38:58: PM2 log: App [server:0] starting in -fork mode-
PM2 | 2020-09-16T07:38:58: PM2 log: App [server:0] online
0|server | Error: ENOENT: no such file or directory, stat '/root/repos/IRS-Ecommerce/IRS-
Ecommerce/build/index.html'
/root/.pm2/logs/server-out.log last 15 lines:
0|server | Server is up and running at port : 8080
0|server | MongoDB connected successfully!
My node js server file where I'm sending my react app in response:
app.use(express.static("IRS-Ecommerce/build"));
app.get("*", (req, res) => {
res.sendFile(path.join(__dirname, "IRS-Ecommerce", "build", "index.html"));
});
I've run npm build in my react app and build folder is present there, but it is showing this error that index.html is not there. I've checked the path, it is correct.
When I access public IP, my react app shows up which means it is working. But why am I seeing this error here?
/root/repos/IRS-Ecommerce/IRS- Ecommerce/build/index.html double IRS-
Ecommerce orz

Nodejs pm2 is always restarting when I reboot Ubuntu

I have an express nodejs server running in Ubuntu LTS with pm2. The server runs fine, but when I restart Ubuntu, the server is always rebooting.
I use an ecossystem.config like this:
module.exports = {
apps : [{
name: 'gTimeTracking',
script: 'index.js',
args: 'one two',
instances: 1,
autorestart: true,
watch: true,
max_memory_restart: '1G',
env: {
NODE_ENV: 'development'
},
env_production: {
NODE_ENV: 'production'
}
}]
};
I started the server with this command:
pm2 start ecosystem.config.js --env production
And with pm2 save
and I have this infinite error on Ubuntu reboot
0|gTimeTracking | Server running since: Mon Jul 01 2019 09:36:43 GMT+0200 (CEST)
PM2 | Change detected on path logs/logger-01-07-2019-09.log for app gTimeTracking - restarting
PM2 | Stopping app:gTimeTracking id:0
PM2 | App [gTimeTracking:0] exited with code [0] via signal [SIGINT]
PM2 | pid=16255 msg=process killed
PM2 | App [gTimeTracking:0] starting in -fork mode-
PM2 | App [gTimeTracking:0] online
0|gTimeTracking | Server running since: Mon Jul 01 2019 09:36:44 GMT+0200 (CEST)
PM2 | Change detected on path logs/logger-01-07-2019-09.log for app gTimeTracking - restarting
PM2 | Stopping app:gTimeTracking id:0
PM2 | App [gTimeTracking:0] exited with code [0] via signal [SIGINT]
PM2 | pid=16274 msg=process killed
PM2 | App [gTimeTracking:0] starting in -fork mode-
PM2 | App [gTimeTracking:0] online
Last time I had this problem I had to reinstall many times pm2 to relaunch the server, but now this method doesn't works and isn't an stable solution
What could be wrong?
I had to use pm2 cleardump for solve the problem with pm2 delete all and pm2 kill it didn't works for me. (I didn't have to change anything about the loggers path)

pm2 start app.js is exiting after 15 restarts

npm start will start my app just fine but when I do:
pm2 start app.js
I get:
[PM2] Spawning PM2 daemon
[PM2] PM2 Successfully daemonized
[PM2] Process app.js launched
┌──────────┬────┬──────┬──────┬────────┬─────────┬────────┬─────────────┬──────────┐
│ App name │ id │ mode │ pid │ status │ restart │ uptime │ memory │ watching │
├──────────┼────┼──────┼──────┼────────┼─────────┼────────┼─────────────┼──────────┤
│ app │ 0 │ fork │ 4681 │ online │ 0 │ 0s │ 11.508 MB │ disabled │
└──────────┴────┴──────┴──────┴────────┴─────────┴────────┴─────────────┴──────────┘
Use `pm2 show <id|name>` to get more details about an app
in the logs I get:
[PM2] Starting streaming logs for [all] process
PM2: 2015-06-04 17:12:37: App name:app id:0 exited with code 0
PM2: 2015-06-04 17:12:37: Starting execution sequence in -fork mode- for app name:app id:0
PM2: 2015-06-04 17:12:37: App name:app id:0 online
PM2: 2015-06-04 17:12:37: App name:app id:0 exited with code 0
PM2: 2015-06-04 17:12:37: Starting execution sequence in -fork mode- for app name:app id:0
PM2: 2015-06-04 17:12:37: App name:app id:0 online
PM2: 2015-06-04 17:12:37: App name:app id:0 exited with code 0
PM2: 2015-06-04 17:12:37: Starting execution sequence in -fork mode- for app name:app id:0
PM2: 2015-06-04 17:12:37: App name:app id:0 online
PM2: 2015-06-04 17:12:38: App name:app id:0 exited with code 0
PM2: 2015-06-04 17:12:38: Starting execution sequence in -fork mode- for app name:app id:0
PM2: 2015-06-04 17:12:38: App name:app id:0 online
PM2: 2015-06-04 17:12:38: App name:app id:0 exited with code 0
PM2: 2015-06-04 17:12:38: Starting execution sequence in -fork mode- for app name:app id:0
PM2: 2015-06-04 17:12:38: App name:app id:0 online
PM2: 2015-06-04 17:12:39: App name:app id:0 exited with code 0
PM2: 2015-06-04 17:12:39: Starting execution sequence in -fork mode- for app name:app id:0
PM2: 2015-06-04 17:12:39: App name:app id:0 online
PM2: 2015-06-04 17:12:39: App name:app id:0 exited with code 0
PM2: 2015-06-04 17:12:39: Script /home/user/app/app.js had too many unstable restarts (15). Stopped. "errored"
here is my package.json:
1 {
2 "name": "app",
3 "version": "0.0.0",
4 "private": true,
5 "scripts": {
6 "start": "node ./bin/www"
7 },
8 "dependencies": {
9 "body-parser": "~1.12.4",
10 "cookie-parser": "~1.3.5",
11 "debug": "~2.2.0",
12 "express": "~4.12.4",
13 "jade": "~1.9.2",
14 "morgan": "~1.5.3",
15 "serve-favicon": "~2.2.1",
16 "stylus": "0.42.3"
17 }
18 }
node version: v0.10.38
pm2 version: 0.12.15
How do I even debug this? I am not sure why it's failing, is there some other place I need to check? My app.js file?
First, I'd try node ./bin/www and just make sure that works correctly.
I'm not sure what the "official" way to figure this out is but this should work:
You could put an uncaught exception handler into your code which simply writes to a file or do something else.
process.on('uncaughtException', function(err) {
console.log('Caught exception: ' + err);
throw err;
});
Edit:
Based on your comment the reason you're having issues is because app.js is not the real entry point in your application. The real entry point is ./bin/www
So you need to tell PM2 to start that file rather than app.js like this:
pm2 start ./bin/www

Resources