#!/bin/sh
#
# garbd		Galera Arbitrator Daemon.
#
# chkconfig: - 90 10
# description:	multi-line \
#		description \
#		of the service.
# processname: garbd
# config: /etc/garbd/garbd.conf
# pidfile: /var/run/garbd/garbd.pid
### BEGIN INIT INFO
# Provides:          garbd
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Should-Start:      $network $named $time
# Should-Stop:       $network $named $time
# Default-Start:     3 4 5
# Default-Stop:      0 1 2 6
# Short-Description: Galera Arbitrator Daemon
# Description:       The Galera Arbitrator is used as part of clusters
#                    that have only two real Galera servers and need an
#                    extra node to arbitrate split brain situations.
### END INIT INFO

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

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

PIDFILE=/run/garbd/garbd.pid
LOCKFILE=/run/lock/subsys/garbd
RETVAL=0

start()
{
	start_daemon --make-pidfile --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user _garbd -- garbd -d -c /etc/garbd/garbd.conf
	RETVAL=$?
	return $RETVAL
}

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

restart()
{
	stop
	start
}

reload()
{
	msg_reloading garbd
	stop_daemon --pidfile "$PIDFILE" --expect-user _garbd -HUP -- garbd
	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 _garbd -- garbd
		RETVAL=$?
		;;
	*)
		msg_usage "${0##*/} {start|stop|reload|restart|condstop|condrestart|condreload|status}"
		RETVAL=1
esac

exit $RETVAL
