diff --git a/src/backups.js b/src/backups.js index 41dcf2dbe..57b246915 100644 --- a/src/backups.js +++ b/src/backups.js @@ -249,7 +249,7 @@ async function startBackupTask(auditSource) { await eventlog.add(eventlog.ACTION_BACKUP_START, auditSource, { taskId }); - tasks.startTask(taskId, { timeout: 24 * 60 * 60 * 1000 /* 24 hours */, nice: 15, memoryLimit }, async function (error, backupId) { + tasks.startTask(taskId, { timeout: 24 * 60 * 60 * 1000 /* 24 hours */, nice: 15, memoryLimit, oomScoreAdjust: -999 }, async function (error, backupId) { locker.unlock(locker.OP_FULL_BACKUP); const errorMessage = error ? error.message : ''; diff --git a/src/scripts/backupupload.js b/src/scripts/backupupload.js index cbdf59c7c..551ca680f 100755 --- a/src/scripts/backupupload.js +++ b/src/scripts/backupupload.js @@ -34,7 +34,7 @@ function throttledProgressCallback(msecs) { let lastProgress = null; return function (progress) { - let now = Date.now(); + const now = Date.now(); if (lastProgress && ((now - lastProgress) < msecs)) return; process.send(progress); lastProgress = now; diff --git a/src/scripts/starttask.sh b/src/scripts/starttask.sh index 93ac1aa3c..e01e246cc 100755 --- a/src/scripts/starttask.sh +++ b/src/scripts/starttask.sh @@ -24,6 +24,7 @@ readonly task_id="$1" readonly logfile="$2" readonly nice="$3" readonly memory_limit_mb="$4" # SI units +readonly oom_score_adjust="$5" readonly service_name="box-task-${task_id}" systemctl reset-failed "${service_name}" 2>/dev/null || true @@ -31,7 +32,7 @@ systemctl reset-failed "${service_name}" 2>/dev/null || true readonly id=$(id -u $SUDO_USER) readonly ubuntu_version=$(lsb_release -rs) -options="-p TimeoutStopSec=10s -p MemoryMax=${memory_limit_mb}M --pipe --wait" +options="-p TimeoutStopSec=10s -p MemoryMax=${memory_limit_mb}M -p OOMScoreAdjust=${oom_score_adjust} --pipe --wait" # Note: BindsTo will kill this task when the box is stopped. but will not kill this task when restarted! # For this reason, we have code to kill the tasks both on shutdown and startup. diff --git a/src/tasks.js b/src/tasks.js index f13eb18cd..1f8e3d058 100644 --- a/src/tasks.js +++ b/src/tasks.js @@ -170,7 +170,7 @@ function startTask(id, options, onTaskFinished) { const sudoOptions = { preserveEnv: true, logStream: null }; if (constants.TEST) sudoOptions.logStream = fs.createWriteStream('/dev/null'); // without this output is messed up, not sure why - gTasks[id] = shell.sudo('startTask', [ START_TASK_CMD, id, logFile, options.nice || 0, options.memoryLimit || 400 ], sudoOptions, async function (sudoError) { + gTasks[id] = shell.sudo('startTask', [ START_TASK_CMD, id, logFile, options.nice || 0, options.memoryLimit || 400, options.oomScoreAdjust || 0 ], sudoOptions, async function (sudoError) { if (!gTasks[id]) return; // ignore task exit since we are shutting down. see stopAllTasks const code = sudoError ? sudoError.code : 0;