prometheus-community / smartctl_exporter

Export smartctl statistics to prometheus
Apache License 2.0
288 stars 86 forks source link

Feature request: Windows Service mode #163

Open easymoney322 opened 1 year ago

easymoney322 commented 1 year ago

I'd like to see support for the service mode in Windows. Right now, if you just make service, Windows will kill (Error 7000) the process on timeout (Error 7009). Im unable to use task scheduler on some systems due to unstabilites, like when TS just finishes the task right after the start. Docker containers wont work on old systems, And computer startup scripts are the only workarounds, but are harder to control remotely.

NiceGuyIT commented 1 year ago

How are you creating the service?

I wonder what other exporters use. :thinking: node_exporter recommends windows_exporter which uses an MSI for installation. dellhw_exporter uses sc.exe.

easymoney322 commented 1 year ago

I was creating it manually with PowerShell New-Service, and I think it doesn't really matter, since all the services are managed by Service Control Manager in the end. The service works fine for ~30s, before SCM kills it for not responding to the system calls. This timeout is set at global level and can't be changed for any service individually.

Windows_exporter works fine, is able to work as a service, and creates one during the installation. Same goes for OHM-Graphite.

If I understood Microsoft's Docs correctly, support for an app to work as a service must be implemented in the executable itself. For C++ it would be made via "winsvc.h". I don't know how it can be implemented with Go language, as I have no experience with Go. I'd suggest reading this https://github.com/golang/go/issues/23479

How are you creating the service?

I wonder what other exporters use. 🤔 node_exporter recommends windows_exporter which uses an MSI for installation. dellhw_exporter uses sc.exe.

Informatic commented 1 month ago

One fairly simple workaround for this (and a correct solution if some application you want to run doesn't implement Windows service protocol) would be using something like nssm.

easymoney322 commented 1 month ago

and a correct solution

IMO NSSM (as well as winsw) should be a workaround where an app can't be modified to run as a service.

The only correct solution (which would also decrease an ammount of third-party moving parts and would make an app self-contained) would be to use the system API itself. For C/C++ it would be winsvc.h. I made a quick search in google and it looks this is possible in golang too via func RegisterServiceCtrlHandlerEx from "Windows" package.

Also, Im not sure if NSSM and WinSW release builds exist for an ARM architecture Windows deployments.