2
# Init script for logstash-forwarder
4
# Generated by pleaserun.
5
# Implemented based on LSB Core 3.1:
6
# * Sections: 20.2, 20.3
9
# Provides: logstash-forwarder
4
10
# Required-Start: $remote_fs $syslog
5
11
# Required-Stop: $remote_fs $syslog
6
12
# Default-Start: 2 3 4 5
7
13
# Default-Stop: 0 1 6
8
# Short-Description: Example initscript
9
# Description: This file should be used to construct scripts to be
10
# placed in /etc/init.d.
15
# Description: no description given
13
# Author: Jordan Sissel <jordan.sissel@dreamhost.com>
15
# PATH should only include /usr/* if it runs after the mountnfs.sh script
16
18
PATH=/sbin:/usr/sbin:/bin:/usr/bin
18
NAME=logstash-forwarder
19
DAEMON=/srv/logstash-forwarder/bin/logstash-forwarder
20
DAEMON_ARGS="-config /etc/logstash-forwarder -spool-size 100"
21
PIDFILE=/var/run/$NAME.pid
22
SCRIPTNAME=/etc/init.d/$NAME
23
LOGDIR=/var/log/logstash-forwarder
25
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
27
. /lib/lsb/init-functions
29
if [ ! -d ${LOGDIR} ]; then
32
COMMAND="cd /var/run; exec $DAEMON $DAEMON_ARGS >> ${LOGDIR}/logstash-forwarder.log 2>&1"
35
# Skip if it's already running
36
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec /bin/sh --test > /dev/null || return 1
39
# Actually start it now.
40
start-stop-daemon --start --quiet --make-pidfile --background \
41
--pidfile $PIDFILE --exec /bin/sh -- -c "$COMMAND" || return 2
46
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE
48
[ "$RETVAL" = 2 ] && return 2
49
start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
50
[ "$?" = 2 ] && return 2
21
name=logstash-forwarder
22
program=/srv/logstash-forwarder/bin/logstash-forwarder
23
pidfile="/var/run/$name.pid"
25
[ -r /etc/default/$name ] && . /etc/default/$name
26
[ -r /etc/sysconfig/$name ] && . /etc/sysconfig/$name
30
logger -t "/etc/init.d/logstash-forwarder" "$@"
40
# Ensure the log directory is setup correctly.
41
[ ! -d "/var/log/logstash-forwarder/" ] && mkdir "/var/log/logstash-forwarder/"
42
chown "$user":"$group" "/var/log/logstash-forwarder/"
43
chmod 755 "/var/log/logstash-forwarder/"
46
# Setup any environmental stuff beforehand
51
chroot --userspec "$user":"$group" "$chroot" sh -c "
54
exec \"$program\" $args
55
" >> /var/log/logstash-forwarder/logstash-forwarder.stdout 2>> /var/log/logstash-forwarder/logstash-forwarder.stderr &
57
# Generate the pidfile from here. If we instead made the forked process
58
# generate it there will be a race condition between the pidfile writing
59
# and a process possibly asking for status.
67
# Try a few times to kill TERM the program
70
trace "Killing $name (pid $pid) with SIGTERM"
72
# Wait for it to exit.
73
for i in 1 2 3 4 5 ; do
74
trace "Waiting $name (pid $pid) to die..."
79
emit "$name stop failed; still running."
87
if [ -f "$pidfile" ] ; then
89
if ps -p $pid > /dev/null 2> /dev/null ; then
90
# process by this pid is running.
91
# It may not be our pid, but that's what you get with just pidfiles.
92
# TODO(sissel): Check if this process seems to be the same as the one we
93
# expect. It'd be nice to use flock here, but flock uses fork, not exec,
94
# so it makes it quite awkward to use in this case.
97
return 2 # program is dead but pid file exists
100
return 3 # program is not running
107
status && kill -KILL $(cat "$pidfile")
113
force-start|start|stop|force-stop|restart)
114
trace "Attempting '$1' on logstash-forwarder"
57
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
60
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
61
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
65
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
68
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
69
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
73
status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
76
log_daemon_msg "Restarting $DESC" "$NAME"
83
1) log_end_msg 1 ;; # Old process is still running
84
*) log_end_msg 1 ;; # Failed to start
126
if [ $code -eq 0 ]; then
127
emit "$name is already running"
135
force-stop) force_stop ;;
139
if [ $code -eq 0 ] ; then
140
emit "$name is running"
142
emit "$name is not running"
94
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
151
echo "Usage: $SCRIPTNAME {start|force-start|stop|force-start|force-stop|status|restart}" >&2