Repository navigation
feat(spored): run as a native Windows Service (#77 stage 3) - #86
Merged
Merged
Conversation
spored can now run under the Windows Service Control Manager with the same
lifecycle daemon, so a Windows instance self-manages like Linux.
- cmd/spored/service_windows.go: svc.Handler that runs runDaemon() in the
background and maps SCM Stop/Shutdown → requestStop() → graceful cleanup;
reports StartPending/Running/StopPending to the SCM. Plus a `spored service
install|uninstall|start` subcommand (auto-start + on-failure restart, matching
the systemd unit) for the installer to call.
- shutdown_{windows,other}.go: waitForShutdown() factored per-OS — Unix blocks
on SIGINT/SIGTERM (unchanged behavior); Windows blocks on the SCM stop channel
or console signals. main.go's daemon loop now calls waitForShutdown() instead
of an inline signal block.
- platform_{windows,other}.go: main() runs under the SCM when svc.IsWindowsService()
(else normal CLI), and registers the `service` subcommand on Windows only.
- golang.org/x/sys promoted to a direct dependency.
Validated on real Windows 11 (black3) over SSH: install → start (service
RUNNING) → daemon ran with graceful local-provider fallback (no EC2 IMDS on a
laptop) → "monitor tick 1" → sc stop drove "Shutting down… → cleanup → spored
stopped → STOPPED" → uninstall. Full SCM lifecycle works.
GOOS=windows + GOOS=linux build clean; host tests + make check unchanged.
Note: a few /var/lib/spored runtime paths (push token, plugin state, queue)
are still Unix-shaped and write to bogus locations on Windows — non-fatal
(optional features) and folded into Stage 4's path/install work.
Refs #77.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Stage 3 of Windows spored (#77): spored runs under the Windows Service Control Manager with the same lifecycle daemon, so a Windows instance self-manages like Linux.
cmd/spored/service_windows.go:svc.Handlerthat runsrunDaemon()in the background and maps SCM Stop/Shutdown →requestStop()→ graceful cleanup; reports StartPending/Running/StopPending. Plus aspored service install|uninstall|startsubcommand (auto-start + on-failure restart, matching the systemd unit) for the installer.shutdown_{windows,other}.go:waitForShutdown()factored per-OS — Unix blocks on SIGINT/SIGTERM (unchanged); Windows blocks on the SCM stop channel or console signals. The daemon loop callswaitForShutdown()instead of an inline signal block.platform_{windows,other}.go:main()runs under the SCM whensvc.IsWindowsService()(else normal CLI), and registersserviceon Windows only.golang.org/x/syspromoted to a direct dependency.Validated on real Windows 11 (over SSH)
service install→sc start(RUNNING) → daemon ran with graceful local-provider fallback (no EC2 IMDS on a laptop) →monitor tick 1→sc stopdrove "Shutting down… → cleanup → spored stopped → STOPPED" →uninstall. Full SCM lifecycle works, including graceful shutdown.GOOS=windows+GOOS=linuxbuild clean; host tests +make checkunchanged.Note
A few
/var/lib/sporedruntime paths (push token, plugin state, queue) are still Unix-shaped and write to bogus locations on Windows — non-fatal (optional features; the daemon ran fine) and folded into Stage 4's path/install work.Refs #77. Next: Stage 4 — installer (
install-spored.ps1, S3 download mirroringinstall-spored.sh), GoReleaserwindows/amd64+ S3 upload, launch wiring, and the remaining path fixes.