#!/bin/sh
# NUT upsd start-up and shutdown script.
# This should be started after rc.nut-drvctl on the machine connected to the
# UPS's control port. See /etc/nut/ for configuration files.

# Start upsd:
upsd_start() {
  # Make sure the runtime directory is there:
  mkdir -p /run/nut
  chown -R nut:nut /run/nut
  chmod 0770 /run/nut
  # Start the UPS daemon:
  echo "Starting the NUT UPS information server:  upsd -u nut"
  upsd -u nut
}

# Stop upsd:
upsd_stop() {
  echo "Stopping the NUT UPS information server."
  upsd -c stop
}

# Reload configuration files for upsd:
upsd_reload() {
  echo "Reloading configuration files for the NUT UPS information server:  upsd -c reload"
  upsd -c reload
}

case "$1" in
'start')
  upsd_start
  ;;
'stop')
  upsd_stop
  ;;
'reload')
  upsd_reload
  ;;
*)
  echo "usage $0 start|stop|reload"
esac