Skip to content

feat: a service's stop command runs when devstack stops an instance (ADR-0059) - #247

Merged
7schmiede merged 3 commits into
mainfrom
feat/service-stop
Oct 23, 2026
Merged

7schmiede merged 3 commits into
mainfrom
feat/service-stop

Conversation

@7schmiede

@7schmiede 7schmiede commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

Summary

  • ADR-0059 (Accepted): [services.<name>] stop ends what a service's run started outside its process tree, a container of a docker run service, say.
  • It is expanded with the instance's placeholders when the instance starts ({port} is the instance's own, {lane_suffix}, … as for run). It runs whenever the instance ends: a stop, a restart, down, the old instance a candidate replaced, a failed or cancelled start/candidate, a finished job, or an instance that ended by itself.
  • It runs before the graceful signal, for at most 30 s, with its output appended to the instance's log. If it fails, the failure is logged and the stop goes on as ADR-0009 says (signal, wait, kill). Every end of an instance now goes through Supervisor::end.
  • Crash recovery: the expanded command, its working directory and the instance's log go into state.json beside the ADR-0016 cleanup record. The next start of that tree's supervisor runs the recorded ones before anything starts. They run with devstack's own environment, because the service's environment can hold secrets and is not written to disk.
  • Profiles: a profile may set stop. kind = "static" has none, and a profile that makes a service static drops it. Hot-reload mode does not use it.
  • devstack check warns when a file uses stop without requires = "0.21.0".
  • Docs: docs/stack-file.md has a section on a container as a service (--init, --rm, a name with {lane_suffix}-{port}, stop). The devstack-config skill and the changelog are updated too.

The measurement behind it (#245)

devstack 0.20.0, Windows 11, Docker Desktop 29.9.2:

run devstack stop container afterwards
docker run --rm alpine sleep 300 20 s (timeout, then kill) still Up
docker run --rm --init alpine sleep 300 0 s gone (also with devstack down)
first row + stop = "docker rm -f <name>" (this branch) 0 s gone

The graceful stop does reach the container: CTRL_BREAK goes to the process group, and the CLI forwards it as SIGINT. In the issue's example sleep is PID 1 and ignores that signal. What stop adds is cover for the cases the signal cannot reach: a process that ignores it, a CLI that ended by itself, a failed start, and a dead daemon.

Test plan

  • cargo fmt, cargo clippy --all-targets clean
  • cargo test -p devstack-config -p devstack-daemon -p devstack-skills -p devstack-proc -p devstack
  • New a_services_stop_ends_what_its_run_started (daemon integration, no SDK): the stop gets the instance's port and writes into its log, and after a hard kill of the daemon the next up runs the recorded stop. Passed on Windows, together with a_hanging_job_or_step_ends, a_service_that_exits_by_itself_comes_back, a_stop_while_the_migrator_runs_holds, a_failed_first_start_restores_again, edits_become_candidates, a_job_runs_once_for_two_candidates and serving_without_workers_stays_visible.
  • Checked by hand with real Docker, using the issue's example plus stop.
  • Linux/macOS CI

Refs #245

🤖 Generated with Claude Code

7schmiede and others added 3 commits October 23, 2026 18:12
…d outside its process tree (Proposed)

A `docker run` service leaves its container running whenever the CLI ends
without the container: a process that ignores the graceful signal (killed
after the timeout), a CLI killed on its own, a failed start, a dead daemon.
Measured on Windows: the graceful stop does reach the container (the CLI
forwards CTRL_BREAK as SIGINT; with `--init` the container is gone at
once), but `sleep` as PID 1 ignores it. The ADR proposes
`[services.<name>] stop`: a command expanded with the instance's
placeholders when it starts, run whenever the instance ends, before the
graceful signal, bounded and never blocking the stop; recorded in
state.json so the next start runs it after a crash.

Refs #245

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ADR-0059)

`[services.<name>] stop` is expanded with the instance's placeholders when
it starts (its `{port}`, `{lane_suffix}`, as `run`) and runs whenever the
instance ends: a stop, a restart, `down`, the old instance a candidate
replaced, a start or candidate that failed, a job done, an instance that
ended by itself. It runs before the graceful signal, at most 30 s, its
output appended to the instance's log; a failure is logged and the stop
goes on (ADR-0009). Every end of an instance now goes through one place,
`Supervisor::end`.

The expanded command, its directory and the instance's log are recorded in
state.json beside the cleanup record (ADR-0016); the next start of the
tree's supervisor runs the recorded ones before anything starts, with
devstack's own environment (the service's is not written to disk).

A profile may set `stop`; `kind = "static"` has none, and a profile that
makes a service static drops it; hot-reload mode does not use it.
`devstack check` warns about `stop` without `requires = "0.21.0"`.
docs/stack-file.md describes a container as a service (`--init`, `--rm`, a
name per instance, `stop`); the devstack-config skill says the same.

Refs #245

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@7schmiede
7schmiede merged commit f7df7ed into main Oct 23, 2026
13 checks passed
@7schmiede
7schmiede deleted the feat/service-stop branch October 23, 2026 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant