Skip to content

Instantly share code, notes, and snippets.

@lmorfitt
Created September 6, 2013 04:24
Show Gist options
  • Save lmorfitt/6459539 to your computer and use it in GitHub Desktop.
Save lmorfitt/6459539 to your computer and use it in GitHub Desktop.
Red Hat 6 lumberjack init script
#!/bin/sh
#
# /etc/init.d/lumberjack
#
# Starts and stops Lumberjack as a "daemon".
#
# chkconfig: 2345 30 70
# description: Starts and stops Lumberjack as a daemon.
# The name of this service
NAME=lumberjack
### Start Configuration Options ###
# The JSON config to use
LJ_CONFIG=/etc/lumberjack.conf
# The Lumberjack binary wrapper
LJ_BIN=`which lumberjack`
# Any Lumberjack options
LJ_OPTS="-spool-size 1000"
# The log file for local info
LJ_LOG=/var/log/lumberjack/lumberjack
# The PID file
PID_FILE=/var/run/lumberjack
# The command to daemonize
DAEMON="nohup ${LJ_BIN} -config ${LJ_CONFIG} ${LJ_OPTS} >>${LJ_LOG} 2>&1 &"
### End Configuration Options ###
. /etc/init.d/functions
check_prereqs() {
if [ -z ${LJ_BIN} ]; then
echo "ERROR: Unable to locate Lumberjack binary, make sure it's installed."
exit 1
elif [ ! -f ${LJ_CONFIG} ]; then
echo "ERROR: LJ_CONFIG (${LJ_CONFIG}) doesn't exist."
exit 1
elif [ ! -d `dirname ${LJ_LOG}` ]; then
echo "ERROR: LJ_LOG parent directory (`dirname ${LJ_LOG}`) doesn't exist."
exit 1
fi
}
start() {
check_prereqs
echo -n $"Starting $NAME: "
daemon --check $NAME --pidfile $PID_FILE $DAEMON
RETVAL=$?
if [ $RETVAL -ne 0 ]; then
echo_failure
echo
else
PID=$(pgrep $NAME)
echo -n $PID > $PID_FILE
echo_success
echo
fi
return $RETVAL
}
stop () {
echo -n $"Stopping $NAME: "
killproc -p $PID_FILE $NAME
RETVAL=$?
echo
return $RETVAL
}
restart () {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status -p $PID_FILE $NAME
;;
restart)
restart
;;
*)
echo "Usage: $0 {start|stop|status}"
exit 2
;;
esac
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment