Running VMagent (Windows) as a service
machinedrummer opened this issue ยท 8 comments
Is there a guide on how to run VMAgent as a Windows Service?
When I try to setup a service it keeps crashing (Windows gets no response). I can see process is started but seems exe does not support running as a Windows service.
The service did not respond to the start or control request in a timely fashion.
Example of service setup, environment variables are set and location is correct. I can see storage folder created and persistent-queue gets populated with files. I can execute it from shell and it runs fine but I'm unable to setup as a windows service.
$Name = "VMAgent"
$params = @{
Name = $Name
BinaryPathName = '"C:\VMAgent\vmagent-windows-amd64-prod.exe" -envflag.enable'
DisplayName = $Name
StartupType = "Auto"
Description = "$Name is used to send server event logs and metrics to centralized monitoring server."
}
New-Service @params
Hello, currently it's not possible in native mode for vmagent. It doesn't have window service integration.
You have to use some windows service wrapper like https://github.com/winsw/winsw
Thank you,
Are there plans for windows service integration? If yes, is there a link I could track?
I was looking at https://nssm.cc/download, but that is not actively maintained, and will definitely check winsw.
For now, there is no such plans, maybe @valyala could prioritize it.
Related integration example https://cs.opensource.google/go/x/sys/+/refs/tags/v0.5.0:windows/svc/example/
@machinedrummer , VictoriaMetrics team has no good expertise in Windows, so it would be great to get help from the community for implementing this feature request.
Thank you,
I understand, for now I will use winsw.
In case someone else is looking on how to run it as a service, this is how I tested.
In this example I decided to reuse existing windows_exporter directory (https://github.com/prometheus-community/windows_exporter/releases latest msi).
Download vmagent-windows-amd64-prod.exe and place it under C:\Program Files\windows_exporter
Create C:\Program Files\windows_exporter\VMAgent.xml
<service>
<id>VMAgent</id>
<name>VMAgent</name>
<description>This service is a service created from a sample configuration</description>
<executable>%BASE%\vmagent-windows-amd64-prod.exe"</executable>
<onfailure action="restart" delay="10 sec"/>
<onfailure action="restart" delay="20 sec"/>
<resetfailure>1 hour</resetfailure>
<arguments>-envflag.enable</arguments>
<priority>Normal</priority>
<stoptimeout>15 sec</stoptimeout>
<stopparentprocessfirst>true</stopparentprocessfirst>
<startmode>Automatic</startmode>
<waithint>15 sec</waithint>
<sleeptime>1 sec</sleeptime>
<logpath>%BASE%\logs</logpath>
<log mode="roll">
<sizeThreshold>10240</sizeThreshold>
<keepFiles>8</keepFiles>
</log>
<!--
SECTION: Environment setup since we are using -envflag.enable switch
-->
<env name="loggerFormat" value="json" />
<env name="loggerOutput" value="stderr" />
<env name="remoteWrite_url" value="https://x.x.x.x/prometheus" />
<env name="remoteWrite_maxDiskUsagePerURL" value="52428800" />
<env name="promscrape_fileSDCheckInterval" value="5s" />
<env name="promscrape_suppressScrapeErrors" value="false" />
<env name="remoteWrite_tmpDataPath" value="C:\Program Files\windows_exporter\storage" />
<env name="promscrape_config" value="C:\Program Files\windows_exporter\promscrape.yml" />
</service>
Download winsw from https://github.com/winsw/winsw/releases/download/v2.12.0/WinSW-x64.exe
Rename WinSW-x64.exe to VMAgent.exe and move it to C:\Program Files\windows_exporter
From elevated powershell run
& "C:\Program Files\windows_exporter\VMAgent.exe" install VMAgent.xml
Get-Service VMAgent | Start-Service
Please note that for winsw .XML name must match .EXE name
I've created a Chocolatey packages which installs WinSW as well as VMAgent automatically and adds it as Service to Windows.
Thanks for @machinedrummer as I use the same XML as base and it is working flawless right now.
I've created a Chocolatey packages which installs WinSW as well as VMAgent automatically and adds it as Service to Windows.
Hi! Is that available anywhere public?
I've created a Chocolatey packages which installs WinSW as well as VMAgent automatically and adds it as Service to Windows.
Hi! Is that available anywhere public?
Hey @lapo-luchini , unfortunately the release process of chocolatey is not as straight forward as we hoped so it is not in their public repo. But we do have an Installation guide on how to use chocolatey for a manual installation: https://github.com/symflower/vmutils-bin/tree/main/Choco
We are still working on a chocolatey release but for now this is the manual step is the only thing we can provide.
If you have any questions or want to contribute feel free.