Created: 03/30/2017

Last Tested 03/30/2017

Notice: I am going to assume that you have you ups connected via usb and passed to the FreeNAS VM.


  1. Login to FreeNAS
  2. Go to the following location ServicesManagementUPS → click on +
    • Tick Enabled
    • UPS Mode: MASTER
    • Identifier: ups :This will be used later on the remote guest.
    • Driver: This will be the model of your ups mine is ( APC Back-UPS RS USB USB )
    • Driver Port: Select the option that describes your ups on USB.
    • Description: optional
    • Shutdown Mode: (1.)BAT - When the unit enters Battery mode. (2.) LowBAT - When the ups is low on power.
    • Shutdown Time: Either (1.)Time that the ups has been on battery or (2.)time left on battery.
    • Allow Remote Connections: TICK
    • Monitor User: You can change this: this will be used later on the remote guest.
    • Password: Input one here: this will be used later on the remote guest.
    • Send Alerts: Tick if you have alerts enabled under: System → Alerts & Reporting.
    • Power Off UPS: Untick: Must be supported by the device and wanted by the user.
  3. You are now done with this part.

Testing 1: Run the following command in CLI upsc [email protected] it should output information about the current battery level.

Testing 2: I would test the full configuration. Set Shutdown Mode to BATT then set shutdown time to a low number then unplug the ups and see if FreeNAS goes for shutdown.


Setting up Debian as an NUT client

    • Or copy the code that was available at the time of this article.
      #!/bin/bash
      
      apt-get purge nut && apt-get purge nut-client && apt-get purge nut-server
      rm -r * /etc/nut
      
      # simple script to setup a NUT netclient config
      # assumptions are Ubuntu 14.04.1, and that the nut server has only one UPS attached
      # and is accessible by an already configured nut user+pass.
      
      read -e -p "Do you wish to install and configure NUT from scratch (y/n): " -i "y" SETUP_NUT
      echo
      
      if [ ! "$SETUP_NUT" = "y" ]; then
        echo "OK exiting script"
        exit -1
      fi
      
      
      if ! dpkg -s nut >/dev/null; then
        echo "installing nut package"
        apt-get install -q nut -y
      
        # Get the ups and server name as well as the nut user credentials needed
        echo "Pleae input the following info"
        read -e -p "Nut SERVER NAME or IP ADDRESS (needed to construct the local MONITOR line): " -i "nutserver" NUT_SERVER
        read -e -p "The nut UPS NAME you wish to monitor on the above server: " -i "ups" UPS_NAME
        read -e -p "Nut servers MONITOR USER (defined in /etc/nut/upsd.users): " -i "monmaster" NUT_USER
        read -e -p "and the monitor users PASSWORD: " -i "mmpass" USER_PASS
      
        # most basic of sanity checks (are any of the above empty if so exit script  
        if [ -z "$NUT_SERVER" ]; then echo "No server name given. Exiting."; exit -1; fi
        if [ -z "$UPS_NAME" ]; then echo "No ups name given. Exiting."; exit -1; fi 
        if [ -z "$NUT_USER" ]; then echo "No username given. Exiting."; exit -1; fi
        if [ -z "$USER_PASS" ]; then echo "No password given. Exiting."; exit -1; fi
      
        # now to construct the MONITOR line from the above info and put it on the end of /etc/nut/upsmon.conf
        echo "MONITOR $UPS_NAME@$NUT_SERVER 1 $NUT_USER $USER_PASS slave" | tee -a /etc/nut/upsmon.conf >/dev/null
      
        # now to replace the MODE=none with MODE=netclient in nut.conf
        sed -i 's/MODE=none/MODE=netclient/g' /etc/nut/nut.conf
      
        echo "starting nut-client"
        /etc/init.d/nut-client restart
      
        # fsd is normally called when a ups is OB (On Battery) and LB (Low Battery)
        # fsd = Full Shut Down
      
        echo "the following command should list current information about your ups"
        echo "upsc $UPS_NAME@$NUT_SERVER"
      
        echo "To test this setup it is best to reboot first then execute the following command"
        echo "sudo upsmon -c fsd"
        echo "If all is functioning correctly this will simulate the ups being in both the following states:"
        echo "On Battery (OB) & Low Battery (LB)"
        echo "In that situation the system should perform an automatic power-fail shutdown"
      
      else
        echo "nut package already installed, please consider removing nut first"
        echo "as this script expects to install and configure nut itself"
        echo "sudo apt-get purge nut"
        echo "N.B. WARNING this will remove all previous configurations"
      fi
  1. Create the following script file in the root home folder nano setup.sh
    • Add in the script form above. (notice you may want to remove all of the SUDO commands form the file. In my copy I have already done this.
    • Make the script bookable: chmod +x setup.sh
    • Run the script ./setup.sh - Make sure your vm has a network connection.
    • Do you wish to install and configure NUT from scratch (y/n): Y = press Y
    • Accept the install of the new packages.
    • Nut SERVER NAME or IP ADDRESS: The IP or DNS name of the freenas box.
    • The nut UPS NAME: This is the name from the FreeNAS setup above (2.3)
    • The Nut servers MONITOR USER: This is the username from the FreeNAS setup above (2.10)
    • The monitor users PASSWORD: This is the user password from the FreeNAS setup above (2.11)
  2. You are now done.

Testing 0: upsc [email protected]

Testing 1: Run the following command upsmon -c fsd it should simulate the shutdown because of a battery low alert.

Testing 2: Again I would test the full configuration. Set Shutdown Mode to BATT then set shutdown time to a low number then unplug the ups and see if FreeNAS and the Debian box go for a shutdown.