Skip to content

Commit

Permalink
better child process control with better shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
taeguscromis committed Jun 7, 2020
1 parent 0280e0d commit 1c81f7f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"command-line-usage": "^5.0.5",
"conceal-api": "^0.7.5",
"download-github-release": "^0.3.2",
"execa": "^4.0.2",
"express": "^4.17.1",
"extract-zip": "^1.6.7",
"geoip-lite": "^1.4.0",
Expand All @@ -53,4 +54,4 @@
"expr": true,
"esversion": 8
}
}
}
17 changes: 7 additions & 10 deletions units/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const moment = require("moment");
const comms = require("./comms.js");
const pjson = require('../package.json');
const utils = require("./utils.js");
const execa = require('execa');
const path = require("path");
const fs = require("fs");
const os = require("os");
Expand Down Expand Up @@ -50,6 +51,8 @@ exports.NodeGuard = function (cmdOptions, configOpts, rootPath, guardVersion) {
})();

this.stop = function (doAutoRestart) {
logMessage("Stopping the daemon process", "info", false);

autoRestart = (doAutoRestart != null) ? doAutoRestart : true;
clearInterval(poolNotifyInterval);

Expand All @@ -76,15 +79,9 @@ exports.NodeGuard = function (cmdOptions, configOpts, rootPath, guardVersion) {
logMessage("Sending SIGTERM to daemon process", "info", false);

isStoping = true;
nodeProcess.kill("SIGTERM");

// if normal fails, do a forced terminate
killTimeout = setTimeout(function () {
if (isStoping) {
logMessage("Sending SIGKILL to daemon process", "error", false);
nodeProcess.kill("SIGKILL");
}
}, (configOpts.restart.terminateTimeout || 5) * 1000);
nodeProcess.kill('SIGTERM', {
forceKillAfterTimeout: (configOpts.restart.terminateTimeout || 5) * 1000
});
}
}
};
Expand Down Expand Up @@ -218,7 +215,7 @@ exports.NodeGuard = function (cmdOptions, configOpts, rootPath, guardVersion) {
// start the daemon process and then monitor it
//*************************************************************//
function startDaemonProcess() {
nodeProcess = child_process.spawn(utils.getNodeActualPath(cmdOptions, configOpts, rootPath), configOpts.node.args || []);
nodeProcess = execa(utils.getNodeActualPath(cmdOptions, configOpts, rootPath), configOpts.node.args || []);
logMessage("Started the daemon process", "info", false);
autoRestart = true;
isStoping = false;
Expand Down

0 comments on commit 1c81f7f

Please sign in to comment.