#!/bin/bash

# early-shutdown-with-remote
#
# Jason Healy
#
# Based on the file "early-shutdown" from the main Suffield NUT package.
#
# This script parses output from upssched and shuts the machine down early
# (that is, before the UPS battery goes critical).  This version also makes
# a call to an external script which shuts down remote machines.
#
# It also deals with receiving FSD (forced shutdown) requests from the
# master server, if the master is about to die (even if we aren't).  In this
# case, we shut down too, to ensure that we shut off in time.
#

case "${1}" in

  early-shutdown)
    logger -t early-shutdown "Early Shutdown time has arrived!"
    /usr/local/bin/shutdown_os9
    sleep 10
    /usr/local/ups/sbin/upsmon -c fsd
  ;;

  forced-shutdown)
    logger -t early-shutdown "UPS Master sent Forced Shutdown Request"
    /usr/local/bin/shutdown_os9
    sleep 10
    /usr/local/ups/sbin/upsmon -c fsd
  ;;

  *)
    logger -t early-shutdown "Unknown command: ${1}"
  ;;

esac
