# Logstash pid file

**URL:** <https://discuss.elastic.co/t/logstash-pid-file/152891>\
**Category:** Logstash\
**Created:** [October 17, 2018, 5:38pm UTC](https://discuss.elastic.co/t/logstash-pid-file/152891 "2018-10-17T17:38:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![shivaprasadrao.b](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@shivaprasadrao.b](https://discuss.elastic.co/u/shivaprasadrao.b)\
**Post date:** [October 17, 2018, 5:38pm UTC](https://discuss.elastic.co/t/logstash-pid-file/152891/1 "2018-10-17T17:38:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [October 17, 2018, 8:34pm UTC](https://discuss.elastic.co/t/logstash-pid-file/152891/2 "2018-10-17T20:34:33Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![shivaprasadrao.b](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@shivaprasadrao.b](https://discuss.elastic.co/u/shivaprasadrao.b)\
**Post date:** [October 17, 2018, 9:07pm UTC](https://discuss.elastic.co/t/logstash-pid-file/152891/3 "2018-10-17T21:07:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![shivaprasadrao.b](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@shivaprasadrao.b](https://discuss.elastic.co/u/shivaprasadrao.b)\
**Post date:** [October 18, 2018, 8:58pm UTC](https://discuss.elastic.co/t/logstash-pid-file/152891/4 "2018-10-18T20:58:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 15, 2018, 8:58pm UTC](https://discuss.elastic.co/t/logstash-pid-file/152891/5 "2018-11-15T20:58:53Z")

</div>

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