#!/bin/sh
# NUT upsmon start-up and shutdown script.
# upsmon is the client process that is responsible for the most important part
# of UPS monitoring--shutting down the system when the power goes out.
#
# upsmon should be run on every machine that is powered by the UPS if you wish
# to support automatic shutdown on battery power.
#
# See /etc/nut/ for configuration files.

# Start upsmon:
upsmon_start() {
  # Make sure the runtime directory is there:
  mkdir -p /run/nut
  chown -R nut:nut /run/nut
  chmod 0770 /run/nut
  # Start the NUT UPS monitor and shutdown controller:
  echo "Starting the NUT UPS monitor and shutdown controller:  upsmon -u nut"
  upsmon -u nut
}

# Stop upsmon:
upsmon_stop() {
  echo "Stopping the NUT UPS monitor and shutdown controller."
  upsmon -c stop
}

# Reload configuration files for upsmon:
upsmon_reload() {
  echo "Reloading configuration files for the NUT UPS monitor and shutdown controller:  upsmon -c reload"
  upsmon -c reload
}

case "$1" in
'start')
  upsmon_start
  ;;
'stop')
  upsmon_stop
  ;;
'reload')
  upsmon_reload
  ;;
*)
  echo "usage $0 start|stop|reload"
esac
