diff --git a/src/scripts/starttask.sh b/src/scripts/starttask.sh index acffa70c7..31f544a74 100755 --- a/src/scripts/starttask.sh +++ b/src/scripts/starttask.sh @@ -23,6 +23,7 @@ fi readonly task_id="$1" readonly logfile="$2" readonly nice="$3" +readonly memory_limit_mb="$4" readonly service_name="box-task-${task_id}" systemctl reset-failed "${service_name}" || true @@ -31,9 +32,9 @@ readonly id=$(id -u $SUDO_USER) readonly ubuntu_version=$(lsb_release -rs) if [[ "${ubuntu_version}" == "16.04" ]]; then - options="-p MemoryLimit=400M --remain-after-exit" + options="-p MemoryLimit=${memory_limit_mb}M --remain-after-exit" else - options="-p MemoryMax=400M --pipe --wait" + options="-p MemoryMax=${memory_limit_mb}M --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 026324e6e..a5bb6dfc2 100644 --- a/src/tasks.js +++ b/src/tasks.js @@ -143,7 +143,7 @@ function startTask(id, options, callback) { let killTimerId = null, timedOut = false; - gTasks[id] = shell.sudo('startTask', [ START_TASK_CMD, id, logFile, options.nice || 0 ], { preserveEnv: true }, function (error) { + gTasks[id] = shell.sudo('startTask', [ START_TASK_CMD, id, logFile, options.nice || 0, options.memoryLimit || 400 ], { preserveEnv: true }, function (error) { if (!gTasks[id]) return; // ignore task exit since we are shutting down. see stopAllTasks const code = error ? error.code : 0;