Logstash pid file

Hi All,

i'm starting my logstash with command ./logstash -f logstash.conf & as a backend process.
i would like to generate a pid file in my logstash home directory.
How to achieve this.

For kibana i have used pid.file in kibana.yml file.

Let me know if anyone has any pointers on this.

Thanks
Shivaprasad

The recommended way to run Logstash in the background is to run it as a service managed by systemd or whatever your operating system uses.

Logstash doesn't support pid files.

okay..let me try the systemd or other service..but my requirement is all the files related to ELK setup should be under the folder /opt/ELK/..

When i install filebeat as service....the filebeat.yml came up under etc/filebeat...

Hence checking for the other options...or is it possible to setup logstash as service but all the files under my custom folder i.e. /opt/ELK/..

currently i have a custom script which im using :
echo $sDate 'Start of Logstash' >> $LOG_FILE
echo $sDate 'Kill of Logstash' >> $LOG_FILE
logstashpid=lsof -i:9600 | grep 'LISTEN' | awk '{print $2}'

if [ -z '$logstashpid' ]
then
echo $sDate '$logstashpid is empty' >> $LOG_FILE
else
echo $sDate '$logstashpid is NOT empty' >> $LOG_FILE
echo $sDate 'logstashpid :'$logstashpid >> $LOG_FILE
kill -9 $logstashpid
fi

cd /opt/ELK/logstash-6.4.0/bin
export JAVA_HOME=/opt/ELK/jdk
./logstash -f logstash.conf &

sleep 30

I was able to achieve my requirement with the use as systmectl. Below are the details.

under /etc/systemd/system i have created logstash.serivce with the below data :
[Unit]
Description=logstash

[Service]
ExecStart=/opt/ELK/logstash.sh

[Install]
WantedBy=multi-user.target

and my logstash.sh contains:
#!/bin/sh
dstamp=date '+%Y%m%d%H%M'
LOG_FILE=/opt/ELK/Logstash.log
sDate=date '+%Y-%m-%d %r'

echo $sDate '::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::' >> $LOG_FILE

echo $sDate 'Start of Logstash' >> $LOG_FILE

cd /opt/ELK/logstash-6.4.0/bin
export JAVA_HOME=/opt/ELK/jdk
./logstash -f logstash.conf

echo $sDate 'END of Logstash' >> $LOG_FILE
echo $sDate '::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::' >> $LOG_FILE

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.