mirror of
https://github.com/Unitech/pm2.git
synced 2025-12-08 20:35:53 +00:00
(docker) better auto exit trigger (#2861)
This commit is contained in:
parent
64fe775ce3
commit
da7f7698b9
@ -118,23 +118,42 @@ function exitPM2() {
|
||||
* function activated via --auto-exit
|
||||
*/
|
||||
function autoExit() {
|
||||
setTimeout(function() {
|
||||
pm2.list(function(err, apps) {
|
||||
if (err) console.error(err.stack || err);
|
||||
var interval = 3000;
|
||||
var aliveInterval = interval * 1.5;
|
||||
|
||||
var online_count = 0;
|
||||
setTimeout(function () {
|
||||
var alive = false
|
||||
var aliveTimer = setTimeout(function () {
|
||||
if (!alive) {
|
||||
console.error('PM2 Daemon is dead');
|
||||
process.exit(1);
|
||||
}
|
||||
}, aliveInterval);
|
||||
|
||||
apps.forEach(function(app) {
|
||||
if (app.pm2_env.status == cst.ONLINE_STATUS ||
|
||||
app.pm2_env.status == cst.LAUNCHING_STATUS)
|
||||
online_count++;
|
||||
pm2.list(function (err, apps) {
|
||||
if (err) {
|
||||
console.log('pm2.list got error')
|
||||
console.error(err);
|
||||
exitPM2();
|
||||
}
|
||||
|
||||
clearTimeout(aliveTimer);
|
||||
alive = true;
|
||||
|
||||
var appOnline = 0;
|
||||
|
||||
apps.forEach(function (app) {
|
||||
if (app.pm2_env.status === cst.ONLINE_STATUS ||
|
||||
app.pm2_env.status === cst.LAUNCHING_STATUS) {
|
||||
appOnline++;
|
||||
}
|
||||
});
|
||||
|
||||
if (online_count == 0) {
|
||||
if (appOnline === 0) {
|
||||
console.log('0 application online, exiting');
|
||||
exitPM2();
|
||||
}
|
||||
autoExit();
|
||||
});
|
||||
}, 3000);
|
||||
}, interval);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user