Blob Blame History Raw
#!/bin/sh
#
# chkconfig: 2345 26 74
# description: apmd is used for monitoring battery status and logging it via \
#	syslog(8). It can also be used for shutting down the machine when \
#	the battery is low.
# processname: apmd
# config: /etc/sysconfig/apmd
# clock: /etc/sysconfig/clock

### BEGIN INIT INFO
# Provides: apmd
# Required-Start: $syslog $local_fs
# Required-Stop: $syslog $local_fs
# Default-Start:  2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop apmd
# Description: apmd is used for monitoring battery status and logging it via
#	           syslog(8). It can also be used for shutting down the machine when
#	           the battery is low.
### END INIT INFO

CONFIG=/etc/sysconfig/apmd

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

RETVAL=0

start() {
	# Check that we're a priviledged user
	[ `id -u` = 0 ] || exit 4

	# If APM isn't supported by the kernel, try loading the module...
	[ -e /proc/apm ] || /sbin/modprobe apm &>/dev/null
		
	# Don't bother if /proc/apm still doesn't exist, kernel doesn't have
	# support for APM.
	[ -e /proc/apm ] || exit 1
	
	# Check if acpid is executable
	[ -x /usr/sbin/apmd ] || exit 5
	
	# Check if config exists
	[ -f $CONFIG ] || exit 6
	
	. "$CONFIG"

	echo -n $"Starting up APM daemon: "
	daemon /usr/sbin/apmd -p $LOGPERCENTCHANGE -w $WARNPERCENT $ADDPARAMS \
		-P /etc/sysconfig/apm-scripts/apmscript
	RETVAL=$?
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/apmd
	echo
	return $RETVAL
}

stop() {
	echo -n $"Shutting down APM daemon: "
	killproc apmd
	RETVAL=$?
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/apmd
	echo
	return $RETVAL
}

restart() {
	stop
	start
}

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

exit $RETVAL