diff --git a/src/scripts/starttask.sh b/src/scripts/starttask.sh index b5c01a8b1..71a5b0e7a 100755 --- a/src/scripts/starttask.sh +++ b/src/scripts/starttask.sh @@ -44,10 +44,12 @@ fi # DEBUG has to be hardcoded because it is not set in the tests. --setenv is required for ubuntu 16 (-E does not work) # NODE_OPTIONS is used because env -S does not work in ubuntu 16/18. -systemd-run --unit "${service_name}" --nice "${nice}" --uid=${id} --gid=${id} ${options} \ - --setenv HOME=${HOME} --setenv USER=${SUDO_USER} --setenv DEBUG=box:* --setenv BOX_ENV=${BOX_ENV} --setenv NODE_ENV=production --setenv NODE_OPTIONS=--unhandled-rejections=strict \ - "${task_worker}" "${task_id}" "${logfile}" -exit_code=$? +# it seems systemd-run does not return the exit status of the process despite --wait +if ! systemd-run --unit "${service_name}" --nice "${nice}" --uid=${id} --gid=${id} ${options} --setenv HOME=${HOME} --setenv USER=${SUDO_USER} --setenv DEBUG=box:* --setenv BOX_ENV=${BOX_ENV} --setenv NODE_ENV=production --setenv NODE_OPTIONS=--unhandled-rejections=strict "${task_worker}" "${task_id}" "${logfile}"; then + echo "Service ${service_name} failed to run" # this only happens if the path to task worker itself is wrong +fi + +exit_code=$(systemctl show "${service_name}" -p ExecMainCode | sed 's/ExecMainCode=//g') echo "Service ${service_name} finished with exit code ${exit_code}" exit "${exit_code}" diff --git a/src/tasks.js b/src/tasks.js index c0ee9d6a2..8721e039e 100644 --- a/src/tasks.js +++ b/src/tasks.js @@ -171,9 +171,8 @@ function startTask(id, options, callback) { if (!gTasks[id]) return; // ignore task exit since we are shutting down. see stopAllTasks const code = sudoError ? sudoError.code : 0; - const signal = sudoError ? sudoError.signal : 0; - debug(`startTask: ${id} completed with code ${code} and signal ${signal}`); + debug(`startTask: ${id} completed with code ${code}`); if (options.timeout) clearTimeout(killTimerId); @@ -186,9 +185,9 @@ function startTask(id, options, callback) { message: `Task ${id} ${timedOut ? 'timed out' : 'stopped'}` , code: timedOut ? exports.ETIMEOUT : exports.ESTOPPED }; - } else { // task crashed + } else { // task crashed. for code, maybe we can check systemctl show box-task-1707 -p ExecMainStatus taskError = { - message: signal === 9 ? `Task ${id} crashed as it ran out of memory` : `Task ${id} crashed with code ${code} and signal ${signal}`, + message: code === 2 ? `Task ${id} crashed as it ran out of memory` : `Task ${id} crashed with code ${code}`, code: exports.ECRASHED }; }