Skip to content

Instantly share code, notes, and snippets.

@spatzle
Last active October 5, 2015 21:28
Show Gist options
  • Save spatzle/2879582 to your computer and use it in GitHub Desktop.
Save spatzle/2879582 to your computer and use it in GitHub Desktop.
init.d file for metricsd
#!/bin/sh
#
# for use with https://github.com/mojodna/metricsd
# chkconfig: 2345 95 1
# description: Starts Daemon Using metricsd.jar.
#
# Source function library.
# author: Joyce Chan
. /etc/init.d/functions
JAVA=${JAVA:-/usr/bin/java}
prog=metricsd
jar=metricsd-0.4.2-jar-with-dependencies.jar
config_filename=config.json
log_filename=metricsd.log
RETVAL=0
start () {
echo -n $"Starting $prog: "
# start daemon
daemon +19 "CONFIG=/opt/$prog/$config_filename java -jar /opt/$prog/$jar" > /var/log/$prog/$log_filename &
RETVAL=$?
echo
if [ $RETVAL = 0 ]; then
success "$prog started"
else
failure "$prog failed to start"
fi
echo
return $RETVAL
}
stop () {
# stop daemon
echo -n $"Stopping $prog: "
for i in {1..2}
do
kill -9 `ps uax | grep -i "java -jar /opt/$prog/$jar" | head -n 1 | awk '{print $2}'` > /dev/null 2>&1
done
RETVAL=$?
if [ $RETVAL = 0 ]; then
success "$prog stopped"
else
failure "$prog failed to stop"
fi
return $RETVAL
}
restart() {
stop
start
}
case $1 in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo $"Usage: $prog {start|stop|restart}"
exit 3
esac
exit $RETVAL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment