how to start logstash-forwarder as a service in Windows?

792 views Asked by At

i am at the moment using a vbs script to do this

This script works perfectly for some hours and stops for no reason. Can anyone point to me what is wrong with the script? How do i add logstash-forwarder to run as a service? I am having a hard time trying to figure out how to do this?

any help is appreciated.

Set WshShell = CreateObject("WScript.Shell")
cmds=WshShell.RUN("E:\logstash\logstash-forwarder.exe --config E:\logstash\conf.txt", 0, True)
Set WshShell = Nothing
2

There are 2 answers

1
leeman24 On

I just had to deal with this issue and was able to resolve. I basically used @VinothNair's instructions from his answer however it was missing "AppParameters" which contains the "-config logstash-forwarder.conf" argument which is required for this to work.

I created a script called createService.bat in C:\temp\logstash-forwarder. I also copied the nssm.exe file into the same directory. You can download nssm from https://nssm.cc/release/nssm-2.24.zip. Extract and copy nssm-2.24\win64\nssm.exe to the same directory.

@echo off
set BASE_DIR=C:\temp\logstash-forwarder
nssm install Logstash-Forwarder "%BASE_DIR%\logstash-forwarder.exe"
nssm set Logstash-Forwarder AppDirectory "%BASE_DIR%"
nssm set Logstash-Forwarder AppStopMethodSkip "6"
nssm set Logstash-Forwarder AppParameters "-config %BASE_DIR%\logstash-forwarder.conf"
1
VinothNair On

Try the below batch command. You don't need to install nssm. You just need the nssm exe on the current directory.

#install logstash-forwarder as service
c:\elk> nssm "install" "logstash-forwarder" "c:\elk\logstash-forwarder_windows_386.exe" 

c:\elk> nssm "set" "logstash-forwarder" "AppDirectory" "c:\logstash-forwarder" 

c:\elk> nssm "set" "logstash-forwarder" "AppStopMethodSkip" "6"