Skip to content

Instantly share code, notes, and snippets.

@dcrec1
Forked from erickr/statsd.init.sh
Last active December 17, 2015 04:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcrec1/5550283 to your computer and use it in GitHub Desktop.
Save dcrec1/5550283 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# StatsD
#
# chkconfig: 3 50 50
# description: StatsD init.d
. /lib/lsb/init-functions
prog=statsd
STATSDDIR=/var/local/apps/statsd
statsd=stats.js
LOG=/var/log/statsd.log
ERRLOG=/var/log/statsderr.log
CONFFILE=${STATSDDIR}/config.js
pidfile=/var/run/statsd.pid
lockfile=/var/lock/subsys/statsd
RETVAL=0
STOP_TIMEOUT=${STOP_TIMEOUT-10}
start() {
echo -n $"Starting $prog: "
cd ${STATSDDIR}
# See if it's already running. Look *only* at the pid file.
if [ -f ${pidfile} ]; then
log_failure_msg "PID file exists for statsd"
RETVAL=1
else
# Run as process
/usr/local/bin/node ${statsd} ${CONFFILE} >> ${LOG} 2>> ${ERRLOG} &
RETVAL=$?
# Store PID
echo $! > ${pidfile}
# Success
[ $RETVAL = 0 ] && log_success_msg "statsd started"
fi
echo
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc -p ${pidfile}
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f ${pidfile} && log_success_msg "statsd stopped"
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status -p ${pidfile} ${prog}
RETVAL=$?
;;
restart)
stop
start
;;
condrestart)
if [ -f ${pidfile} ] ; then
stop
start
fi
;;
*)
echo $"Usage: $prog {start|stop|restart|condrestart|status}"
exit 1
esac
exit $RETVAL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment