Kill all tasks on shutdown and startup
BindsTo will kill all the tasks when systemctl stop box is executed. But when restarted, it keeps the tasks running. Because of this behavior, we kill the tasks on startup and stop of the box code.
This commit is contained in:
12
src/tasks.js
12
src/tasks.js
@@ -38,7 +38,6 @@ exports = module.exports = {
|
||||
};
|
||||
|
||||
let assert = require('assert'),
|
||||
async = require('async'),
|
||||
BoxError = require('./boxerror.js'),
|
||||
debug = require('debug')('box:tasks'),
|
||||
path = require('path'),
|
||||
@@ -144,7 +143,9 @@ function startTask(id, options, callback) {
|
||||
|
||||
let killTimerId = null, timedOut = false;
|
||||
|
||||
shell.sudo('startTask', [ START_TASK_CMD, id, logFile, options.nice || 0 ], {}, function (error) {
|
||||
gTasks[id] = shell.sudo('startTask', [ START_TASK_CMD, id, logFile, options.nice || 0 ], { preserveEnv: true }, function (error) {
|
||||
if (!gTasks[id]) return; // ignore task exit since we are shutting down. see stopAllTasks
|
||||
|
||||
const code = error ? error.code : 0;
|
||||
const signal = error ? error.signal : 0;
|
||||
|
||||
@@ -200,9 +201,10 @@ function stopTask(id, callback) {
|
||||
function stopAllTasks(callback) {
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
async.eachSeries(Object.keys(gTasks), function (id, iteratorDone) {
|
||||
stopTask(id, () => iteratorDone()); // ignore any error
|
||||
}, callback);
|
||||
debug('stopTask: stopping all tasks');
|
||||
|
||||
gTasks = {}; // this signals startTask() to not set completion status as "crashed"
|
||||
shell.sudo('stopTask', [ STOP_TASK_CMD, 'all' ], {}, callback);
|
||||
}
|
||||
|
||||
function listByTypePaged(type, page, perPage, callback) {
|
||||
|
||||
Reference in New Issue
Block a user