daemon
daemon copied to clipboard
daemon service does not work in windows10
Attempting to start windows service results in a long pause and the following error returned:
Error: The service did not respond to the start or control request in a timely fashion.
See my pull request #97 Restructuring your service as i've done with the myservice example should make it work on windows.
I updated to golang.org/x/sys v0.0.0-20200905004654-be1d3432aa8f, but it still does't work.
Updating the dependency was just a side-effect, not at all necessary. The important thing is to restructure your code as i have done in my pull request. If you clink on the PR link (#97) and then on "Files changed" you'll see what modifications i have done to examples/myservice.go to make it work.
@filippo-veneri I just looked at the code on your PR and I couldn't help but wonder why and how it "works"? Unless I missed it, I don't see any place where you are calling (daemon.Daemon).Start()
. You seem to have implemented your own start method which does something else. At what point does it actually start the daemon (windows service). Could this explain why you are not getting this issue?
Appreciate your contribution on this :-)
This is also related to #68
It is a bit convoluted. On Windows the (daemon.Daemon).Install()
interface method refers to the (daemon.windowsRecord).Install()
concrete method. Assuming your service executable is named myservice.exe, this method creates the windows service using the path of myservice.exe as the service executable.
When the windows service is started, myservice.exe is executed without parameters, resulting in service.Run(mysvc)
(defined in myservice.go) being called, which, in this case, corresponds to (daemon.windowsRecord).Run(e Executable)
. This method then calls svc.Run(windows.name, &serviceHandler{executable: e})
which in turn calls (daemon.serviceHandler).Execute(...)
, which is the main loop of the windows service.
In response to the windows service state changes this loop calls the MyService.Start()
and MyService.Stop()
methods. Note that MyService
implements the daemon.Executable
interface.
Note that
MyService
implements thedaemon.Executable
interface.
I was running into a similar issue and found @filippo-veneri is correct. The example service does not work on the master branch. Your code needs to implement the daemon.Executable
interface and be passed into daemon.Run(MyService)
instead of the structure on the master branch. Look at their PR for a proper example https://github.com/takama/daemon/blob/c329ab930e326908bf8d91a622481e6d124343e4/examples/myservice.go#L131