Skip to content

Instantly share code, notes, and snippets.

@eduardodeoh
Created October 26, 2012 17:56
Show Gist options
  • Save eduardodeoh/3960290 to your computer and use it in GitHub Desktop.
Save eduardodeoh/3960290 to your computer and use it in GitHub Desktop.
Statsd Init Script
#!/bin/bash
#
# /etc/rc.d/init.d/is24-statsd
#
# Starts the is24 statsd daemon
#
# chkconfig: 2345 20 80
# description: Frontend aggregatation of messages destined for graphite daemon
# processname: is24-statsd
### BEGIN INIT INFO
# Provides: is24-statsd
# Defalt-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: Frontend aggregatation of messages destined for graphite daemon
### END INIT INFO
# Source function library.
. /etc/rc.d/init.d/functions
NAME=statsd
INSTALL_DIR=/opt/$NAME
NODE_DIR=/opt/node
NODE_EXE=$NODE_DIR/bin/node
STATSJS=stats.js
CONFIGJS=config.js
[ -x $NODE_EXE ] || exit 0
[ -f $INSTALL_DIR/$STATSJS ] || exit 0
RETVAL=0
#
# See how we were called.
#
start() {
# Check if it is already running
if [ ! -f /var/lock/subsys/$NAME ]; then
echo -n $"Starting $NAME daemon: "
# daemon
sudo -u statsd -- $NODE_EXE $INSTALL_DIR/$STATSJS $INSTALL_DIR/$CONFIGJS >/dev/null 2>&1 </dev/null &
#$NODE_EXE $INSTALL_DIR/$STATSJS $INSTALL_DIR/$CONFIGJS >/dev/null 2>&1 </dev/null &
RETVAL=$?
if [ $RETVAL -eq 0 ]; then
touch /var/lock/subsys/$NAME
echo_success
else
echo_failure
fi
echo
fi
return $RETVAL
}
stop() {
echo -n $"Stopping $NAME daemon: "
#pid=$(ps aux | grep stats.js | grep node | awk '{print $2}')
pid=`ps aux | grep $STATSJS | grep $CONFIGJS | awk '{print $2}'`
kill $pid
RETVAL=$?
if [ $RETVAL -eq 0 ]; then
rm -f /var/lock/subsys/$NAME
echo_success
else
echo_failure
fi
echo
return $RETVAL
}
restart() {
stop
start
}
reload() {
trap "" SIGHUP
killall -HUP stats.js
}
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
restart
;;
condrestart)
if [ -f /var/lock/subsys/$NAME ]; then
restart
fi
;;
status)
if [ -f /var/lock/subsys/$NAME ]; then
echo "$NAME is running"
exit 0
else
echo "$NAME is stopped"
exit 3
fi
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|reload}"
exit 1
esac
exit $RETVAL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment