Skip to content

Instantly share code, notes, and snippets.

@jose-d
Forked from piavlo/adduser
Last active January 9, 2017 17:38
Show Gist options
  • Save jose-d/74aa5c8d9a374f9be1b985a7c49da172 to your computer and use it in GitHub Desktop.
Save jose-d/74aa5c8d9a374f9be1b985a7c49da172 to your computer and use it in GitHub Desktop.
logstash init script for centos 5/6 requires daemonize binary and unpacked monolitic jar under /opt/logstash
#!/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
DESC="Logstash Daemon"
LOGSTASH_USER=logstash
DAEMON=/usr/bin/java
CONFIG_DIR="/etc/logstash"
CONFIGFILE="${CONFIG_DIR}/*.conf"
LOGDIR="/var/log/logstash"
PATTERNSPATH="/etc/logstash/patterns"
SCRIPTNAME=/etc/init.d/logstash
PIDFILE="/var/run/logstash.pid"
LOCKFILE="/var/lock/subsys/logstash"
WORKDIR=/opt/logstash
FILTER_WORKERS=1
EVENT_TIMEOUT=60
SHUTDOWN_TIMEOUT=5
[ -e /etc/sysconfig/logstash ] && . /etc/sysconfig/logstash
LOGSTASH_OPTS="--config ${CONFIGFILE} --grok-patterns-path ${PATTERNSPATH} --log ${LOGDIR}/agent.log --filterworkers ${FILTER_WORKERS} --watchdog-timeout ${EVENT_TIMEOUT}"
CMD="${DAEMON} ${JVM_OPTS} -cp /opt/logstash logstash.runner agent ${LOGSTASH_OPTS}"
. /lib/lsb/init-functions
start() {
daemonize -c $WORKDIR -u $LOGSTASH_USER -p $PIDFILE -l $LOCKFILE -o $LOGDIR/stdout -e $LOGDIR/stderr $CMD
if [ $? -eq 0 ]; then
log_success_msg "Starting $DESC:"
else
log_failure_msg "Starting $DESC:"
fi
}
stop(){
[ -e "$PIDFILE" ] && [ ! -z "$(cat $PIDFILE)" ] && test -d "/proc/$(cat $PIDFILE)" && kill -SIGINT $(cat $PIDFILE)
flock --exclusive --timeout $SHUTDOWN_TIMEOUT $LOCKFILE --command "echo -n"
if [ $? -eq 0 ]; then
log_success_msg "Stopping $DESC:"
else
log_failure_msg "Stopping $DESC:"
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 0.2
start
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart}" >&2
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment