agent: P2-16 Windows service (SCM) integration
internal/agent/service: build-tagged into service_windows.go (svc.Handler that listens for Stop/Shutdown + delegates to the agent loop) and service_other.go (foreground stub for Linux/macOS). install_windows.go wraps mgr.Connect+CreateService/Delete/Start/Stop for the new 'restic-manager-agent install|uninstall|start|stop' subcommands. Cross-compile verified: GOOS=windows GOARCH=amd64 go build ./cmd/agent succeeds. UNTESTED on Windows itself — the SCM round-trip can't be exercised from Linux CI; treat as a starting point for the first real Windows install.
This commit is contained in:
@@ -17,6 +17,7 @@ import (
|
||||
"gitea.dcglab.co.uk/steve/restic-manager/internal/agent/runner"
|
||||
"gitea.dcglab.co.uk/steve/restic-manager/internal/agent/scheduler"
|
||||
"gitea.dcglab.co.uk/steve/restic-manager/internal/agent/secrets"
|
||||
"gitea.dcglab.co.uk/steve/restic-manager/internal/agent/service"
|
||||
"gitea.dcglab.co.uk/steve/restic-manager/internal/agent/sysinfo"
|
||||
"gitea.dcglab.co.uk/steve/restic-manager/internal/agent/wsclient"
|
||||
"gitea.dcglab.co.uk/steve/restic-manager/internal/api"
|
||||
@@ -33,6 +34,27 @@ func main() {
|
||||
}
|
||||
|
||||
func run() error {
|
||||
// Optional first positional verb for SCM control on Windows.
|
||||
// `restic-manager-agent install|uninstall|start|stop` route into
|
||||
// the service package; everything else falls through to the
|
||||
// flag-driven default (which is what systemd / interactive runs
|
||||
// hit). On non-Windows builds these verbs return a clear error.
|
||||
if len(os.Args) > 1 {
|
||||
switch os.Args[1] {
|
||||
case "install":
|
||||
return service.Install()
|
||||
case "uninstall":
|
||||
return service.Uninstall()
|
||||
case "start":
|
||||
return service.Start()
|
||||
case "stop":
|
||||
return service.Stop()
|
||||
case "run":
|
||||
// Strip the verb so flag.Parse sees the rest unchanged.
|
||||
os.Args = append([]string{os.Args[0]}, os.Args[2:]...)
|
||||
}
|
||||
}
|
||||
|
||||
configPath := flag.String("config", config.DefaultPath(), "path to agent.yaml")
|
||||
enrollServer := flag.String("enroll-server", "", "server URL (used with -enroll-token to perform first-run enrollment)")
|
||||
enrollToken := flag.String("enroll-token", "", "one-time enrollment token (operator copies this from the UI)")
|
||||
|
||||
Reference in New Issue
Block a user