Skip to content

Instantly share code, notes, and snippets.

@ibuys
Last active August 29, 2015 14:26
Show Gist options
  • Save ibuys/1e39d945de245a4591df to your computer and use it in GitHub Desktop.
Save ibuys/1e39d945de245a4591df to your computer and use it in GitHub Desktop.
#! /bin/sh
### BEGIN INIT INFO
# Provides: graylog-collector
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: graylog-collector init script
# Description: graylog-collector init script
### END INIT INFO
## Source function library.
. /etc/init.d/functions
NAME="graylog-collector"
GRAYLOG_COLLECTOR_HOME=/opt/graylog/collector
GRAYLOG_COLLECTOR_CONFIG=$GRAYLOG_COLLECTOR_HOME/config/collector.conf
GRAYLOG_COLLECTOR=$GRAYLOG_COLLECTOR_HOME/bin/graylog-collector
GRAYLOG_COLLECTOR_OUT="/var/log/graylog-collector.log"
PID_FILE="$GRAYLOG_COLLECTOR_HOME/RUNNING_PID"
LOCK_FILE="/var/lock/subsys/${NAME}"
RUN_AS_USER=root
if [ ! -r "$GRAYLOG_COLLECTOR" ]; then
echo "Cannot find $GRAYLOG_COLLECTOR"
echo "${GRAYLOG_COLLECTOR} is absent or does not have read permission"
exit 1
fi
touch "$GRAYLOG_COLLECTOR_OUT"
chown $RUN_AS_USER "$GRAYLOG_COLLECTOR_OUT"
start() {
echo "Starting $NAME: "
$GRAYLOG_COLLECTOR run -f $GRAYLOG_COLLECTOR_CONFIG >> $GRAYLOG_COLLECTOR_OUT 2>&1 &
RETVAL=$?
sleep 5
GRAYPID=`ps -eaf | grep graylog-collector.jar | grep -v grep | awk '{ print $2 }'`
echo $GRAYPID > $PID_FILE
[ $RETVAL -eq 0 ] && touch $LOCK_FILE
return $RETVAL
}
stop() {
echo "Stopping $NAME: "
killproc -p ${PID_FILE} -d 5
RETVAL=$?
[ $RETVAL -eq 0 ] && rm -f $LOCK_FILE
return $RETVAL
}
restart() {
stop
sleep 3
start
}
dump() {
echo "Dumping $NAME: "
PID=`cat $PID_FILE`
kill -3 $PID
RETVAL=$?
[ $RETVAL -eq 0 ] && success $"Dumped $NAME." || failure $"Failed to dump $NAME."
return $RETVAL
}
rh_status() {
status -p ${PID_FILE} ${NAME}
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
start
;;
stop)
rh_status_q || exit 0
stop
;;
restart)
restart
;;
status)
rh_status
;;
dump)
rh_status_q || exit 0
dump
;;
condrestart|try-restart)
rh_status_q || exit 0
restart
;;
*)
echo "Usage: $0 {start|stop|status|restart|condrestart|try-restart|dump}"
exit 1
esac
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment