logstash-forwarder.lsb.init 2.07 KB
Newer Older
Jørn Åne de Jong's avatar
Jørn Åne de Jong committed
1 2 3 4 5 6 7
#! /bin/sh
### BEGIN INIT INFO
# Provides:          logstash-forwarder
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
8 9
# Short-Description: UNINETT LAaaS Log Shipper LSB
# Description:       Ship logfiles to the UNINETT LAaaS service
Jørn Åne de Jong's avatar
Jørn Åne de Jong committed
10 11 12
### END INIT INFO

# Author: Jordan Sissel <jordan.sissel@dreamhost.com>
13
# Author: Jørn Åne de Jong <jorn.dejong@uninett.no>
Jørn Åne de Jong's avatar
Jørn Åne de Jong committed
14 15 16 17 18

# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="log shipper"
NAME=logstash-forwarder
19
DAEMON=/usr/local/logstash-forwarder/bin/logstash-forwarder
Jørn Åne de Jong's avatar
Jørn Åne de Jong committed
20 21 22 23 24 25
DAEMON_ARGS="-config /etc/logstashforwarder/config.json -spool-size 100 -log-to-syslog"
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
LOGFILE=/var/log/$NAME.log

[ -r /etc/default/$NAME ] && . /etc/default/$NAME
26 27 28 29 30 31 32 33 34
if [[ -f /lib/lsb/init-functions ]]; then
  . /lib/lsb/init-functions
elif [[ -f /etc/init.d/functions ]]; then
  . /etc/init.d/functions
else
  echo "Linux LSB init function script or Redhat /etc/init.d/functions is required for this script."
  echo "See http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/iniscrptfunc.html"
  exit 1
fi
Jørn Åne de Jong's avatar
Jørn Åne de Jong committed
35 36 37 38 39 40 41 42 43

COMMAND="cd /var/run; exec $DAEMON $DAEMON_ARGS"

do_start() {
  if [ -z "$DAEMON" ]; then
    echo "not found - $DAEMON"
    exit 1
  fi

44
  if pidofproc -p "$PIDFILE" "$DAEMON" >/dev/null; then
Jørn Åne de Jong's avatar
Jørn Åne de Jong committed
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
    exit 0
  fi

  exec $DAEMON $DAEMON_ARGS >> $LOGFILE 2>&1 < /dev/null &
  RETVAL=$?
  local PID=$!
  usleep 500000
  echo $PID > $PIDFILE
}

do_stop()
{
    killproc -p $PIDFILE $DAEMON
    RETVAL=$?
    echo
    [ $RETVAL = 0 ] && rm -f ${PIDFILE}
}

case "$1" in
  start)
    echo "Starting $DESC" "$NAME"
    do_start
    ;;
  stop)
    echo "Stopping $DESC" "$NAME"
    do_stop
    ;;
  status)
    echo -n "Status of $DESC"
    status -p $PIDFILE
    exit $?
    ;;
  restart|force-reload)
    echo "Restarting $DESC" "$NAME"
    do_stop
    do_start
    ;;
  *)
    echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
    exit 3
    ;;
esac

: