#!/bin/bash
#
#	/etc/rc.d/init.d/clvmd
#
# Starts the clvm daemon
# NOTE: These startup levels may not be right yet - it depends on where
#       the rest of the cluster startup goes.
#
# chkconfig: 345 72 5
# description: distributes LVM commands in a clustered environment. \
#    a clvmd must be run on all nodes in a cluster for clustered LVM \
#    operations to work.
# processname: clvmd

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

BINARY=/usr/sbin/clvmd
LOCKFILE=/var/lock/subsys/clvmd

test -x "$BINARY" || exit 0

RETVAL=0

#
#	See how we were called.
#

prog="clvmd"

start() {
	# Check if clvmd is already running
	if [ ! -f "$LOCKFILE" ]; then
	    echo -n $"Starting $prog: "
	    daemon $BINARY
	    RETVAL=$?
	    [ $RETVAL -eq 0 ] && touch $LOCKFILE
	    echo
	fi
	return $RETVAL
}

stop() {
	echo -n $"Stopping $prog: "
	killproc $BINARY
	RETVAL=$?
	[ $RETVAL -eq 0 ] && rm -f $LOCKFILE
	echo
        return $RETVAL
}


restart() {
	stop
	start
}	

reload() {
	restart
}	

status_clvm() {
 	status $BINARY
}

case "$1" in
start)
	start
	;;
stop)
	stop
	;;
reload|restart)
	restart
	;;
condrestart)
	if [ -f $LOCKFILE ]; then
	    restart
	fi
	;;
status)
	status_clvm
	;;
*)
	echo $"Usage: $0 {start|stop|restart|condrestart|status}"
	exit 1
esac

exit $?
exit $RETVAL
