#!/bin/bash
#
# Init file for columbus's viking
#
# FIXME
# chkconfig: 2345 90 10
# description: columbus's viking - syncs columbus on link good detection
#
# processname: viking
# pidfile: /var/run/viking

# source function library
. /etc/rc.d/init.d/functions

# pull in sysconfig settings
# FIXME : this might be a good idea
# [ -f /etc/sysconfig/sshd ] && . /etc/sysconfig/sshd

RETVAL=0
prog="viking"

start()
{
	echo -n $"Starting $prog:"
	[ -f /var/lock/subsys/columbus ] && echo && return 0
        viking --watch > /dev/null 2>&1 &
	RETVAL=$?
	[ "$RETVAL" = 0 ] && touch /var/lock/subsys/columbus \
	&& action "" /bin/true \
	|| action "" /bin/false
}

stop()
{
	echo -n $"Stopping $prog:"
	killproc viking -TERM
	RETVAL=$?
	[ "$RETVAL" = 0 ] && rm -f /var/lock/subsys/columbus
	echo
}

case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	restart)
		stop
		start
		;;
	condrestart)
		if [ -f /var/lock/subsys/columbus ] ; then
			stop
			# avoid race
			sleep 1
			start
		fi
		;;
	status)
		status viking
		RETVAL=$?
		;;
	*)
		echo $"Usage: $0 {start|stop|restart|condrestart|status}"
		RETVAL=1
esac
exit $RETVAL
