Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Register
    • Login

    UPSMON independent shutdown.

    Scheduled Pinned Locked Moved Hardware
    37 Posts 3 Posters 4.1k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • 4
      4o4rh @stephenw10
      last edited by 4o4rh

      @stephenw10 correct, no comms. If the power failed at my NAS, it means 99.9% of the time, the power has failed for the whole house. the nas is connected to an APC 1500 so will last 30 - 60 minutes.

      The mini-UPS are the same size as the power adapter of the J1900 and unintelligent. As i can't know when the battery will fail, for safety i would shutdown the J1900 after 10min

      https://www.amazon.com/Battery-Uninterruptable-Function-100V-240V-Wireless/dp/B07W8MCBMS?th=1

      1 Reply Last reply Reply Quote 0
      • stephenw10S
        stephenw10 Netgate Administrator
        last edited by

        Ok well you should be able to do it using upssched. You may have to add it manually though I'm not sure anything is added via the package. There is nothing in /usr/local/etc/nut/upssched.conf by default.

        Steve

        4 1 Reply Last reply Reply Quote 0
        • 4
          4o4rh @stephenw10
          last edited by

          @stephenw10
          i created in the Filer package
          /usr/local/etc/nut/upssched.conf 0644 UPS Shutdown Scheduler

          CMDSCRIPT /usr/local/bin/upssched-cmd
          PIPEFN /var/db/nut/upssched.pipe
          LOCKFN /var/db/nut/upssched.lock
          AT NOCOMM * EXECUTE EMAIL
          AT COMMBAD * START-TIMER COMMBAD 10
          AT COMMOK * CANCEL-TIMER COMMBAD COMMOK
          AT FSD * EXECUTE EMAIL
          AT LOWBATT * EXECUTE EMAIL
          AT ONBATT * START-TIMER ONBATT 120
          AT ONBATT * EXECUTE EMAIL
          AT ONLINE * CANCEL-TIMER ONBATT ONLINE
          AT ONLINE * EXECUTE EMAIL
          AT REPLBATT * EXECUTE EMAIL
          AT SHUTDOWN * EXECUTE EMAIL
          

          upsmon contents are

          MONITOR ups@nas.net.lan 1 upsmon abc123 slave
          SHUTDOWNCMD "/sbin/shutdown -p +0"
          POWERDOWNFLAG /etc/killpower
          

          i don't think this is working, but not sure how to simulate test it.

          1 Reply Last reply Reply Quote 0
          • stephenw10S
            stephenw10 Netgate Administrator
            last edited by

            Do you see anything logged in reaction to any of those events? Going On-Battery for example?
            Is NUT in pfSense actually monitoring the remote UPS as expected?

            Steve

            4 1 Reply Last reply Reply Quote 0
            • 4
              4o4rh @stephenw10
              last edited by

              @stephenw10 nut is correctly monitoring the UPS on the nas box. I see on the UPS Status screen the device go offline if i shutdown the nas box for example, or if it runs a self-test

              1 Reply Last reply Reply Quote 0
              • stephenw10S
                stephenw10 Netgate Administrator
                last edited by

                But it doesn't log the timer starting if the UPS goes on battery for example?

                I have no way to test this unfortunately.

                Steve

                4 1 Reply Last reply Reply Quote 0
                • 4
                  4o4rh @stephenw10
                  last edited by

                  @stephenw10 so here is my config

                  upsmon.conf

                  NOTIFYCMD /usr/local/sbin/upssched
                  POLLFREQ 5
                  POLLFREQALERT 5
                  HOSTSYNC 15
                  DEADTIME 15
                  
                  NOTIFYMSG ONLINE   "UPS %s: On line power."
                  NOTIFYMSG ONBATT   "UPS %s: On battery."
                  NOTIFYMSG LOWBATT  "UPS %s: Battery is low."
                  NOTIFYMSG REPLBATT "UPS %s: Battery needs to be replaced."
                  NOTIFYMSG FSD      "UPS %s: Forced shutdown in progress."
                  NOTIFYMSG SHUTDOWN "Auto logout and shutdown proceeding."
                  NOTIFYMSG COMMOK   "UPS %s: Communications (re-)established."
                  NOTIFYMSG COMMBAD  "UPS %s: Communications lost."
                  NOTIFYMSG NOCOMM   "UPS %s: Not available."
                  NOTIFYMSG NOPARENT "upsmon parent dead, shutdown impossible."
                  
                  NOTIFYFLAG ONBATT   SYSLOG+WALL+EXEC
                  NOTIFYFLAG ONLINE   SYSLOG+WALL+EXEC
                  NOTIFYFLAG LOWBATT  SYSLOG+WALL+EXEC
                  NOTIFYFLAG COMMBAD  SYSLOG+WALL+EXEC
                  NOTIFYFLAG COMMOK   SYSLOG+WALL+EXEC
                  NOTIFYFLAG NOCOMM   SYSLOG+WALL+EXEC
                  NOTIFYFLAG FSD      SYSLOG+WALL+EXEC
                  NOTIFYFLAG SHUTDOWN SYSLOG+WALL+EXEC
                  NOTIFYFLAG REPLBATT SYSLOG+WALL
                  NOTIFYFLAG NOPARENT SYSLOG+WALL
                  
                  RBWARNTIME 43200
                  NOCOMMWARNTIME 300
                  FINALDELAY 5
                  

                  upssched.conf (via filer package)

                  CMDSCRIPT /usr/local/bin/upssched-cmd
                  PIPEFN /var/db/nut/upssched.pipe
                  LOCKFN /var/db/nut/upssched.lock
                  
                  AT ONBATT  * START-TIMER onbatt 300
                  AT ONLINE  * CANCEL-TIMER onbatt online
                  AT LOWBATT * EXECUTE lowbatt
                  AT COMMBAD  * START-TIMER commbad 30
                  AT COMMOK  * CANCEL-TIMER commbad commok
                  AT NOCOMM * EXECUTE commbad
                  AT FSD * EXECUTE powerdown
                  AT SHUTDOWN * EXECUTE powerdown
                  

                  upssched-cmd

                  #! /bin/sh
                  
                  UPS="ups"
                  STATUS=$( upsc $UPS ups.status )
                  CHARGE=$( upsc $UPS battery.charge )
                  CHMSG="[$STATUS]:$CHARGE%"
                  
                  # upssched-cmd  --slave --
                  logger -i -t upssched-cmd Calling upssched-cmd $1
                  
                  case $1 in
                      online) 
                      MSG="$UPS, $CHMSG - power supply has been restored."
                      ;;
                      onbatt)
                      MSG="$UPS, $CHMSG - power failure - save your work!"
                      ;;
                      lowbatt) 
                      MSG="$UPS, $CHMSG - shutdown now!"
                      ;;
                      *) 
                      logger -i -t upssched-cmd "Bad arg: \"$1\", $CHMSG"
                      exit 1
                      ;;
                  esac
                  logger -i -t upssched-cmd $MSG
                  

                  log file is showing

                  Nov 8 10:08:49 	upssched 	44022 	exec_cmd(/usr/local/bin/upssched-cmd online) returned 127
                  Nov 8 10:08:49 	upssched-cmd 	44598 	UPS - power supply had been restored.
                  Nov 8 10:08:49 	upssched-cmd 	44492 	Calling upssched-cmd online
                  Nov 8 10:08:49 	upsmon 	61766 	UPS ups@nas.net.lan: On line power.
                  Nov 8 10:08:44 	upssched 	22770 	exec_cmd(/usr/local/bin/upssched-cmd onbatt) returned 127
                  Nov 8 10:08:44 	upssched-cmd 	23262 	UPS - power failure - save your work!
                  Nov 8 10:08:44 	upssched-cmd 	23007 	Calling upssched-cmd onbatt
                  Nov 8 10:08:44 	upsmon 	61766 	UPS ups@nas.net.lan: On battery. 
                  

                  what is the
                  "upssched 44022 exec_cmd(/usr/local/bin/upssched-cmd online) returned 127"

                  1 Reply Last reply Reply Quote 0
                  • stephenw10S
                    stephenw10 Netgate Administrator
                    last edited by stephenw10

                    That return code is usually telling you 'command not found' or similar.

                    Did you try running those from the command line?

                    The timer names seem to be defined in upper case but referenced as lower case.

                    Steve

                    4 1 Reply Last reply Reply Quote 0
                    • 4
                      4o4rh @stephenw10
                      last edited by

                      @stephenw10 script doesn't do anything.

                      when running /usr/local/bin/upssched-cmd online, the prompt doesn't return and you have to ctl-c to break it.

                      1 Reply Last reply Reply Quote 0
                      • stephenw10S
                        stephenw10 Netgate Administrator
                        last edited by

                        It doesn't even write anything to the logs?

                        4 1 Reply Last reply Reply Quote 0
                        • 4
                          4o4rh @stephenw10
                          last edited by 4o4rh

                          @stephenw10 here is what shows in the log

                          upssched 22770 exec_cmd(/usr/local/bin/upssched-cmd onbatt) returned 127
                          upssched-cmd 23262 UPS - power failure - save your work!
                          upssched-cmd 23007 Calling upssched-cmd onbatt
                          upsmon 61766 UPS ups@nas.net.lan: On battery.

                          after further searching, i found that some of the lines were missing the open bracket, but the bigger issue is, this is a bash script (which is not installed). I have no idea how to convert it to sh

                          #!/usr/local/bin/bash -u
                          logger -i -t upssched-cmd Calling upssched-cmd $1
                          
                          UPS="eapeups"
                          STATUS=$( upsc $UPS ups.status )
                          CHARGE=$( upsc $UPS battery.charge )
                          CHMSG="[$STATUS]:$CHARGE%"
                          
                          case $1 in
                              (online)  MSG="$UPS, $CHMSG - power supply has been restored." ;;
                              (onbatt)  MSG="$UPS, $CHMSG - power failure - save your work!" ;;
                              (lowbatt) MSG="$UPS, $CHMSG - shutdown now!" ;;
                          (*) logger -i -t upssched-cmd "Bad arg: \"$1\", $CHMSG"
                              exit 1 ;;
                          esac
                          logger -i -t upssched-cmd $MSG
                          
                          GertjanG 1 Reply Last reply Reply Quote 0
                          • stephenw10S
                            stephenw10 Netgate Administrator
                            last edited by

                            You can install bash if you really need to.
                            What part fails id you use sh?

                            Steve

                            1 Reply Last reply Reply Quote 0
                            • GertjanG
                              Gertjan @4o4rh
                              last edited by

                              @gwaitsi said in UPSMON independent shutdown.:

                              but the bigger issue is, this is a bash script

                              Although bash is probably a more powerful shell, I guess the script's syntax could be re written in sh syntax.

                              No "help me" PM's please. Use the forum, the community will thank you.
                              Edit : and where are the logs ??

                              4 1 Reply Last reply Reply Quote 0
                              • 4
                                4o4rh @Gertjan
                                last edited by

                                @Gertjan is that something you could help with pls? i would have no clue as i am not familiar with either

                                1 Reply Last reply Reply Quote 0
                                • GertjanG
                                  Gertjan
                                  last edited by

                                  First things first : extreme, but you won't regret it : do not use the build in GUI file editor.
                                  Use a console or better : ssh access. You'll be having full control, you can see file permissions, attributes etc.

                                  The GUI file editor is only used by experts ... and they probably use when they want to fly blind.

                                  @gwaitsi said in UPSMON independent shutdown.:

                                  but the bigger issue is, this is a bash script (which is not installed)

                                  I'm experimenting right now with this upssched-cmd ....
                                  See here https://dan.langille.org/2020/09/07/monitoring-your-ups-using-nut-on-freebsd/ for guidelines and the entire https://networkupstools.org/ .....

                                  Be careful : you've seen that pfSense (re) creates /usr/local/etc/nut/upsmon.conf and other .conf files in that dircetory. Use the GUI NUT pages to add your own lines to these files.

                                  No "help me" PM's please. Use the forum, the community will thank you.
                                  Edit : and where are the logs ??

                                  4 1 Reply Last reply Reply Quote 0
                                  • 4
                                    4o4rh @Gertjan
                                    last edited by

                                    @Gertjan hi, I created my files a linux text editor. I copied and pasted them into the filer package.

                                    /usr/local/etc/nut/upssched.conf 	0644 	UPS Shutdown Scheduler Configuration 	
                                    	 
                                    /usr/local/bin/upssched-cmd 	0755 	UPS Shutdown Scheduler Command Script
                                    

                                    The extra upsmon script commands were added to the advanced tab.
                                    the log clearly shows the script is being triggered, but just i don't know what i am doing with the scripts to be able to convert it.

                                    GertjanG 1 Reply Last reply Reply Quote 0
                                    • GertjanG
                                      Gertjan @4o4rh
                                      last edited by

                                      @gwaitsi said in UPSMON independent shutdown.:

                                      hi, I created my files a linux text editor

                                      Again : use ssh directly, you'll feel @home right away.

                                      I advise you to execute this on pfSEnse :

                                      pkg install nano
                                      

                                      I guess you know who 'nano' is ;)

                                      I don't know what you mean with

                                      /usr/local/etc/nut/upssched.conf 	0644 	UPS Shutdown Scheduler Configuration 	
                                      	 
                                      /usr/local/bin/upssched-cmd 	0755 	UPS Shutdown Scheduler Command Script
                                      

                                      Btw : I have a Back-UPS 700 APC ups, hooked up using a USB cable.

                                      These are my settings :

                                      2ba8b960-d21b-43e2-9b1f-9587d85d8a98-image.png

                                      upsmon.conf : the strict minimum, as the other settings in upsmon.conf will be set to default. see upsmon.conf.example for the values.

                                      The upsd.conf contains the LAN IPv4 and IPv6, as my pfSense NUT us a UPS master - I have a disk station NAS being the NUT slave.

                                      The upsd.users section shows the login details of the NAS.

                                      My /usr/local/etc/nut/upssched.conf file :

                                      -r-xr-xr-x   1 root  wheel    649 Nov 12 15:36 upssched-cmd
                                      
                                      CMDSCRIPT /usr/local/etc/nut/upssched-cmd
                                      PIPEFN /var/db/nut/upssched.pipe
                                      LOCKFN /var/db/nut/upssched.lock
                                      
                                      AT ONBATT  * START-TIMER onbatt 20
                                      AT ONLINE  * CANCEL-TIMER onbatt online
                                      AT LOWBATT * EXECUTE lowbatt
                                      AT COMMBAD  * START-TIMER commbad 30
                                      AT COMMOK  * CANCEL-TIMER commbad commok
                                      AT NOCOMM * EXECUTE commbad
                                      AT FSD * EXECUTE powerdown
                                      AT SHUTDOWN * EXECUTE powerdown
                                      

                                      Take note of the location of the "CMDSCRIPT " file : /usr/local/etc/nut/upssched-cmd file

                                      See also : "onbatt 20" which means that I receive notifications by mail etc after "20 sec" - not the default 300 seconds.

                                      Here is /usr/local/etc/nut/upssched-cmd file :

                                      #! /bin/sh
                                      
                                      UPS="ups"
                                      STATUS=$( upsc $UPS ups.status )
                                      CHARGE=$( upsc $UPS battery.charge )
                                      CHMSG="[$STATUS]:$CHARGE%"
                                      
                                      # upssched-cmd  --slave --
                                      logger -i -t upssched-cmd Calling upssched-cmd $1
                                      
                                      case $1 in
                                          online) 
                                          MSG="$UPS, $CHMSG - power supply has been restored."
                                          ;;
                                          onbatt)
                                          MSG="$UPS, $CHMSG - power failure - save your work!"
                                          ;;
                                          lowbatt) 
                                          MSG="$UPS, $CHMSG - shutdown now!"
                                          ;;
                                      	upsgone)
                                      	MSG="$UPS, $CHMSG - UPS has been gone for awhile"
                                      	;;
                                          *) 
                                          logger -i -t upssched-cmd "Bad arg: \"$1\", $CHMSG"
                                          exit 1
                                          ;;
                                      esac
                                      logger -i -t upssched-cmd $MSG
                                      

                                      This is logged when I pull the plug :

                                      8a2f4877-c8d8-430e-bd7e-7b077eca8c8b-image.png

                                      Read from bottom to top.
                                      I received the mails.

                                      No "help me" PM's please. Use the forum, the community will thank you.
                                      Edit : and where are the logs ??

                                      4 1 Reply Last reply Reply Quote 0
                                      • 4
                                        4o4rh @Gertjan
                                        last edited by

                                        @Gertjan said in UPSMON independent shutdown.:

                                        #! /bin/sh

                                        UPS="ups"
                                        STATUS=$( upsc $UPS ups.status )
                                        CHARGE=$( upsc $UPS battery.charge )
                                        CHMSG="[$STATUS]:$CHARGE%"

                                        upssched-cmd --slave --

                                        logger -i -t upssched-cmd Calling upssched-cmd $1

                                        case $1 in
                                        online)
                                        MSG="$UPS, $CHMSG - power supply has been restored."
                                        ;;
                                        onbatt)
                                        MSG="$UPS, $CHMSG - power failure - save your work!"
                                        ;;
                                        lowbatt)
                                        MSG="$UPS, $CHMSG - shutdown now!"
                                        ;;
                                        upsgone)
                                        MSG="$UPS, $CHMSG - UPS has been gone for awhile"
                                        ;;
                                        *)
                                        logger -i -t upssched-cmd "Bad arg: "$1", $CHMSG"
                                        exit 1
                                        ;;
                                        esac
                                        logger -i -t upssched-cmd $MSG

                                        i will give it a shot.

                                        fyi - If you use nano to create upssched.conf and upssched-cmd the files will be lost if you have to re-install.

                                        If you install the "Filer" package, you can create those files under the Diagnostics menu and the contents will be saved to config.xml, so you can transfer the settings to a new install.

                                        GertjanG 1 Reply Last reply Reply Quote 0
                                        • stephenw10S
                                          stephenw10 Netgate Administrator
                                          last edited by

                                          You can also use the included Easy Editor ee which provides much the same functionality as nano.

                                          Steve

                                          1 Reply Last reply Reply Quote 0
                                          • GertjanG
                                            Gertjan @4o4rh
                                            last edited by

                                            @gwaitsi said in UPSMON independent shutdown.:

                                            If you install the "Filer" package,

                                            True ! In fact, discovered yesterday that "Filer" wasn't the build-in GUI editor ...
                                            I use the Notes package myself : for every change I made that can't be done with the GUI, thus stored for eternity, I take notes.
                                            This forces me to re read the documentation if I want to implement changes. Not only pfSense changes over time ;)

                                            @stephenw10 said in UPSMON independent shutdown.:

                                            ee

                                            I know. nano is just a personal preference, as it exists on all my pfSenses, and linux based servers. I'm trying to limit my have-to-know keyboard short-cut list to a minimum as I'm stilling suffering from the vi syndrome.

                                            No "help me" PM's please. Use the forum, the community will thank you.
                                            Edit : and where are the logs ??

                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post
                                            Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.