diff --git a/src/scripts/starttask.sh b/src/scripts/starttask.sh index 48a69bffe..8b5ce6833 100755 --- a/src/scripts/starttask.sh +++ b/src/scripts/starttask.sh @@ -34,11 +34,13 @@ systemctl reset-failed "${service_name}" 2>/dev/null || true options="-p TimeoutStopSec=10s -p MemoryMax=${memory_limit_mb}M -p OOMScoreAdjust=${oom_score_adjust} --wait" -# systemd-run is used to create resource limited tasks. the tasks are in separate cgroup and won't get affected by box start/stop -# this design is because tasks should not run when box code is stopped. if dashboard is down, nothing should run -in background. -# besides, if tasks continue running, box code needs complex reconcilation code on start up. -# To achieve above design, we could use BindsTo=box.service. While this stops all tasks on systemctl stop, it restarts tasks on systemctl restart. +# systemd-run is used to create resource limited tasks. such tasks are in separate cgroup and won't get affected by box start/stop. +# However, we want task to not run when box code is stopped. If dashboard is down, nothing should run in the background. +# Besides, if tasks do continue running, box code needs complex state reconcilation logic on start up. +# To stop tasks on box stop, we could use BindsTo=box.service. While this stops all tasks on systemctl stop, it restarts tasks on systemctl restart! # Another approach was to use --scope but this is incompatible with --wait (and then we have to start polling status to get exit code) +# So, the implemented solution is to kill the tasks manually on exit by handing SIGTERM with KillMode=mixed which calls stopAllTasks +# As an additional precaution, box start also calls stopAllTasks # it seems systemd-run does not return the exit status of the process despite --wait but atleast it waits if ! systemd-run --unit "${service_name}" --wait --uid=${id} --gid=${id} \