-
-
Notifications
You must be signed in to change notification settings - Fork 97
Description
Describe the bug
Attempting to register and start sql_exporter.exe (v0.18.4) as a Windows Service fails consistently with an operating system error (StartServiceFailed and sometimes the low-level ERROR 487), even when using the technically correct binPath syntax. The binary is unable to maintain execution in the Windows Service Control Manager (SCM) environment, leading to an immediate crash upon attempting to start. This suggests a Go binary/Windows API incompatibility rather than a configuration error.
To Reproduce
This bug occurs when attempting to load any configuration file via the Windows Service layer:
System: Windows Server (reproducible on various versions, tested on 2019/2022).
Files: Use the sql_exporter.exe binary (Version 0.18.4) and a valid config.yml.
Command: Attempt to create and start the service using the correct New-Service or sc.exe syntax:
PowerShell
$BinPath = "C:\ruta\sql_exporter.exe"
$CfgPath = "C:\ruta\config.yml"
$FullCommand = ('"{0}" --config.file="{1}"' -f $BinPath, $CfgPath)
Attempt to create using native utility
sc.exe create sql_exporter_test binPath= "$FullCommand" start= auto DisplayName= "Prometheus SQL Exporter Test"
Start-Service sql_exporter_test
Error Seen (PowerShell): Start-Service : No pudo iniciarse el servicio... (ServiceCommandException: StartServiceFailed).
Error Seen (SCM): The low-level utility sc.exe create often fails with ERROR 487: Se ha intentado tener acceso a una dirección no válida, indicating a conflict during the registration process itself.
Expected behavior
The service should register successfully and transition to a Running state, listening on its configured port (e.g., 9399), as it does when executed manually in the foreground.
Configuration
Exporter Version: 0.18.4.
OS: Windows Server.
Environment: Executed as NT AUTHORITY\SYSTEM (via SCM).
Additional context
Functional Mode: The binary works perfectly when executed manually in the console (.\sql_exporter.exe --config.file="config.yml"). This confirms the configuration file is valid.
Workaround: The only stable way to run this version in the background is by registering the command via Windows Task Scheduler (schtasks), not via New-Service or sc.exe, confirming a failure in the service control integration.