#!/bin/sh # chkconfig: 2345 64 36 # description: Monitors MySQL and executes specified commands upon change in state # processname: mylbhelper BINARY=/usr/local/bin/mylbhelper RETVAL=0 COMMAND=$1 shift ARGS=$* error() { echo "Can't find $1. Please fix your installation" exit 1 } [ -x $BINARY ] || error $BINARY start() { echo -n "Starting mylbhelper... " $BINARY $ARGS RETVAL=$? if [ $RETVAL -eq 0 ]; then echo "[ OK ]" else echo "[ FAIL ]" fi } stop() { echo -n "Stopping mylbhelper... " $BINARY $ARGS -t 1>/dev/null 2>&1 RETVAL=$? if [ $RETVAL -eq 0 ]; then echo "[ OK ]" else echo "[ FAIL ]" fi } status(){ PID=`pidof $BINARY` RETVAL=$? if [ $RETVAL -eq 0 ]; then echo "mylbhelper running with PID $PID" else echo "mylbhelper does not appear to be running" fi } case "$COMMAND" in start) start ;; stop) stop ;; status) status ;; restart) stop sleep 1 start ;; *) echo "Usage: $0 {start|stop|restart|status}" esac