#!/bin/sh
#
# chkconfig: 2345 27 73
# description: apmiser is used for monitoring system usage when on batteries, \
#	scaling the CPU voltage down via tpctl when idle to save power.
# processname: apmiser

# If thinkpad devices don't exist, try loading the module...
[ -e /dev/thinkpad ] || /sbin/modprobe thinkpad &>/dev/null

# Don't bother if /dev/thinkpad still doesn't exist, kernel doesn't have
# support for thinkpads or this is not a thinkpad
[ -e /dev/thinkpad ] || exit 0

# apmiser needs APM, so don't bother if using ACPI
[ -e /proc/apm ] || exit 0

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

RETVAL=0

start() {
	gprintf "Starting up APMISER daemon: "
	daemon /usr/sbin/apmiser --daemon 
	touch /var/lock/subsys/apmiser
	echo
}

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

dostatus() {
	status apmiser
	RETVAL=$?
}

restart() {
	stop
	start
	RETVAL=$?
}

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

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

exit $RETVAL
