#!/bin/bash

. $PM_UTILS_LIBDIR/functions

case "$1" in
	hibernate)
		if test -f /etc/apcupsd/powerfail ; then
			/etc/init.d/apcupsd stop
			# Stopping of daemon typically needs at least 3 sec.
			sleep 10
			/etc/init.d/apcupsd powerdown
		fi
		;;
	thaw)
		# powerfail exists => apcupsd was running before hibernation
		if test -f /etc/apcupsd/powerfail ; then
			/etc/init.d/apcupsd start
		fi
		;;
	*)
		;;
esac

exit 0
