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.
    • 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
                    • 4
                      4o4rh
                      last edited by

                      So it is looking good so far, lost comms are from shutting down the service on truenas. forced shutdown from lost comms works.

                      Still need to test how long the battery on the dumb ups will last. It should last much longer than the apc ups which gives me about an hour for power to be restored.

                      i will have on rare occasions a use case when the power is gone for more than an hour and pfsense shuts down, but the battery doesn't die before power is restored. in such a use case, pfsense will need to be manually re-started.

                      Anyone got any ideas?

                      Nov 16 06:57:38 	upsmon 	98032 	UPS ups@nas.net.lan: Communications (re-)established.
                      Nov 16 06:57:33 	upsmon 	98032 	UPS [ups@nas.net.lan]: connect failed: Connection failure: Connection refused
                      Nov 16 06:57:28 	upsmon 	98032 	UPS [ups@nas.net.lan]: connect failed: Connection failure: Connection refused
                      Nov 16 06:57:23 	upsmon 	98032 	UPS [ups@nas.net.lan]: connect failed: Connection failure: Connection refused
                      Nov 16 06:57:18 	upsmon 	98032 	UPS [ups@nas.net.lan]: connect failed: Connection failure: Connection refused
                      Nov 16 06:57:13 	upsmon 	98032 	UPS [ups@nas.net.lan]: connect failed: Connection failure: Connection refused
                      Nov 16 06:57:08 	upsmon 	98032 	UPS ups@nas.net.lan: Communications lost.
                      Nov 16 06:57:08 	upsmon 	98032 	Poll UPS [ups@nas.net.lan] failed - Server disconnected
                      Nov 16 06:56:48 	upsmon 	98032 	UPS ups@nas.net.lan: Communications (re-)established.
                      Nov 16 06:56:43 	upsmon 	98032 	UPS ups@nas.net.lan: Communications lost.
                      Nov 16 06:56:43 	upsmon 	98032 	Poll UPS [ups@nas.net.lan] failed - Server disconnected
                      Nov 15 05:34:34 	upsmon 	98032 	UPS ups@nas.net.lan: On line power.
                      Nov 15 05:34:29 	upsmon 	98032 	UPS ups@nas.net.lan: On battery.
                      Nov 14 00:56:34 	upssched-cmd 		UPS on battery too long, forced shutdown
                      

                      final schedups-cmd

                      #! /bin/sh
                      #
                      # This script should be called by upssched via the CMDSCRIPT directive.
                      # Here is a quick example to show how to handle a bunch of possible
                      # timer names with the help of the case structure.
                      # This script may be replaced with another program without harm.
                      # The first argument passed to your CMDSCRIPT is the name of the timer
                      # from your AT lines.
                      
                      # upssched-cmd  --slave --
                      
                      case $1 in
                          onbattery)
                          	logger -t upssched-cmd "UPS on battery too long, forced shutdown"
                          	/usr/local/sbin/upsmon -c fsd
                          	;;
                          lowbattery) 
                          	logger -t upssched-cmd "UPS on battery critical, forced shutdown"
                          	/usr/local/sbin/upsmon -c fsd
                          	;;
                          commbad)
                          	logger -t upssched-cmd "UPS communications missing too long, forced shutdown"
                          	/usr/local/sbin/upsmon -c fsd
                          	;;
                          powerdown)
                          	logger -t upssched-cmd "UPS communications missing too long, forced shutdown"
                          	/usr/local/sbin/upsmon -c fsd
                          	;;
                          *) 
                          		logger -t upssched-cmd "Unrecognized command: $1"
                          		;;
                      esac
                      
                      GertjanG 1 Reply Last reply Reply Quote 1
                      • GertjanG
                        Gertjan @4o4rh
                        last edited by

                        @gwaitsi said in UPSMON independent shutdown.:

                        Anyone got any ideas?

                        What is is the question ?
                        How to manually restart ?

                        For the "AT ... timer commands", see the upssched.conf file.

                        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 the ups on the pfsense (Qotom J1900) is like a power adapter with a battery e.g. it is dumb. pfsense is triggered via truenas server which has a apc ups connected to it.

                          If the power comes back on before the pfsense powers down, all is good. it will run on battery and continue.

                          If the pfsense shutdowns, but the ups battery doesn't deplete, the J1900 will never see a loss of power and therefore wont know to turn back on, so has to be manually started.

                          Looking for ideas on how i could solve this scenario.

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

                            @gwaitsi said in UPSMON independent shutdown.:

                            J1900

                            If the J1900 supports WOL .....

                            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
                            • stephenw10S
                              stephenw10 Netgate Administrator
                              last edited by

                              Yeah, WoL is probably the only option there without some additional hardware.

                              Steve

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

                                sounds like a good idea fellas, just need to figure out how to do that now ;-)

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

                                  If your J-thing is a typical PC device, check the BIOS.
                                  WOL is nothing more a an always-on chip (activated as soon as there is some power) and simulates a press-power-on-the-button as soon as it sees it's own MAC 3 times in a packet load over the/a Ethernet interface, typically the LAN interface.

                                  If not : you found yourself yet another Rasberry/PI project ;)

                                  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
                                  • 4
                                    4o4rh
                                    last edited by

                                    does anyone know how to set a netgear switch (GS108Tv3) up to provide the magic packet

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

                                      @gwaitsi said in UPSMON independent shutdown.:

                                      WOL for GS108Tv3

                                      => They should know it : https://community.netgear.com/t5/Smart-Plus-and-Smart-Pro-Managed/GS108Tv3-how-to-wake-up-pfsense-router/m-p/2007829
                                      If you need a fast answer : look in the Netgear's GUI or go for the manual.

                                      Bad start : Google doesn't know about it, so chances are great the router doesn't have WOL capabilities.

                                      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 couldn't find anything in the gui. there is a section on green ethernet, but it is not clear to me whether that causes broadcast magic packets. (i thought the specific mac address had to be used)

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

                                          You can WOL with pfSense.
                                          pfSense, as your switch, should be 'always' on.

                                          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 4o4rh

                                            @Gertjan what do i have to do on the pfsense side, as the wake on lan under services is for sending the magic packet. are you saying just need to set the bios and then it should be good

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