Set memory limit to 400M for tasks

This commit is contained in:
Girish Ramakrishnan
2020-08-07 00:15:24 -07:00
parent b1b6f70118
commit 114b45882a

View File

@@ -29,6 +29,13 @@ systemctl reset-failed "${service_name}" || true
readonly id=$(id -u $SUDO_USER)
readonly ubuntu_version=$(lsb_release -rs)
if [[ "${ubuntu_version}" == "16.04" ]]; then
memory_limit="-p MemoryLimit=400M"
else
memory_limit="-p MemoryMax=400M"
fi
# 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
if [[ "$BOX_ENV" == "cloudron" ]]; then
@@ -37,7 +44,7 @@ else
binds_to=""
fi
systemd-run --unit "${service_name}" --pipe --wait --property=OOMScoreAdjust=-1000 --nice "${nice}" --uid=${id} --gid=${id} \
${binds_to} -E HOME=${HOME} -E USER=${SUDO_USER} -E DEBUG=${DEBUG} -E BOX_ENV=${BOX_ENV} -E NODE_ENV=production \
systemd-run --unit "${service_name}" --pipe --wait --nice "${nice}" --uid=${id} --gid=${id} ${binds_to} ${memory_limit} \
-E HOME=${HOME} -E USER=${SUDO_USER} -E DEBUG=${DEBUG} -E BOX_ENV=${BOX_ENV} -E NODE_ENV=production \
"${task_worker}" "${task_id}" "${logfile}"