shutdown-order (top-level) controls the sequence in which services are stopped during graceful shutdown.
# Graceful shutdown ordering. With reverse-dep (the default), dependents
# stop before the dependencies they rely on.
shutdown-order: reverse-dep
processes:
- name: db
command: /bin/sh
args: ["-c", "trap 'echo db >> STOPLOG; exit 0' TERM; while true; do sleep 0.2; done"]
on-failure: shutdown
- name: app
command: /bin/sh
args: ["-c", "trap 'echo app >> STOPLOG; exit 0' TERM; while true; do sleep 0.2; done"]
after: [db]
on-failure: shutdownThe three strategies:
reverse-dep(default) — stop dependents first, then their dependencies. Hereappstops beforedb.dep— stop dependencies first, then dependents.dbwould stop beforeapp.simultaneous— signal all services at once.
dbstarts, thenapp(which depends on it).- On SIGTERM with
reverse-dep,appreceives SIGTERM and exits beforedbis signaled. - gopherd exits 0 once all services have stopped.
Each service traps SIGTERM and appends its name to a shared log file before exiting. The test replaces the STOPLOG token with a temp-dir path, starts the daemon, waits for both services to be running, then sends SIGTERM.
Because reverse-dep stops sequentially — signaling a service and waiting for it to exit before moving to the next — the log order is deterministic. The test asserts that the log contains exactly ["app", "db"], proving that the dependent stopped before its dependency.
go test ./documentation/shutdown-order/ -v