{"record":{"id":"328572cb560d43be","repo":"benbjohnson/litestream","slug":"cannot-run-windows-service-as-unix-process","errorCode":null,"errorMessage":"cannot run windows service as unix process","messagePattern":"cannot run windows service as unix process","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"cmd/litestream/main_notwindows.go","lineNumber":19,"sourceCode":"//go:build !windows\n\npackage main\n\nimport (\n\t\"context\"\n\t\"os\"\n\t\"os/signal\"\n\t\"syscall\"\n)\n\nconst defaultConfigPath = \"/etc/litestream.yml\"\n\nfunc isWindowsService() (bool, error) {\n\treturn false, nil\n}\n\nfunc runWindowsService(ctx context.Context) error {\n\tpanic(\"cannot run windows service as unix process\")\n}\n\nfunc signalChan() <-chan os.Signal {\n\tch := make(chan os.Signal, 2)\n\tsignal.Notify(ch, syscall.SIGINT, syscall.SIGTERM)\n\treturn ch\n}\n","sourceCodeStart":1,"sourceCodeEnd":27,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/cmd/litestream/main_notwindows.go#L1-L27","documentation":"This panic is a hard guard in the non-Windows build of Litestream (main_notwindows.go). runWindowsService is only meaningful on Windows where the binary runs as a Windows service; on Unix builds it is unreachable by design, so it panics instead. If you see it, platform detection (isWindowsService) on your build incorrectly reported a Windows service context or the wrong build was invoked via that path.","triggerScenarios":"Calling cmd/litestream's service-launch path (runWindowsService) on a Unix build. Normally unreachable because isWindowsService() always returns (false, nil) on non-Windows; only a code path change or direct call would reach the panic.","commonSituations":"Custom forks or patches that modified the isWindowsService check; embedding litestream's main package internals in another program and calling runWindowsService on Linux/macOS; using a binary built from modified source instead of the released binary.","solutions":["Do not call runWindowsService on Unix; run litestream directly (litestream replicate -config ...) and rely on systemd/launchd for supervision","Verify you are running an unmodified official litestream build; rebuild from a clean checkout","If embedding litestream as a library, use the public API (litestream.NewDB/NewReplica, Store) instead of the CLI/service plumbing"],"exampleFix":"// before: embedding code calls CLI internals on Linux\nrunWindowsService(ctx)\n// after: run normally under systemd/launchd\nexec.Command(\"litestream\", \"replicate\", \"-config\", \"/etc/litestream.yml\").Run()","handlingStrategy":"validation","validationCode":"// Only reach the Windows-service path on Windows builds\nif runtime.GOOS == \"windows\" {\n    if isSvc, err := isWindowsService(); err == nil && isSvc {\n        return runWindowsService(ctx)\n    }\n}\nreturn runNormal(ctx)","typeGuard":"func isUnixBuild() bool { return runtime.GOOS != \"windows\" } // then never call runWindowsService","tryCatchPattern":"// panic is not recoverable by design at this layer; guard the call site\nif isSvc, err := isWindowsService(); err != nil {\n    return err\n} else if isSvc {\n    if runtime.GOOS == \"windows\" {\n        return runWindowsService(ctx)\n    }\n}","preventionTips":["Never call runWindowsService from non-Windows code paths; check runtime.GOOS first","Run litestream on Unix via systemd/launchd instead of a service wrapper","Build from the official source; avoid patches that alter isWindowsService","When embedding, use the litestream library API, not cmd/litestream internals"],"tags":["windows","platform","panic","cli"],"backgroundTag":"unsupported-platform","analyzedSha":"4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3","analyzedAt":"2026-09-06T18:29:25.564Z","contentChangedAt":"2026-09-06T18:29:25.564Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}