-
Notifications
You must be signed in to change notification settings - Fork 685
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
Propagate windows service start parameters #82
Comments
A new method (e.g. Would you be interested in a PR? |
The |
Are the args passed into Execute different then os.Args()? |
Yes, Windows seems to distinguish between:
AFAIU the arguments passed to As an example, both
Note that, in the last example you are free to choose service start arguments different from the ones passed to the binary ( |
@kardianos I got the problem too. However, when I run my code with builded binary executer, the problem appeared: |
Any news about this? Something like what @2opremio proposed would be really nice to have :-) |
Oh, we can already manually propagate arguments! Sorry about the noise... I ended up using something like: nameFlag := flag.String("name", "dummy", "Service name.")
flag.Parse()
s, err := service.New(
&dummyService{},
&service.Config{
Arguments: []string{"-name", *nameFlag},
Name: *nameFlag,
DisplayName: "Dummy Windows Service",
Description: "Dummy Windows Service",
}) |
Can this technique of passing arguments be used to say create a "Delayed" start service? |
Yes. |
@rgl , does this example actually propagate the live argument as @2opremio called out? |
I did more investigation, and see adding a line of ws.Arguments = append(ws.Arguments, args...) in Execute method of service_windows.go solved the issue for me.
then in my usage, I declare service.Config to my program struct, and then in program Start method access the parameter from p.config.Arguments, and I've validated that could propagate the live arguments from service control manager. @kardianos , how do you feel this solution? |
@chuanbozhang-okta @kardianos @rgl Is support for runtime arguments like below supported in windows service start method?
to be explicit when a customer starts the service with a runtime port number, I need to access this runtime parameter somehow or injected somhow.
|
@msays2000 , yes, my proposal fix above to add "ws.Arguments = append(ws.Arguments, args...)" to Execute method could fix the issue and make your usage work. @kardianos , do you accept contribution for this? If so I could send a PR for it. |
@chuanbozhang-okta thank you for confirming. We have a use case where we need to start a grpc service on a determined port passed to the service via its start arguments. |
@kardianos is there an alternative to pass the arguments to a service. |
This library simply ignores and doesn't propagate the start parameters of windows services.
Those live parameters are very convenient and flexible, allowing to avoid configuration files or registry keys to store the parameters.
Related to #75
The text was updated successfully, but these errors were encountered: