#! /bin/sh

DAEMON=/usr/sbin/sleepd
NAME=sleepd
DESC="APM sleep daemon"

test -f $DAEMON || exit 0

set -e

# Source defaults file; edit that file to configure this script.
PARAMS=""
if [ -e /etc/default/sleepd ]; then
	. /etc/default/sleepd
fi

stop() {
   eval start-stop-daemon --stop --quiet --oknodo --pidfile /var/run/$NAME.pid \
		--exec $DAEMON -- $PARAMS
}

start() {
   eval start-stop-daemon --quiet --start --pidfile /var/run/$NAME.pid \
		--exec $DAEMON -- $PARAMS
}

case "$1" in
	start)
		# Ensure apm module is loaded.
		test -e /dev/apm_bios && touch /dev/apm_bios

		echo -n "Starting $DESC: "
		start
		echo "$NAME."
	;;
	stop)
		echo -n "Stopping $DESC: "
		stop
		echo "$NAME."
	;;
	restart|force-reload)
		echo -n "Restarting $DESC: "
		stop
		sleep 1
		start
		echo "$NAME."
	;;
	*)
		echo "Usage: /etc/init.d/$NAME {start|stop|restart|force-reload}" >&2
		exit 1
		;;
esac

exit 0
