#!/bin/sh
#
# PowerManager:   PowerManager daemon
#
# chkconfig: - 98 02
# description:  This is a daemon for automatically doing power stuff \
#               and providing the sf.net.PowerManager interfaces. \
#
# processname: PowerManager
# pidfile: /var/run/PowerManager.pid
#

# Sanity check
if [ ! -x /usr/sbin/PowerManager ]; then
	echo "Cannot find PowerManager!"
	exit 1
	fi

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

# so we can rearrange this easily
processname=PowerManager
servicename=PowerManager
pidfile=/var/run/PowerManager.pid

RETVAL=0

start()
{
	echo -n $"Starting PowerManager daemon: "
	daemon --check $servicename $processname
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$servicename && echo `/sbin/pidof $processname` > $pidfile
}

stop()
{
	echo -n $"Stopping PowerManager daemon: "

	killproc $servicename -TERM
	RETVAL=$?
	echo
	if [ $RETVAL -eq 0 ]; then
		rm -f /var/lock/subsys/$servicename
		rm -f $pidfile
	fi
}

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	status)
		status $processname
		RETVAL=$?
		;;
	restart)
		stop
		start
		;;
	condrestart)
		if [ -f /var/lock/subsys/$servicename ]; then
			stop
			start
		fi
		;;
	*)
		echo $"Usage: $0 {start|stop|status|restart|condrestart}"
		;;
esac
exit $RETVAL
