Reputation: 752
I have created an executable in Go and I am running it as a windows service.
I am using golang.org/x/sys/windows/svc package, and provide it with the Execute method which gets called by the SCM
run := svc.Run
_ = run(svcName, &myservice{})
func (m *myservice) Execute(args []string, r <-chan svc.ChangeRequest, changes chan<- svc.Status) (ssec bool, errno uint32) {
changes <- svc.Status{State: svc.StartPending}
go mainmethod()
changes <- svc.Status{State: svc.Running, Accepts: cmdsAccepted}
}
The service works most of the time but the problem is that whenever I restart my system, the service gives me a Error 1053 : "The service did not respond to start or control request in a timely fashion" error and does not start,
After adding the log statements in my run and Execute methods, I figured out that when the service starts without error the logs get printed, but when the services gives a 1053 error the SCM does not even invoke my exe, since none of the log statements get printed. Has anyone tried creating a windows service in a similar way? Is it a problem with implementation or the windows svc package?
Upvotes: 1
Views: 2174
Reputation: 752
I have the GO exe deployed in Program Files, I changed the LogOnAs attribute of Windows Service to "Local Service" and gave "Local Service" complete Access to the installation folder in "Folder Security".
This seems to fix the issue for windows10. The service starts on windows restart, But this fix still does not work for windows 7 and windows8.
Edit:
Making the service "Automatic Delayed" works, however you have to wait for the service start after boot which takes 2-3 minutes.
The answer mentioned here helped: https://serverfault.com/questions/697608/automatic-windows-service-not-starting/697852#697852?newreg=788f7ab0bb084fec85d1ce2e51bf8317
Upvotes: 1