#! /bin/sh
#
# osh-sync-watcher: The Bastion sync daemon
#
### BEGIN INIT INFO
# Provides:          osh-sync-watcher
# Required-Start:    $network
# Required-Stop:     $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Starts the bastion master-slave sync watcher at boot time
# Description:       Script to start/stop/reload the osh-sync-watcher daemon
### END INIT INFO

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/opt/bastion/bin/admin/osh-sync-watcher.sh
NAME=osh-sync-watcher
DESC="syncs the master bastion to the slave"
SCRIPTNAME=/etc/init.d/$NAME
# don't change the pidfile location because it's also in the script
PIDFILE=/var/run/osh-sync-watcher.pid

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions

test -x $DAEMON || exit 0

case "$1" in
    start)
	echo -n "Starting osh-sync-watcher daemon"
	start-stop-daemon --start --background --exec $DAEMON
	echo "."
	;;
    stop)
	echo -n "Shutting down osh-sync-watcher daemon... "
	if pgrep -c -f $DAEMON >/dev/null ; then
		pkill -f $DAEMON
		echo done
	else
		echo "not running"
	fi
	;;
    force-reload|restart)
	echo -n "Restarting osh-sync-watcher daemon"
	if pgrep -c -f $DAEMON >/dev/null ; then
		pkill -f $DAEMON
		echo done
	else
		echo "not running"
	fi
	start-stop-daemon --start --background --exec $DAEMON
	echo "."
	;;
    *)
	echo "Usage: $0 {start|stop|restart|force-reload}"
	exit 1
esac
exit 0