fix: retire orphaned containers when scaling down

When scaling a process type to a smaller count, the indices above the
new count had their `CONTAINER.<proctype>.<idx>` state files deleted but
the underlying Docker containers were never registered for retirement,
so they remained running indefinitely. The cleanup block now reads each
orphaned state file and registers its container id with the existing
`scheduler-register-retired` trigger before the file is removed.
This commit is contained in:
Jose Diaz-Gonzalez
2026-04-27 01:20:24 -04:00
parent e54fcc4035
commit 4927ca092d
2 changed files with 52 additions and 1 deletions

View File

@@ -85,8 +85,15 @@ fn-scheduler-deploy-process() {
else
local CONTAINER_IDX_OFFSET=$((PROC_COUNT + 1))
fi
local container_state_filetype
local container_state_filetype orphaned_container_file orphaned_cid
pushd "$DOKKU_ROOT/$APP" >/dev/null
for orphaned_container_file in $(find . -maxdepth 1 -name "CONTAINER.$PROC_TYPE.*" -printf "%f\n" | sort -t . -k 3 -n | tail -n +$CONTAINER_IDX_OFFSET); do
[[ -s "$orphaned_container_file" ]] || continue
orphaned_cid="$(<"$orphaned_container_file")"
[[ -z "$orphaned_cid" ]] && continue
dokku_log_verbose "Scheduling orphaned container shutdown in $DOKKU_WAIT_TO_RETIRE seconds (${orphaned_container_file#CONTAINER.})"
plugn trigger scheduler-register-retired "$APP" "$orphaned_cid" "$DOKKU_WAIT_TO_RETIRE"
done
for container_state_filetype in CONTAINER IP PORT; do
find . -maxdepth 1 -name "$container_state_filetype.$PROC_TYPE.*" -printf "%f\n" | sort -t . -k 3 -n | tail -n +$CONTAINER_IDX_OFFSET | xargs rm -f
done