Skip to content

feat(spored): run as a native Windows Service (#77 stage 3) - #86

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/77-windows-spored-stage3
Jun 8, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/77-windows-spored-stage3

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

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.Handler that runs runDaemon() in the background and maps SCM Stop/Shutdown → requestStop() → graceful cleanup; reports StartPending/Running/StopPending. Plus a spored service install|uninstall|start subcommand (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 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 service on Windows only.
  • golang.org/x/sys promoted 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 stop drove "Shutting down… → cleanup → spored stopped → STOPPED" → uninstall. Full SCM lifecycle works, including graceful shutdown.

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; the daemon ran fine) and folded into Stage 4's path/install work.

Refs #77. Next: Stage 4 — installer (install-spored.ps1, S3 download mirroring install-spored.sh), GoReleaser windows/amd64 + S3 upload, launch wiring, and the remaining path fixes.

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

codecov Bot commented Jun 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 20 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/spored/main.go 0.00% 14 Missing ⚠️
cmd/spored/shutdown_other.go 0.00% 4 Missing ⚠️
cmd/spored/platform_other.go 0.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 0ea9e39 into main Jun 8, 2026
2 of 3 checks passed
@scttfrdmn
scttfrdmn deleted the feat/77-windows-spored-stage3 branch June 8, 2026 22:33
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