#!/bin/bash
#
# chkconfig: 2345 26 74
# description: acpid is used to listen and dispatch ACPI events received from \
#	the kernel.
# processname: acpid

# If ACPI isn't supported by the kernel, try loading the module...
[ -e /proc/acpi ] || /sbin/modprobe acpi &>/dev/null

# Don't bother if /proc/acpi still doesn't exist, kernel doesn't have
# support for ACPI.
[ -e /proc/acpi ] || exit 0

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

RETVAL=0

start() {
	echo -n $"Starting up ACPI daemon: "
	daemon /usr/sbin/acpid
	RETVAL=$?
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/acpid
	echo
}

stop() {
	echo -n $"Shutting down ACPI daemon: "
	killproc acpid
	RETVAL=$?
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/acpid
	/sbin/modprobe -r acpi &>/dev/null
	echo
}

dostatus() {
	status acpid
	RETVAL=$?
}

restart() {
	stop
	start
	RETVAL=$?
}	

condrestart() {
	[ -e /var/lock/subsys/acpid ] && restart || :
}

reload() {
	killproc acpid -HUP
}	

# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  status)
	dostatus
	;;
  restart)
	restart
	;;
  condrestart)
	condrestart
	;;
  reload)
	reload
	;;
*)
	echo "Usage: acpid {start|stop|restart|condrestart|reload|status}"
	exit 1
esac

exit $RETVAL
