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

x/sys/windows/svc: example service fails to start #42596

Closed
aapi-rp opened this issue Nov 13, 2020 · 3 comments
Closed

x/sys/windows/svc: example service fails to start #42596

aapi-rp opened this issue Nov 13, 2020 · 3 comments

Comments

@aapi-rp
Copy link

aapi-rp commented Nov 13, 2020

What version of Go are you using (go version)?

$ 1.14.7

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ Windows 10 64bit

What did you do?

I ran the example as built via the terminal, example can be found here: https://github.com/golang/sys/tree/0a15ea8d9b02651b828a1b41989a6af25c24cb64/windows/svc/example

Commands run:
"go run main.go install" This command worked, it installed the service
"go run main.go start" This command failed with "failed to start myservice: could not start service: The system cannot find the file specified"

What did you expect to see?

I expected the service to actually work, and show in the services menu.

What did you see instead?

"failed to start myservice: could not start service: The system cannot find the file specified"

@mdlayher mdlayher changed the title Example does not work. x/sys/windows/svc: example service fails to start Nov 13, 2020
@gopherbot gopherbot added this to the Unreleased milestone Nov 13, 2020
@networkimprov
Copy link

cc @alexbrainman @mattn

@gopherbot add OS-Windows

@alexbrainman
Copy link
Member

Commands run:
"go run main.go install" This command worked, it installed the service

Not true.

The way Windows service is installed is by calling CreateService Windows API

https://docs.microsoft.com/en-us/windows/win32/api/winsvc/nf-winsvc-createservicew

And that API requires you to provide full path to your service executable (see lpBinaryPathName parameter). And, once installed, the service executable cannot be moved (until service is deleted), because Windows will try to run it when you request Windows to start your service.

When you use go run ... command, your executable is built inside of TEMP directory, executed and gets deleted immediately. So when you run go run main.go start your service executable is gone. That is why Windows is complaining.

Do not use go run ... command with this example. Build executable instead. Copy built executable to a location where it could remain until you remove your service.

Alex

@cagedmantis
Copy link
Contributor

This issue has received a sufficient response from @alexbrainman. Please re-open the issue if you believe it's been close in error.

@golang golang locked and limited conversation to collaborators Nov 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants