Skip to content

Instantly share code, notes, and snippets.

@erickr
Forked from lukemorton/README.markdown
Created October 30, 2011 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save erickr/1326359 to your computer and use it in GitHub Desktop.
Save erickr/1326359 to your computer and use it in GitHub Desktop.
Modified statsd.init.sh file to work on Debian
#!/bin/bash
#
# StatsD
#
# chkconfig: 3 50 50
# description: StatsD init.d
. /lib/lsb/init-functions
prog=statsd
STATSDDIR=/opt/statsd
statsd=stats.js
LOG=/var/log/statsd.log
ERRLOG=/var/log/statsderr.log
CONFFILE=${STATSDDIR}/conf.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
@cbliard
Copy link

cbliard commented Aug 23, 2012

I have adapted it to rely on LSB functions, use start-stop-daemon, and run as a specific user. But I lost the logs

Here is the version

start() {
        log_daemon_msg "Starting $prog"
        start-stop-daemon --start --oknodo --quiet --background --make-pidfile -p ${pidfile} -d ${STATSDDIR} --chuid ${user} --exec /usr/bin/node -- ${statsd} ${CONFFILE}
        log_end_msg $?
}

stop() {
        log_daemon_msg "Stopping $prog"
        start-stop-daemon --stop --oknodo --quiet -p ${pidfile} --exec /usr/bin/node --retry TERM/10/KILL/5
        log_end_msg $?
}

# See how we were called.
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  status)
        status_of_proc /usr/bin/node ${prog} -p ${pidfile}
        ;;
  restart)
        stop
        start
        ;;
  *)
        echo $"Usage: $prog {start|stop|restart|status}"
        exit 1
esac

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment