logstash icon indicating copy to clipboard operation
logstash copied to clipboard

Logstash systemd unit doesn't create pidfiles. Ignores /etc/default/logstash:LS_PIDFILE

Open roaksoax opened this issue 3 years ago • 4 comments

When using logstash from deb/rpms or the elastic archive, Logstash systemd unit doesn't create pidfiles, hence, completely ignoring what's set it /etc/default.

Version: 7.9 Operating System: Centos 7 / Ubuntu 18.04 Steps to reproduce:

  1. Install Logstash from archives or deb/rpms
  2. Start logstash, make sure it is running (sudo service logstash start)
  3. Pidfile doesn't exist in /var/run/

Service is running:

[root@centos-logstash-0 /]# sudo service logstash status
Redirecting to /bin/systemctl status logstash.service
● logstash.service - logstash
   Loaded: loaded (/etc/systemd/system/logstash.service; disabled; vendor preset: disabled)
   Active: active (running) since Thu 2020-10-22 16:11:19 UTC; 1 weeks 5 days ago
 Main PID: 862 (java)
   CGroup: /system.slice/logstash.service
           └─862 /bin/java -Xms1g -Xmx1g -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -Djava.awt.headless=true -Dfile...

/etc/default/logstash:

[root@centos-logstash-0 /]# cat /etc/default/logstash 
LS_HOME="/usr/share/logstash"
LS_SETTINGS_DIR="/etc/logstash"
LS_PIDFILE="/var/run/logstash.pid"
LS_USER="logstash"
LS_GROUP="logstash"
LS_GC_LOG_FILE="/var/log/logstash/gc.log"
LS_OPEN_FILES="16384"
LS_NICE="19"
SERVICE_NAME="logstash"
SERVICE_DESCRIPTION="logstash"

/var/run, no pidfile

[root@centos-logstash-0 /]# ls -l /var/run/
total 20
drwxr-xr-x  2 root root   40 Oct 22 15:03 console
-rw-r--r--  1 root root    3 Oct 22 15:03 crond.pid
----------  1 root root    0 Oct 22 15:03 cron.reboot
drwx------  2 root root   40 Oct 22 15:03 cryptsetup
drwxr-xr-x  2 root root   60 Oct 22 15:03 dbus
-rw-r--r--  1 root root    4 Oct 22 15:03 dhclient-eth0.pid
drwxr-xr-x  2 root root   40 Oct 22 15:03 faillock
drwxr-xr-x  4 root root   80 Oct 22 15:03 lock
drwxr-xr-x  3 root root   60 Oct 22 15:03 log
drwxr-xr-x  2 root root   40 Oct 22 15:03 mount
drwxrwxr-x  2 root root   40 Oct 22 15:03 netreport
drwxr-xr-x  2 root root   40 Oct 22 15:03 sepermit
drwxr-xr-x  2 root root   40 Oct 22 15:03 setrans
-rw-r--r--  1 root root    4 Oct 22 15:06 sshd.pid
drwx--x--x  3 root root   60 Oct 22 15:06 sudo
-rw-------  1 root root    3 Oct 22 15:03 syslogd.pid
drwxr-xr-x 16 root root  440 Oct 22 16:01 systemd
drwxr-xr-x  3 root root   60 Nov  4 15:37 user
-rw-rw-r--  1 root utmp 1536 Nov  4 15:37 utmp

Service unit

[root@centos-logstash-0 system]# cat logstash.service 
[Unit]
Description=logstash

[Service]
Type=simple
User=logstash
Group=logstash
# Load env vars from /etc/default/ and /etc/sysconfig/ if they exist.
# Prefixing the path with '-' makes it try to load, but if the file doesn't
# exist, it continues onward.
EnvironmentFile=-/etc/default/logstash
EnvironmentFile=-/etc/sysconfig/logstash
ExecStart=/usr/share/logstash/bin/logstash "--path.settings" "/etc/logstash"
Restart=always
WorkingDirectory=/
Nice=19
LimitNOFILE=16384

# When stopping, how long to wait before giving up and sending SIGKILL?
# Keep in mind that SIGKILL on a process can cause data loss.
TimeoutStopSec=infinity

[Install]
WantedBy=multi-user.target

roaksoax avatar Nov 04 '20 15:11 roaksoax

+1

hariyerramsetty avatar Jan 08 '21 23:01 hariyerramsetty

+1

michallukas avatar Sep 09 '22 19:09 michallukas

:+1:

this issue has been open for almost 3 years and looks like there's zero movement on it :/

teemall avatar Sep 25 '23 18:09 teemall

Logstash doesn't use or support pidfiles. It's a simple type. Doesn't need it. The pid at start is the pid at end. Systemd has no problem tracking this.

Pidfile is only useful in this case for sysvinit. If you have a service script, you need something to track state with and that is a pidfile. You create a subshell, echo the PID into the pidfile, then exec logstash. Next time you run the script it can check the pidfile to see if logstash is alive or not. Prevent starting a new one if the pid in the pidfile is alive, tell you status, and not try to stop a pid which isn't alive.

Matthew-Jenkins avatar Oct 20 '23 13:10 Matthew-Jenkins