cvsdist 075053
#! /bin/bash
cvsdist bfc54a
#
ebcf5e
# ups: Starts the Network UPS Tools
ebcf5e
#
cvsdist b21753
# chkconfig: - 26 74
cvsdist 81ab26
# description: Network UPS Tools is a collection of programs which provide a common \
ebcf5e
#		interface for monitoring and administering UPS hardware.
cvsdist bfc54a
# processname: upsd
cvsdist bfc54a
# config: /etc/ups/
ebcf5e
# config: /etc/sysconfig/ups
ebcf5e
#
cvsdist bfc54a
cvsdist bfc54a
# Source function library.
cvsdist bfc54a
if [ -f /etc/init.d/functions ]; then
cvsdist 075053
	. /etc/init.d/functions
cvsdist bfc54a
elif [ -f /etc/rc.d/init.d/functions ]; then
cvsdist 075053
	. /etc/rc.d/init.d/functions
cvsdist bfc54a
else
cvsdist 075053
	exit 0
cvsdist bfc54a
fi
cvsdist bfc54a
cvsdist bfc54a
# Get config.
cvsdist bfc54a
if [ -f /etc/sysconfig/ups ]; then
cvsdist bfc54a
	. /etc/sysconfig/ups
cvsdist bfc54a
else
cvsdist bfc54a
	SERVER="no"
cvsdist bfc54a
fi
cvsdist bfc54a
cvsdist bfc54a
start() {
cvsdist 726fc7
	if [ "$SERVER" = "yes" ]; then
eb2ea7
		echo -n $"Starting UPS driver controller: "
4ab5f7
		daemon /sbin/upsdrvctl start > /dev/null 2>&1 && success || failure
eb2ea7
		RETVAL=$?
cvsdist 726fc7
		echo
cvsdist bfc54a
cvsdist 726fc7
		prog="upsd"
cvsdist 726fc7
		echo -n $"Starting $prog: "
4ab5f7
		daemon /usr/sbin/upsd $UPSD_OPTIONS > /dev/null 2>&1 && success || failure
eb2ea7
		if [ "$RETVAL" = 0 ]; then
eb2ea7
			RETVAL=$?
eb2ea7
		fi
cvsdist 726fc7
		echo
cvsdist bfc54a
cvsdist 726fc7
		echo -n $"Starting UPS monitor (master): "
ebcf5e
		daemon --pidfile /var/run/nut/upsmon.pid /usr/sbin/upsmon > /dev/null 2>&1 && success || failure
eb2ea7
		if [ "$RETVAL" = 0 ]; then
eb2ea7
			RETVAL=$?
eb2ea7
		fi
cvsdist 726fc7
		echo
cvsdist 726fc7
	else
cvsdist 726fc7
		echo -n $"Starting UPS monitor (slave): "
ebcf5e
		daemon --pidfile /var/run/nut/upsmon.pid /usr/sbin/upsmon > /dev/null 2>&1 && success || failure
cvsdist 726fc7
		echo
cvsdist 726fc7
	fi
cvsdist bfc54a
cvsdist 726fc7
	[ "$RETVAL" = 0 ] && touch /var/lock/subsys/ups
cvsdist bfc54a
}
cvsdist bfc54a
cvsdist bfc54a
stop() {
cvsdist 075053
	echo -n $"Stopping UPS monitor: "
ebcf5e
	killproc -p /var/run/nut/upsmon.pid upsmon
cvsdist bfc54a
	echo
cvsdist bfc54a
cvsdist 075053
	if [ "$SERVER" = "yes" ]; then
cvsdist 075053
		prog="upsd"
cvsdist 075053
		echo -n $"Stopping $prog: "
4ab5f7
		killproc upsd > /dev/null 2>&1 && success || failure
cvsdist 075053
		RETVAL=$?
cvsdist 075053
		echo
cvsdist 075053
4ab5f7
		echo -n $"Shutting down upsdrvctl: "
4ab5f7
		/sbin/upsdrvctl stop > /dev/null 2>&1 && success || failure
4ab5f7
		if [ "$RETVAL" = 0 ]; then
4ab5f7
			RETVAL=$?
cvsdist 075053
		fi
cvsdist 075053
		echo
cvsdist 075053
	fi
cvsdist 075053
	[ "$RETVAL" = 0 ] && rm -f /var/lock/subsys/ups
cvsdist bfc54a
}
cvsdist bfc54a
cvsdist bfc54a
restart() {
cvsdist bfc54a
	stop
ebcf5e
        waitmore=5
ebcf5e
        while [ -n "$(ls /var/run/nut/)" -a $waitmore -ge 1 ]
ebcf5e
        do
ebcf5e
          sleep 1
ebcf5e
          waitmore=$((waitmore-1))
ebcf5e
        done
cvsdist bfc54a
	start
cvsdist bfc54a
}
cvsdist bfc54a
9d928d
reload() {
9d928d
	# FIXME: upsd and upsmon always return 0
9d928d
	# => can't tell if reload was successful
9d928d
	if [ "$SERVER" = "yes" ]; then
9d928d
		action "Reloading upsd:" /usr/sbin/upsd -c reload
9d928d
		RETVAL=$?
9d928d
	fi
9d928d
	action "Reloading upsmon:" /usr/sbin/upsmon -c reload
9d928d
	if [ "$RETVAL" = 0 ]; then
9d928d
		RETVAL=$?
9d928d
	fi
9d928d
}
9d928d
cvsdist bfc54a
# See how we are called.
cvsdist bfc54a
case "$1" in
cvsdist 075053
	start)
cvsdist 075053
		start ;;
cvsdist 075053
cvsdist 075053
	stop)
cvsdist 075053
		stop ;;
cvsdist 075053
cvsdist 075053
	restart)
cvsdist 075053
		restart ;;
cvsdist 075053
9d928d
	try-restart)
cvsdist 075053
		[ -f /var/lock/subsys/ups ] && restart || :
cvsdist 075053
		;;
cvsdist 075053
9d928d
	reload)
9d928d
		reload ;;
9d928d
9d928d
	force-reload)
9d928d
		restart ;;
9d928d
cvsdist 075053
	status)
cvsdist 075053
		if [ "$SERVER" = "yes" ]; then
cvsdist 075053
			status upsd
cvsdist 075053
		fi
cvsdist 075053
		status upsmon
cvsdist 075053
		;;
cvsdist 075053
cvsdist 075053
	*)
9d928d
		echo $"Usage: $0 {start|stop|restart|try-restart|reload|force-reload|status}"
9d928d
		RETVAL=3
cvsdist bfc54a
esac
cvsdist bfc54a
cvsdist bfc54a
exit $RETVAL