Skip to content
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

Running VMagent (Windows) as a service #3781

Open
machinedrummer opened this issue Feb 7, 2023 · 8 comments
Open

Running VMagent (Windows) as a service #3781

machinedrummer opened this issue Feb 7, 2023 · 8 comments
Labels
enhancement New feature or request help wanted Extra attention is needed vmagent windows

Comments

@machinedrummer
Copy link

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
@f41gh7
Copy link
Contributor

f41gh7 commented Feb 9, 2023

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

@f41gh7 f41gh7 added the enhancement New feature or request label Feb 9, 2023
@machinedrummer
Copy link
Author

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.

@f41gh7
Copy link
Contributor

f41gh7 commented Feb 9, 2023

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/

@valyala valyala added help wanted Extra attention is needed vmagent windows labels Feb 9, 2023
@valyala
Copy link
Collaborator

valyala commented Feb 9, 2023

@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.

@machinedrummer
Copy link
Author

machinedrummer commented Feb 9, 2023

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

@Munsio
Copy link

Munsio commented Sep 6, 2023

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.

zekker6 added a commit that referenced this issue Oct 5, 2023
Use service configuration example from #3781 (comment)

Signed-off-by: Zakhar Bessarab <z.bessarab@victoriametrics.com>
hagen1778 pushed a commit that referenced this issue Oct 5, 2023
Use service configuration example from #3781 (comment)

Signed-off-by: Zakhar Bessarab <z.bessarab@victoriametrics.com>
hagen1778 pushed a commit that referenced this issue Oct 5, 2023
Use service configuration example from #3781 (comment)

Signed-off-by: Zakhar Bessarab <z.bessarab@victoriametrics.com>

(cherry picked from commit cc7d5b7)
Signed-off-by: hagen1778 <roman@victoriametrics.com>
valyala added a commit that referenced this issue Oct 15, 2023
…ue, which describes how to run VictoriaMetrics as Windows service

This is a follow-up for cc7d5b7

The original issue #3781 contains
up-to-date information on how to run VictoriaMetrics components as Windows service,
plus it may contain additional information about this case such as #3781 (comment) ,
so it is better to refer this issue from the docs.
valyala added a commit that referenced this issue Oct 16, 2023
…ue, which describes how to run VictoriaMetrics as Windows service

This is a follow-up for cc7d5b7

The original issue #3781 contains
up-to-date information on how to run VictoriaMetrics components as Windows service,
plus it may contain additional information about this case such as #3781 (comment) ,
so it is better to refer this issue from the docs.
AndrewChubatiuk pushed a commit to AndrewChubatiuk/VictoriaMetrics that referenced this issue Nov 15, 2023
…ue, which describes how to run VictoriaMetrics as Windows service

This is a follow-up for cc7d5b7

The original issue VictoriaMetrics#3781 contains
up-to-date information on how to run VictoriaMetrics components as Windows service,
plus it may contain additional information about this case such as VictoriaMetrics#3781 (comment) ,
so it is better to refer this issue from the docs.
@lapo-luchini
Copy link
Contributor

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?

@Munsio
Copy link

Munsio commented Jan 8, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed vmagent windows
Projects
None yet
Development

No branches or pull requests

5 participants