influxdb icon indicating copy to clipboard operation
influxdb copied to clipboard

Windows service wrapper

Open mintyc opened this issue 10 years ago • 5 comments

I see you mention future plans to include a windows service manager. May I suggest nssm.cc as a 3rd party wrapper around your executable. Weve used it with a number of our cross platform products and it easy to configure, reliable and allows your app to write to std streams and will capture and log to logrotated files. Not quite event viewer but a reasonable alternative that is easily text searchable. Just trap ctrl c or similar so that nssm can start / stop and most service deployment work is trivial.

mintyc avatar Jan 20 '16 21:01 mintyc

Need a couple of tweaks to their git latest to allow building on vs2015 64 bit. 5 mins, obvious changes. Using text scripts to set up the service or allow access to a ui edit tool. I gladly took win specific service code away from my app. Bonus is its also to run as an executable for debugging.

mintyc avatar Jan 20 '16 21:01 mintyc

@mintyc thanks for the suggestion, but we probably won't be building against any external libraries that aren't written in Go. closing this out!

toddboom avatar Jan 20 '16 22:01 toddboom

Nssm is an app that is like the windows built in svcany. It doesnt care what language your command is implemented in.

You can download as an installer but if you want the latest features or a 64 bit build you would need to compile and tweak code in c++. It is completely decoupled from your app and can wrap an executable in 5 mins provided it responds to one of several methods for stopping the app. If we get telegraf 0.10 working on windows we'll probably wrap it using nssm. We wrap ruby web servers c++ apps and scripts very easily. Just suggesting you dont need to necessarily sully your codebase directly with implementing the windows service interface.

mintyc avatar Jan 21 '16 21:01 mintyc

@mintyc @toddboom @e-dard You could look at https://github.com/judwhite/go-svc (forgive the self-reference)

It's used in nsqd/nsqlookupd https://github.com/nsqio/nsq/blob/454cf2f56a35bbd5c9179d2921ee204d822b9f20/apps/nsqd/nsqd.go#L177

judwhite avatar Nov 02 '16 11:11 judwhite

NSSM hasn't been updated in almost a decade and has serious bugs in Windows 10 and later.

Please reopen this issue and implement running as a native windows service. There is no need for a separate executable. You just try to become a service, and fallback to a regular process if you couldn't.

At the beginning of main(), on Windows only, you call StartServiceCtrlDispatcher(). If it returns 0, you call GetLastError(), and if that returns ERROR_FAILED_SERVICE_CONTROLLER_CONNECT, then you are not a service and you proceed with normal startup.

alexchandel avatar Aug 28 '25 21:08 alexchandel