tasks: add note on why we use systemd-run

This commit is contained in:
Girish Ramakrishnan
2025-06-16 18:14:21 +02:00
parent 6a2f2b4efe
commit 5cf98922fb

View File

@@ -37,9 +37,10 @@ options="-p TimeoutStopSec=10s -p MemoryMax=${memory_limit_mb}M -p OOMScoreAdjus
# For this reason, we have code to kill the tasks both on shutdown and startup.
[[ "$BOX_ENV" == "cloudron" ]] && options="${options} -p BindsTo=box.service"
# DEBUG has to be hardcoded because it is not set in the tests. --setenv is required for ubuntu 16 (-E does not work)
# systemd-run is used to create resource limited tasks. the tasks are in separate cgroup and won't get affected by box start/stop
# 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 "${task_worker}" "${task_id}" "${logfile}"; then
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 "${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