# Logstash init process in Debian Jessie

**URL:** <https://discuss.elastic.co/t/logstash-init-process-in-debian-jessie/33673>\
**Category:** Logstash\
**Created:** [November 3, 2015, 9:03pm UTC](https://discuss.elastic.co/t/logstash-init-process-in-debian-jessie/33673 "2015-11-03T21:03:51Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Don\_Pich](https://avatars.discourse-cdn.com/v4/letter/d/b487fb/32.png) [@Don\_Pich](https://discuss.elastic.co/u/Don_Pich)\
**Post date:** [November 3, 2015, 9:03pm UTC](https://discuss.elastic.co/t/logstash-init-process-in-debian-jessie/33673/1 "2015-11-03T21:03:51Z")

</div>

for the life of me, I cannot understand why this isn't working.

If I start the logstash daemon manually with this one liner built off of the init, it works fine.

```
/opt/logstash/bin/logstash agent -f /etc/logstash/conf.d -l /var/log/logstash/logstash.log -v

```

What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![Don\_Pich](https://avatars.discourse-cdn.com/v4/letter/d/b487fb/32.png) [@Don\_Pich](https://discuss.elastic.co/u/Don_Pich)\
**Post date:** [November 3, 2015, 9:04pm UTC](https://discuss.elastic.co/t/logstash-init-process-in-debian-jessie/33673/2 "2015-11-03T21:04:07Z")

</div>

```
However, the init will not work at all.

#!/bin/bash
#
# /etc/init.d/logstash -- startup script for LogStash.
#
### BEGIN INIT INFO
# Provides: logstash
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Starts logstash
# Description: Starts logstash using start-stop-daemon
### END INIT INFO

set -e

NAME=logstash
DESC="Logstash Daemon"
DEFAULT=/etc/default/$NAME

if [`id -u` -ne 0]; then
   echo "You need root privileges to run this script"
   exit 1
fi

. /lib/lsb/init-functions

if [-r /etc/default/rcS]; then
   . /etc/default/rcS
fi

# The following variables can be overwritten in $DEFAULT
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/opt/logstash/bin

# See contents of file named in $DEFAULT for comments
LS_USER=logstash
LS_GROUP=logstash
LS_HOME=/var/lib/logstash
LS_HEAP_SIZE="2g"
LS_JAVA_OPTS="-Djava.io.tmpdir=${LS_HOME}"
LS_LOG_FILE=/var/log/logstash/$NAME.log
LS_CONF_DIR=/etc/logstash/conf.d
LS_OPEN_FILES=65535
LS_NICE=19
LS_OPTS="-v"
LS_PIDFILE=/var/run/$NAME.pid

# End of variables that can be overwritten in $DEFAULT

# overwrite settings from default file
if [-f "$DEFAULT"]; then
   . "$DEFAULT"
fi

# Define other required variables
PID_FILE=${LS_PIDFILE}
DAEMON=/opt/logstash/bin/logstash
DAEMON_OPTS="agent -f ${LS_CONF_DIR} -l ${LS_LOG_FILE} ${LS_OPTS}"

# Check DAEMON exists
if ! test -e $DAEMON; then
   log_failure_msg "Script $DAEMON doesn't exist"
   exit 1
fi

case "$1" in
   start)
      if [-z "$DAEMON"]; then
         log_failure_msg "no logstash script found - $DAEMON"
         exit 1
      fi

      # Check if a config file exists
      if [! "$(ls -A $LS_CONF_DIR/*.conf 2> /dev/null)"]; then
         log_failure_msg "There aren't any configuration files in $LS_CONF_DIR"
         exit 1
      fi

      log_daemon_msg "Starting $DESC"

      # Parse the actual JAVACMD from the process' environment, we don't care about errors.
      JAVA=$(cat /proc/$(cat "${PID_FILE}" 2>/dev/null)/environ 2>/dev/null | grep -z ^JAVACMD= | cut -d= -f2)
      if start-stop-daemon --test --start --pidfile "$PID_FILE" --user "$LS_USER" --exec "$JAVA" >/dev/null; then
         # Prepare environment
         HOME="${HOME:-$LS_HOME}"
         JAVA_OPTS="${LS_JAVA_OPTS}"
         ulimit -n ${LS_OPEN_FILES}
	 cd "${LS_HOME}"
         export PATH HOME JAVACMD JAVA_OPTS LS_HEAP_SIZE LS_JAVA_OPTS LS_USE_GC_LOGGING

         # Start Daemon
         start-stop-daemon --start -b --user "$LS_USER" -c "$LS_USER":"$LS_GROUP" -d "$LS_HOME" --nicelevel "$LS_NICE" --pidfile "$PID_FILE" --make-pidfile --exec $DAEMON -- $DAEMON_OPTS

         sleep 1

         # Parse the actual JAVACMD from the process' environment, we don't care about errors.
         JAVA=$(cat /proc/$(cat "${PID_FILE}" 2>/dev/null)/environ 2>/dev/null | grep -z ^JAVACMD= | cut -d= -f2)
         if start-stop-daemon --test --start --pidfile "$PID_FILE" --user "$LS_USER" --exec "$JAVA" >/dev/null; then

            if [-f "$PID_FILE"]; then
               rm -f "$PID_FILE"
            fi

            log_end_msg 1
         else
            log_end_msg 0
         fi
      else
         log_progress_msg "(already running)"
         log_end_msg 0
      fi
   ;;
   stop)
      log_daemon_msg "Stopping $DESC"

      set +e

      if [-f "$PID_FILE"]; then
         start-stop-daemon --stop --pidfile "$PID_FILE" --user "$LS_USER" --retry=TERM/20/KILL/5 >/dev/null

         if [$? -eq 1]; then
            log_progress_msg "$DESC is not running but pid file exists, cleaning up"
         elif [$? -eq 3]; then
            PID="`cat $PID_FILE`"
            log_failure_msg "Failed to stop $DESC (pid $PID)"
            exit 1
         fi
```

---

<div class="post-metadata">

**Author:** ![Don\_Pich](https://avatars.discourse-cdn.com/v4/letter/d/b487fb/32.png) [@Don\_Pich](https://discuss.elastic.co/u/Don_Pich)\
**Post date:** [November 3, 2015, 9:04pm UTC](https://discuss.elastic.co/t/logstash-init-process-in-debian-jessie/33673/3 "2015-11-03T21:04:17Z")

</div>

```
         rm -f "$PID_FILE"
      else
         log_progress_msg "(not running)"
      fi

      log_end_msg 0
      set -e
   ;;
   status)
      set +e

      # Parse the actual JAVACMD from the process' environment, we don't care about errors.
      JAVA=$(cat /proc/$(cat "${PID_FILE}" 2>/dev/null)/environ 2>/dev/null | grep -z ^JAVACMD= | cut -d= -f2)
      start-stop-daemon --test --start --pidfile "$PID_FILE" --user "$LS_USER" --exec "$JAVA" >/dev/null 2>&1

      if ["$?" = "0"]; then
         if [-f "$PID_FILE"]; then
            log_success_msg "$DESC is not running, but pid file exists."
            exit 1
         else
            log_success_msg "$DESC is not running."
            exit 3
         fi
      else
         log_success_msg "$DESC is running with pid `cat $PID_FILE`"
      fi

      set -e
   ;;
   restart|force-reload)
      if [-f "$PID_FILE"]; then
         $0 stop
         sleep 1
      fi

      $0 start
   ;;
   *)
      log_success_msg "Usage: $0 {start|stop|restart|force-reload|status}"
      exit 1
   ;;
esac

exit 0
```

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [November 3, 2015, 9:07pm UTC](https://discuss.elastic.co/t/logstash-init-process-in-debian-jessie/33673/4 "2015-11-03T21:07:42Z")

</div>

How did you install LS, from package or repo?

---

<div class="post-metadata">

**Author:** ![Don\_Pich](https://avatars.discourse-cdn.com/v4/letter/d/b487fb/32.png) [@Don\_Pich](https://discuss.elastic.co/u/Don_Pich)\
**Post date:** [November 3, 2015, 9:40pm UTC](https://discuss.elastic.co/t/logstash-init-process-in-debian-jessie/33673/5 "2015-11-03T21:40:10Z")

</div>

I downloaded the 1.5.5 tar file and extracted it in /opt/elasticsearch. I  
have multiple config files in /etc/logstash/conf.d

_Don Pich | Jedi Master (aka System Administrator 2) | O: 701-952-5925_

3320 Westrac Drive South, Suite A \* Fargo, ND 58103

Facebook [http://www.facebook.com/RealTruck](http://www.facebook.com/RealTruck) | Youtube  
[http://www.youtube.com/realtruckcom](http://www.youtube.com/realtruckcom)| Twitter  
[http://twitter.com/realtruck](http://twitter.com/realtruck) | Google+ [https://google.com/+Realtruck](https://google.com/+Realtruck) |  
Instagram [http://instagram.com/realtruckcom](http://instagram.com/realtruckcom) | Linkedin  
[http://www.linkedin.com/company/realtruck](http://www.linkedin.com/company/realtruck) | Our Guiding Principles  
[http://www.realtruck.com/our-guiding-principles/](http://www.realtruck.com/our-guiding-principles/)  
“If it goes on a truck we got it, if it’s fun we do it” – [RealTruck.com](http://RealTruck.com)  
[http://realtruck.com/](http://realtruck.com/)

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [November 3, 2015, 9:41pm UTC](https://discuss.elastic.co/t/logstash-init-process-in-debian-jessie/33673/6 "2015-11-03T21:41:23Z")

</div>

Why not use the packaged version that provides an init script?

---

<div class="post-metadata">

**Author:** ![Don\_Pich](https://avatars.discourse-cdn.com/v4/letter/d/b487fb/32.png) [@Don\_Pich](https://discuss.elastic.co/u/Don_Pich)\
**Post date:** [November 5, 2015, 7:06pm UTC](https://discuss.elastic.co/t/logstash-init-process-in-debian-jessie/33673/7 "2015-11-05T19:06:06Z")

</div>

I probably should be and most times I do. But I have reasons to run the package.

I fixed this with use of another init script:

```
#! /bin/sh

### BEGIN INIT INFO
# Provides: logstash
# Required-Start: $network $remote_fs $named $elasticsearch
# Required-Stop: $network $remote_fs $named $elasticsearch
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start logstash at boot time
# Description: Enable service provided by daemon.
### END INIT INFO

. /lib/lsb/init-functions

name="logstash"
logstash_bin="/opt/logstash/bin/logstash"
logstash_conf="/etc/logstash/conf.d"
logstash_log="/var/log/logstash.log"
pid_file="/var/run/logstash.pid"
logstash_opts="-f ${logstash_conf} -l ${logstash_log}"

start () {
        log_daemon_msg "Starting $name" "$name"
        if start-stop-daemon --quiet --oknodo --pidfile "$pid_file" -b -m --exec $logstash_bin --start -- $logstash_opts; then
                log_end_msg 0
        else
                log_end_msg 1
        fi
}

stop () {
        log_daemon_msg "Stopping $name" "$name"
        start-stop-daemon --stop --quiet --oknodo --pidfile "$pid_file"
}

status () {
        status_of_proc -p $pid_file $logstash_bin "$name"
}

case $1 in
        start)
                if status; then exit 0; fi
                start
                ;;
        stop)
                stop
                ;;
        reload)
                stop
                start
                ;;
        restart)
                stop
                start
                ;;
        status)
                status && exit 0 || exit $?
                ;;
        *)
                echo "Usage: $0 {start|stop|restart|reload|status}"
                exit 1
                ;;
esac
exit 0
```

---

<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:** [July 6, 2017, 5:23am UTC](https://discuss.elastic.co/t/logstash-init-process-in-debian-jessie/33673/8 "2017-07-06T05:23:46Z")

</div>


