#!/bin/sh
#
# keepalived	Start keepalived to manage IPVS & LVS.
#
# chkconfig: - 90 10
# description: Start and stop Keepalived
# processname: keepalived
# config: /etc/keepalived/keepalived.conf
# pidfile: /var/run/keepalived.pid

### BEGIN INIT INFO
# Provides:       keepalived
# Required-Start: $remote_fs $syslog
# Required-Stop:  $remote_fs $syslog
# Default-Start:  3 4 5
# Default-Stop:   0 1 2 6
# Short-Description:      Start keepalived to manage IPVS & LVS
# Description: Start keepalived to manage IPVS & LVS

### END INIT INFO

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

# Source function library.
. /etc/init.d/functions

PIDFILE=/var/run/keepalived.pid
LOCKFILE=/var/lock/subsys/keepalived
SourceIfNotEmpty /etc/sysconfig/keepalived

RETVAL=0

start()
{
	start_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user root -- /usr/sbin/keepalived ${KEEPALIVED_OPTIONS}
	RETVAL=$?
	return $RETVAL
}

stop()
{
	stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user root -- keepalived
	RETVAL=$?
	return $RETVAL
}

restart()
{
	stop
	start
}

reload()
{
	msg_reloading keepalived
	stop_daemon --pidfile "$PIDFILE" --expect-user root -HUP -- keepalived
	RETVAL=$?
	return $RETVAL
} 

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	reload)
		reload
		;;
	restart)
		restart
		;;
	condstop)
		if [ -e "$LOCKFILE" ]; then
			stop
		fi
		;;
	condrestart)
		if [ -e "$LOCKFILE" ]; then
			restart
		fi
		;;
	condreload)
		if [ -e "$LOCKFILE" ]; then
			reload
		fi
		;;
	status)
		status --pidfile "$PIDFILE" --expect-user root -- keepalived
		RETVAL=$?
		;;
	*)
		msg_usage "${0##*/} {start|stop|reload|restart|condstop|condrestart|condreload|status}"
		RETVAL=1
esac

exit $RETVAL
