Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Minimal init scripts for logstash-forwarder on RedHat and Debian.
#! /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
# Short-Description: Start daemon at boot time
# Description: Enable service provided by daemon.
### END INIT INFO
. /lib/lsb/init-functions
NAME="logstash-forwarder"
CONF_DIR="/etc/logstash-forwarder/conf.d"
LOGSTASH_FORWARDER_OPTIONS="-config ${CONF_DIR} -log-to-syslog=true"
# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
LOGSTASH_FORWARDER_BIN="/usr/local/bin/logstash-forwarder"
PID_FILE="/var/run/$NAME.pid"
CWD=`pwd`
USER='logstash'
start () {
log_daemon_msg "Starting $NAME"
if start-stop-daemon --start --chuid $USER --chdir /tmp --quiet --oknodo --pidfile "$PID_FILE" -b -m -N 19 --exec $LOGSTASH_FORWARDER_BIN -- $LOGSTASH_FORWARDER_OPTIONS; then
log_end_msg 0
else
log_end_msg 1
fi
}
stop () {
start-stop-daemon --stop --quiet --oknodo --pidfile "$PID_FILE"
}
status () {
status_of_proc -p $PID_FILE "" "$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
#! /bin/sh
#
# logstash-forwarder Start/Stop logstash-forwarder
#
# chkconfig: 345 99 99
# description: logstash-forwarder
# processname: logstash-forwarder
USER='logstash'
CONF_DIR='/etc/logstash-forwarder/conf.d'
EXE='/usr/local/bin/logstash-forwarder'
OPTIONS="-config ${CONF_DIR}"
COMMAND_LINE="${EXE} ${OPTIONS}"
running () {
ps -eo user,command | grep -q "^${USER} *${COMMAND_LINE}"
return $?
}
start () {
if running; then
echo 'Already running.'
return 0
fi
(cd /tmp && su $USER -c "nohup ${COMMAND_LINE} >/dev/null 2>&1 &")
return $?
}
stop () {
pkill -f "${COMMAND_LINE}"
return $?
}
RETVAL=1
case $1 in
start)
start && RETVAL=0
;;
stop)
stop && RETVAL=0
;;
reload)
stop
start
;;
restart)
stop
start
;;
status)
if running; then
echo 'Running.'
RETVAL=0
else
echo 'Stopped.'
RETVAL=1
fi
;;
*)
echo "Usage: $0 {start|stop|restart|reload|status}"
esac
exit $RETVAL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment