Repository navigation
✨ feat: add --poweroff signal-init for a non-systemd init - #16
Conversation
|
| Filename | Overview |
|---|---|
| cmd/run/run.go | Adds --poweroff CLI flag wired to Config.PoweroffMode; flag value is not validated and silently falls back to systemctl on typo |
| pkg/shutdown.go | Replaces hard-coded systemctl poweroff with an injectable poweroffFunc; adds poweroffFor dispatcher and killPID1 package var for testability; logic is clean |
| pkg/shutdown_strategy_test.go | New Ginkgo specs covering both strategies; mutates package-level killPID1 which is safe for sequential specs but fragile under parallel execution |
| pkg/stereosd.go | Adds PoweroffMode to Config, defaults to PoweroffSystemctl, and threads it through to NewShutdownCoordinator; straightforward and correct |
| pkg/stereosd_test.go | Existing ShutdownCoordinator test updated to pass PoweroffSystemctl to match new constructor signature; no functional change |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Host sends shutdown command] --> B[ShutdownCoordinator.Execute]
B --> C[UnmountAll shared directories]
C --> D[sync filesystems]
D --> E{poweroffFunc selected at startup}
E -->|PoweroffSystemctl default| F[Commander.Run systemctl poweroff]
E -->|PoweroffSignalInit --poweroff signal-init| G[killPID1 syscall.Kill 1 SIGTERM]
F --> H[systemd SIGTERMs all services incl. agentd]
G --> I[capstan PID 1 stops supervised services and calls reboot RB_POWER_OFF]
H --> J[VM powers off]
I --> J
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
A[Host sends shutdown command] --> B[ShutdownCoordinator.Execute]
B --> C[UnmountAll shared directories]
C --> D[sync filesystems]
D --> E{poweroffFunc selected at startup}
E -->|PoweroffSystemctl default| F[Commander.Run systemctl poweroff]
E -->|PoweroffSignalInit --poweroff signal-init| G[killPID1 syscall.Kill 1 SIGTERM]
F --> H[systemd SIGTERMs all services incl. agentd]
G --> I[capstan PID 1 stops supervised services and calls reboot RB_POWER_OFF]
H --> J[VM powers off]
I --> J
Prompt To Fix All With AI
Fix the following 2 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 2
cmd/run/run.go:48-49
**Unvalidated `--poweroff` flag silently falls back to systemctl**
`poweroffFor` treats any unrecognised string as `PoweroffSystemctl`. A user running stereosd under capstan who types `--poweroff signal_init` (underscore) or any other typo will silently get the systemd path, the shutdown will fail at the `systemctl` call, and the VM will never power off — without any indication of misconfiguration. Consider validating the flag value in `runDaemon` (or in `poweroffFor`) and returning an early error for unknown modes.
### Issue 2 of 2
pkg/shutdown_strategy_test.go:21-24
**Package-level variable mutation is unsafe under parallel specs**
`killPID1` is a package-level `var`, so any concurrent spec that also exercises `signalInitPoweroff` (e.g., after a future refactor adds a second signal-init test) would race on the write. The approach works today because Ginkgo specs within one process are sequential, but it is easy to break. The conventional Go pattern is to make `killPID1` a field on `ShutdownCoordinator` (already injectable via the constructor) rather than a naked package var, which also removes the need for `DeferCleanup` restoring global state.
Reviews (1): Last reviewed commit: "✨ feat: add --poweroff signal-init for a..." | Re-trigger Greptile
b734c15 to
7be4d4d
Compare
The shutdown coordinator hardcoded `systemctl poweroff`, which assumes systemd owns the services and will SIGTERM them on its way down. Under a minimal init (capstan as PID 1) there is no systemd, so that call fails and nothing powers off. Add a `--poweroff` strategy, selected by `Config.PoweroffMode`. The default `systemctl` mode is unchanged for the systemd-based stereOS image. The `signal-init` mode sends SIGTERM to PID 1 and lets init stop supervised services and call reboot(2) itself. The power-off step is selected explicitly, and unknown mode strings are rejected before daemon startup. The PID 1 signal function is stored on each shutdown coordinator so tests can inject a fake without mutating package-level state. Part of PCC-777.
The daggerverse ghcontrib module now requires dagger v0.20.8, so the PR checks (title conformance, Linear magic word) error out under the pinned v0.20.6 with "module requires dagger v0.20.8, but you have v0.20.6".
7be4d4d to
f8dee14
Compare
Summary
The shutdown coordinator hardcoded
systemctl poweroff, which assumes systemdowns the services and will SIGTERM them on the way down. Under a minimal init
(capstan as PID 1) there is no systemd, so shutdown failed and the VM never
powered off.
Adds a
--poweroffstrategy (Config.PoweroffMode):systemctl(default, unchanged):systemctl poweroff.signal-init: SIGTERM PID 1 and let init stop the supervised services andreboot(2).The power-off step is now an injectable function on the coordinator; the actual
kill(1, SIGTERM)sits behind a package var so the new test exercisessignal-init without signalling its own init.
Context: lets stereosd run under capstan (a minimal Rust PID 1 for microVM
sandboxes) as well as the systemd-based stereOS image.
Test plan
gofmt/go vet ./...cleanpkg/shutdown_strategy_test.go: defaults to systemctl; signal-initsignals PID 1 and never runs systemctl
make test— change is isolated to the shutdown path; the new specs pass.Note:
make testruns-raceand trips a pre-existing data race in theIPCServerServe/Close lifecycle test (pkg/ipc.go), reproducible onmainand unrelated to this change.Part of PCC-777.