Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

daemon service does not work in windows10 #94

Open
arthur-kb opened this issue Jul 28, 2020 · 7 comments
Open

daemon service does not work in windows10 #94

arthur-kb opened this issue Jul 28, 2020 · 7 comments

Comments

@arthur-kb
Copy link

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.

@filippo-veneri
Copy link

filippo-veneri commented Aug 21, 2020

See my pull request #97
Restructuring your service as i've done with the myservice example should make it work on windows.

@daniel-007
Copy link

I updated to golang.org/x/sys v0.0.0-20200905004654-be1d3432aa8f, but it still does't work.

@filippo-veneri
Copy link

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.

@sithembiso
Copy link

@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 :-)

@sithembiso
Copy link

This is also related to #68

@filippo-veneri
Copy link

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.

@kutterback
Copy link

kutterback commented Jul 27, 2023

Note that MyService implements the daemon.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

return service.Run(mysvc)

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

No branches or pull requests

5 participants