Skip to content

Instantly share code, notes, and snippets.

@polansky
Forked from lmorfitt/gist:6459539
Last active December 27, 2015 09:59
Show Gist options
  • Save polansky/7307828 to your computer and use it in GitHub Desktop.
Save polansky/7307828 to your computer and use it in GitHub Desktop.
This is an update to an existing gist to add functionality to start the daemon in the lumberjack install dir. This is so that the ".lumberjack" file (which is created to track the position lumberjack is in the file) is not created at /.
#!/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`
# The Lumberjack runnning directory
LJ_RUNDIR="$(dirname ${LJ_BIN})/.."
# 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
elif [ ! -d ${LJ_RUNDIR} ]; then
echo "ERROR: LJ_RUNDIR (${LJ_RUNDIR}) doesn't exist."
exit 1
fi
}
start() {
check_prereqs
echo -n $"Starting $NAME: "
cd $LJ_RUNDIR && 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