#!/bin/bash
### BEGIN INIT INFO
# Provides: haroute
# Required-Start: $all
# Required-Stop: $local_fs
# Default-Start: 3
# Default-Stop: 0 6
# Short-Description: Control haroute daemon for high availability routing
### END INIT INFO
NAME="haroute"
PATH="/sbin:/bin:/usr/sbin:/usr/bin"
PID_FILE=/var/run/haroute.pid
LOG_FILE=/var/log/haroute.log
get_pid() {
cat "$PID_FILE"
}
is_running() {
[ -f "$PID_FILE" ] && ps `get_pid` > /dev/null 2>&1
}
start_haroute() {
sleep 5
haroute -p $PID_FILE --log-file $LOG_FILE & disown
}
stop_haroute() {
kill `get_pid`
}
case "$1" in
start)
if is_running; then
echo "Already started"
else
echo "Starting $NAME"
start_haroute
fi
;;
stop)
if is_running; then
echo "Stopping $NAME"
stop_haroute
else
echo "Not Running"
fi
;;
restart)
stop_haroute
start_haroute
;;
status)
if is_running; then
echo "Running"
else
echo "Stopped"
exit 1
fi
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac
exit 0