Created
January 17, 2013 22:48
-
-
Save ring-the-sysop/4560586 to your computer and use it in GitHub Desktop.
A RHEL 6 start/stop/status script for carbon-cache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# chkconfig: 2345 92 17 | |
# description: Backend data caching and persistence daemon for Graphite | |
# | |
# Source function library. | |
. /etc/rc.d/init.d/functions | |
PROG='carbon-cache' | |
PIDFILE="/opt/graphite/storage/${PROG}-a.pid" | |
SUBSYSFILE="/var/lock/subsys/$PROG" | |
EXEC="/opt/graphite/bin/${PROG}.py" | |
RETVAL=0 | |
start() { | |
if [ $UID -ne 0 ]; then | |
echo "User has insufficient privilege." | |
exit 1 | |
fi | |
$EXEC start | |
RETVAL=$? | |
[ $RETVAL -eq 0 ] && touch $SUBSYSFILE | |
} | |
stop() { | |
if [ $UID -ne 0 ]; then | |
echo "User has insufficient privilege." | |
exit 1 | |
fi | |
$EXEC status > /dev/null 2>&1 | |
STATUS_RETVAL=$? | |
[ $STATUS_RETVAL -eq 0 ] && PID=`cat $PIDFILE` | |
$EXEC stop | |
RETVAL=$? | |
if [ $RETVAL -eq 0 ] && [ $STATUS_RETVAL -eq 0 ]; then | |
while [ -d /proc/$PID ] | |
do | |
echo "waiting for carbon-cache to shutdown..." | |
sleep 5 | |
done | |
echo "carbon-cache shutdown complete" | |
fi | |
[ $RETVAL -eq 0 ] && [ -f $SUBSYSFILE ] && rm $SUBSYSFILE | |
} | |
status() { | |
$EXEC status | |
RETVAL=$? | |
} | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
restart|reload) | |
stop | |
start | |
;; | |
status) | |
status | |
;; | |
*) | |
echo $"Usage: $0 {start|stop|restart|reload|status}" | |
exit 1 | |
esac | |
exit $RETVAL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment