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

NUT package (2.8.0 and below)

Scheduled Pinned Locked Moved UPS Tools
1.2k Posts 128 Posters 4.3m 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.
  • N
    n3by
    last edited by Dec 23, 2016, 10:15 AM Dec 23, 2016, 10:03 AM

    Thank you for analysis.

    1 - Unfortunately at this moment it is not possible; this year I bayed this UPS and can't return it any more, it have 2 years warranty but I am sure seller/manufacturer will not fix this problem. To buy another one here in Poland will be a game of chance as seller & manufacturer don't publish full spec. On log term plan I am thinking it will be better to buy an inverter.
    2 - No.
    3 - I can replace the driver only if you can post the driver patched as I don't have a working FreeBSD 10.3 development environment to do the build.
    4 - Not possible for the moment the other computers around are win that are scheduled to turn off overnight and also I don't have a monitor program for win.
    5 - Yes, for the moment I just returned to scheduled cron script that restart NUT every 15 min… any help is appreciated.

    thank you

    p.s.
    w0w unfortunately your suggestion don't work:
    usbconfig -d 5.2 set_config 255 - it kill the communication but;
    usbconfig -d 5.2 set_config 0  - can't restore the communication, not even NUT restart will fix it and I have to unplug the USB cable to fix the communication.

    ugen5.2: <usb to="" serial="" inno="" tech="">at usbus5, cfg=255 md=HOST spd=LOW (1.5Mbps) pwr=ON (100mA)

    bLength = 0x0012
      bDescriptorType = 0x0001
      bcdUSB = 0x0110
      bDeviceClass = 0x0000  <probed by="" interface="" class="">bDeviceSubClass = 0x0000
      bDeviceProtocol = 0x0000
      bMaxPacketSize0 = 0x0008
      idVendor = 0x0665
      idProduct = 0x5161
      bcdDevice = 0x0002
      iManufacturer = 0x0001  <retrieving string="" failed="">iProduct = 0x0002  <retrieving string="" failed="">iSerialNumber = 0x0000  <no string="">bNumConfigurations = 0x0001</no></retrieving></retrieving></probed></usb>

    1 Reply Last reply Reply Quote 0
    • W
      w0w
      last edited by Dec 23, 2016, 11:59 AM

      I am sorry, my bad, instead of powering off and on your device just try to do this with root hub where is your ups is connected.
      Do
      usbconfig | grep ugen5
      You should see something like
      ugen5.1: <uhci root="" hub="" intel="">at usbus2, cfg=0 md=HOST spd=FULL (12Mbps) pwr=SAVE
      ugen5.2: <usb to="" serial="" inno="" tech="">at usbus5, cfg=255 md=HOST spd=LOW (1.5Mbps) pwr=ON (100mA)
      So try
      usbconfig -d 5.1 set_config 255
      usbconfig -d 5.1 set_config 0
      and see what happening.</usb></uhci>

      1 Reply Last reply Reply Quote 0
      • N
        n3by
        last edited by Dec 23, 2016, 12:24 PM Dec 23, 2016, 12:06 PM

        I tested:
        communication is not restored automatically after power on the USB hub, it still required to restart the NUT service.

        edit.

        Thank you.

        I like the idea to power OFF-ON the USB HUB so I added to nut_restart script:

        #!/bin/sh

        /usr/local/etc/rc.d/nut.sh stop
        usbconfig -d 5.1 set_config 255
        sleep 30
        usbconfig -d 5.1 set_config 0
        sleep 30
        /usr/local/etc/rc.d/nut.sh start

        1 Reply Last reply Reply Quote 0
        • H
          hda
          last edited by Dec 23, 2016, 1:38 PM

          @n3by:

          4 - Not possible for the moment the other computers around are win that are scheduled to turn off overnight and also I don't have a monitor program for win.

          Maybe you could utilize a RPi-Linux at 3W power ?

          1 Reply Last reply Reply Quote 0
          • N
            n3by
            last edited by Dec 23, 2016, 1:54 PM

            Sorry I have no RPI here in Poland… and to buy now rpi3+memory+case+power here is ~90 $...

            1 Reply Last reply Reply Quote 0
            • W
              w0w
              last edited by Dec 23, 2016, 7:48 PM Dec 23, 2016, 6:32 PM

              Instead restarting NUT in sheduled fashion, just use script below to check if upsc fails to connect ups and then restart everything you want.
              When UPS driver connection is lost, run
              upsc -l
              It gives you your configured UPS name, run
              upsc "upsname" 
              without quotes

              remember the output, you will need it below in pattern variable. Just put it in quotes like it is.
              for example if upsc myhomeups gives you output
              connection unavailable
              then change script line to

              pattern="connection unavailable"

              #!/bin/sh
              # Script to restart NUT and USB UPS if UPS connection failed
              upsname=$(upsc -l)
              pattern="failed UPS message from upsc"
              check=$(upsc $upsname | grep -o "$pattern")
              if [ "$check" = "$pattern" ] ;
              then
              /usr/local/etc/rc.d/nut.sh stop
              usbconfig -d 5.1 set_config 255
              sleep 30
              usbconfig -d 5.1 set_config 0
              sleep 30
              /usr/local/etc/rc.d/nut.sh start
              fi
              

              You can use cron to schedule script for every 3 minutes for example, or even less if you tune down your sleep timers.

              1 Reply Last reply Reply Quote 0
              • N
                n3by
                last edited by Dec 23, 2016, 8:14 PM Dec 23, 2016, 7:50 PM

                This is what I did:

                because this is normal output if communication with UPS is working OK:

                upsc ActiveJet

                battery.charge: 100
                battery.charge.low: 50
                battery.runtime: 714
                battery.runtime.low: 600
                battery.voltage: 13.70
                battery.voltage.high: 13.7
                battery.voltage.low: 12
                device.type: ups
                driver.flag.norating: enabled
                driver.flag.novendor: enabled
                driver.name: blazer_usb
                driver.parameter.pollinterval: 10
                driver.parameter.port: auto
                driver.parameter.protocol: mustek
                driver.parameter.runtimecal: 180,100,320,50
                driver.parameter.synchronous: no
                driver.version: 2.7.4
                driver.version.internal: 0.12
                input.frequency: 50.0
                input.voltage: 241.2
                input.voltage.fault: 241.2
                output.voltage: 241.2
                ups.beeper.status: enabled
                ups.delay.shutdown: 30
                ups.delay.start: 180
                ups.load: 19
                ups.productid: 5161
                ups.status: OL
                ups.type: offline / line interactive
                ups.vendorid: 0665
                

                I changed your script to this one:

                #!/bin/sh

                Script to restart NUT and USB UPS if UPS connection failed on ActiveJet

                upsname="ActiveJet"
                pattern="battery.charge:"
                check=$(upsc $upsname | grep -o "$pattern")
                if [ "$check" != "$pattern" ]; then
                /usr/local/etc/rc.d/nut.sh stop

                usbconfig -d 5.1 set_config 255

                sleep 10

                usbconfig -d 5.1 set_config 0

                sleep 5
                /usr/local/etc/rc.d/nut.sh start
                fi

                and I added to cron to run it every 3 min.

                If you have a better suggestion please share.

                Thank you again !

                edit:
                changed the script and cron from 2 to 3 and now to 4 min because something is not ok and it restart to often.

                1 Reply Last reply Reply Quote 0
                • N
                  n3by
                  last edited by Dec 23, 2016, 8:55 PM

                  strange …  If I did not made a mistake I think the script interfere with normal NUT because it will restart almost every time.
                  Maybe we can look in syslog for last NUT error messages and not try to interrogate NUT ??

                  Dec 23 21:40:08 	upsd 	59705 	User monuser@127.0.0.1 logged into UPS [ActiveJet]
                  Dec 23 21:40:06 	upsd 	59705 	Startup successful
                  Dec 23 21:40:06 	upsd 	59382 	Connected to UPS [ActiveJet]: blazer_usb-ActiveJet
                  Dec 23 21:40:06 	upsd 	59382 	listening on 127.0.0.1 port 3493
                  Dec 23 21:40:06 	upsd 	59382 	listening on ::1 port 3493
                  Dec 23 21:40:05 	blazer_usb 	59211 	Startup successful
                  Dec 23 21:40:05 	upsmon 	58620 	Startup successful
                  Dec 23 21:40:00 	blazer_usb 	86268 	Signal 15: exiting
                  Dec 23 21:40:00 	upsd 	86696 	Signal 15: exiting
                  Dec 23 21:40:00 	upsd 	86696 	mainloop: Interrupted system call
                  Dec 23 21:40:00 	upsd 	86696 	User monuser@127.0.0.1 logged out from UPS [ActiveJet]
                  Dec 23 21:40:00 	upsmon 	86014 	Signal 15: exiting
                  Dec 23 21:36:08 	upsd 	86696 	User monuser@127.0.0.1 logged into UPS [ActiveJet]
                  Dec 23 21:36:06 	upsd 	86696 	Startup successful
                  Dec 23 21:36:06 	upsd 	86543 	Connected to UPS [ActiveJet]: blazer_usb-ActiveJet
                  Dec 23 21:36:06 	upsd 	86543 	listening on 127.0.0.1 port 3493
                  Dec 23 21:36:06 	upsd 	86543 	listening on ::1 port 3493
                  Dec 23 21:36:05 	blazer_usb 	86268 	Startup successful
                  Dec 23 21:36:05 	upsmon 	85553 	Startup successful
                  Dec 23 21:36:00 	blazer_usb 	8319 	Signal 15: exiting
                  Dec 23 21:36:00 	upsd 	8660 	Signal 15: exiting
                  Dec 23 21:36:00 	upsd 	8660 	mainloop: Interrupted system call
                  Dec 23 21:36:00 	upsd 	8660 	User monuser@127.0.0.1 logged out from UPS [ActiveJet]
                  Dec 23 21:36:00 	upsmon 	7932 	Signal 15: exiting
                  Dec 23 21:32:08 	upsd 	8660 	User monuser@127.0.0.1 logged into UPS [ActiveJet]
                  Dec 23 21:32:06 	upsd 	8660 	Startup successful
                  Dec 23 21:32:06 	upsd 	8388 	Connected to UPS [ActiveJet]: blazer_usb-ActiveJet
                  Dec 23 21:32:06 	upsd 	8388 	listening on 127.0.0.1 port 3493
                  Dec 23 21:32:06 	upsd 	8388 	listening on ::1 port 3493
                  Dec 23 21:32:05 	blazer_usb 	8319 	Startup successful
                  Dec 23 21:32:05 	upsmon 	7510 	Startup successful
                  Dec 23 21:32:00 	upsd 	33016 	Signal 15: exiting
                  Dec 23 21:32:00 	upsd 	33016 	mainloop: Interrupted system call
                  Dec 23 21:32:00 	upsd 	33016 	User monuser@127.0.0.1 logged out from UPS [ActiveJet]
                  Dec 23 21:32:00 	upsmon 	32741 	Signal 15: exiting
                  ... 
                  
                  1 Reply Last reply Reply Quote 0
                  • dennypageD
                    dennypage
                    last edited by Dec 23, 2016, 10:06 PM

                    Remove any other scripts you have put in place and replace /usr/local/etc/rc.d/nut.sh with the script below. I would not add any USB configuration commands unless you encounter a situation in which the script does not restart the driver. If you do encounter such a situation, please run "usbconfig dump_device_desc" while the problem is happening and post the result.

                    Note that the nut.sh script is automatically written every time the NUT configuration is saved This will happen anytime you change the UPS config or upgrade pfSense. When this happens, just copy this script back in place.

                    I would keep the setting of "pollinterval = 10" in the ups.conf advanced section as this will significantly reduce the number of occurrences of driver failure. No other advanced settings are needed.

                    #!/bin/sh
                    # This file has been modified for special upsdrvctl restart
                    
                    rc_start() {
                    	echo starting NUT
                    	if [ -f /var/run/upsdrvctl_loop.pid ]
                    	then
                    		kill -9 `cat /var/db/nut/upsdrvctl_loop.pid`
                    		rm /var/run/upsdrvctl_loop.pid
                    	fi
                    	/usr/bin/killall -q -9 upsmon
                    	/usr/bin/killall -q -9 upsd
                    	/usr/bin/killall -q -9 upsdrvctl
                    	/usr/bin/killall -q -9 blazer_usb
                    	/usr/local/sbin/upsmon
                    	/usr/local/sbin/upsdrvctl start &
                    	(
                    		while true
                    		do
                    			sleep 15
                    			kill -0 `cat /var/db/nut/blazer_usb-ups.pid` > /dev/null 2>&1 && continue
                    			echo "needs restart"
                    			/usr/local/sbin/upsdrvctl start
                    		done
                    	) &
                    	echo $! > /var/db/nut/upsdrvctl_loop.pid
                    	sleep 1
                    	/usr/local/sbin/upsd -u root
                    	return 0
                    }
                    
                    rc_stop() {
                    	echo stopping NUT
                    	if [ -f /var/db/nut/upsdrvctl_loop.pid ]
                    	then
                    		kill -9 `cat /var/db/nut/upsdrvctl_loop.pid`
                    		rm /var/db/nut/upsdrvctl_loop.pid
                    	fi
                    	/usr/bin/killall -q upsmon
                    	/usr/bin/killall -q upsd
                    	/usr/bin/killall -q upsdrvctl
                    	/usr/bin/killall -q blazer_usb
                    	return 0
                    }
                    
                    case $1 in
                    	start)
                    		rc_start
                    		;;
                    	stop)
                    		rc_stop
                    		;;
                    	restart)
                    		rc_stop
                    		rc_start
                    		;;
                    esac
                    
                    
                    1 Reply Last reply Reply Quote 0
                    • dennypageD
                      dennypage
                      last edited by Dec 23, 2016, 10:18 PM

                      Regarding the other settings you were doing:

                      
                      default.battery.voltage.high = 13.7
                      default.battery.voltage.low = 11.5
                      runtimecal = 180,100,360,50
                      ignorelb
                      override.battery.charge.low = 50
                      override.battery.runtime.low = 600
                      
                      

                      These are actually arguments to the UPS driver rather than global directives. As such, they should be in the (non-advanced) section entitled "Extra Arguments to driver" rather than in the advanced section.

                      You should have nothing in the advanced section other than the pollinterval setting in ups.conf.

                      Hope this works out for you.

                      1 Reply Last reply Reply Quote 0
                      • N
                        n3by
                        last edited by Dec 23, 2016, 10:39 PM

                        I did what you said but it looks like the script enter in a cyclic restart:

                        Dec 23 23:36:51 	upsd 	15530 	Connected to UPS [ActiveJet]: blazer_usb-ActiveJet
                        Dec 23 23:36:50 	blazer_usb 	24413 	Startup successful
                        Dec 23 23:36:48 	php-cgi 		nut_email.php: Message sent to xxxxxxxxxxx OK
                        Dec 23 23:36:47 	upsmon 	14675 	Communications with UPS ActiveJet lost
                        Dec 23 23:36:47 	upsmon 	14675 	Poll UPS [ActiveJet] failed - Driver not connected
                        Dec 23 23:36:44 	blazer_usb 	55222 	Signal 15: exiting
                        Dec 23 23:36:33 	php-cgi 		nut_email.php: Message sent to xxxxxxxxxxx OK
                        Dec 23 23:36:32 	upsmon 	14675 	Communications with UPS ActiveJet established
                        Dec 23 23:36:29 	upsd 	15530 	Connected to UPS [ActiveJet]: blazer_usb-ActiveJet
                        Dec 23 23:36:29 	blazer_usb 	55222 	Startup successful
                        Dec 23 23:36:27 	php-cgi 		nut_email.php: Message sent to xxxxxxxxxxx OK
                        Dec 23 23:36:27 	upsmon 	14675 	Communications with UPS ActiveJet lost
                        Dec 23 23:36:27 	upsmon 	14675 	Poll UPS [ActiveJet] failed - Driver not connected
                        Dec 23 23:36:22 	blazer_usb 	27723 	Signal 15: exiting
                        Dec 23 23:36:12 	php-cgi 		nut_email.php: Message sent to xxxxxxxxxxx OK
                        Dec 23 23:36:12 	upsmon 	14675 	Communications with UPS ActiveJet established
                        Dec 23 23:36:09 	upsd 	15530 	Connected to UPS [ActiveJet]: blazer_usb-ActiveJet
                        Dec 23 23:36:07 	blazer_usb 	27723 	Startup successful
                        Dec 23 23:36:07 	upsmon 	14675 	Poll UPS [ActiveJet] failed - Driver not connected
                        Dec 23 23:36:03 	php-cgi 		nut_email.php: Message sent to xxxxxxxxxxx OK
                        Dec 23 23:36:02 	upsmon 	14675 	Communications with UPS ActiveJet lost
                        Dec 23 23:36:02 	upsmon 	14675 	Poll UPS [ActiveJet] failed - Driver not connected
                        Dec 23 23:36:00 	blazer_usb 	90201 	Signal 15: exiting
                        Dec 23 23:35:47 	php-cgi 		nut_email.php: Message sent to xxxxxxxxxxx OK
                        Dec 23 23:35:47 	upsmon 	14675 	Communications with UPS ActiveJet established
                        Dec 23 23:35:46 	upsd 	15530 	Connected to UPS [ActiveJet]: blazer_usb-ActiveJet
                        Dec 23 23:35:45 	blazer_usb 	90201 	Startup successful
                        Dec 23 23:35:43 	php-cgi 		nut_email.php: Message sent to xxxxxxxxxxx OK
                        Dec 23 23:35:42 	upsmon 	14675 	Communications with UPS ActiveJet lost
                        Dec 23 23:35:42 	upsmon 	14675 	Poll UPS [ActiveJet] failed - Driver not connected
                        Dec 23 23:35:39 	blazer_usb 	15841 	Signal 15: exiting
                        Dec 23 23:35:27 	upsd 	15530 	User monuser@127.0.0.1 logged into UPS [ActiveJet]
                        Dec 23 23:35:27 	upsd 	15530 	Connected to UPS [ActiveJet]: blazer_usb-ActiveJet
                        Dec 23 23:35:25 	blazer_usb 	15841 	Startup successful
                        Dec 23 23:35:25 	upsd 	15530 	Startup successful
                        Dec 23 23:35:25 	upsd 	15312 	Can't connect to UPS [ActiveJet] (blazer_usb-ActiveJet): No such file or directory
                        Dec 23 23:35:25 	upsd 	15312 	listening on 127.0.0.1 port 3493
                        Dec 23 23:35:25 	upsd 	15312 	listening on ::1 port 3493
                        Dec 23 23:35:24 	upsmon 	14123 	Startup successful 
                        
                        1 Reply Last reply Reply Quote 0
                        • dennypageD
                          dennypage
                          last edited by Dec 23, 2016, 11:11 PM

                          That looks like kill is missing the -0.

                          Just to confirm the script is correct, could you run a sum on it please?

                          sum /usr/local/etc/rc.d/nut.sh

                          The result should be 60215.

                          1 Reply Last reply Reply Quote 0
                          • N
                            n3by
                            last edited by Dec 23, 2016, 11:14 PM

                            yes it is correct. ( I copied also to nut.sh.new in case it is recreated )

                            60215 2 /usr/local/etc/rc.d/nut.sh.new
                            
                            1 Reply Last reply Reply Quote 0
                            • dennypageD
                              dennypage
                              last edited by Dec 23, 2016, 11:57 PM

                              Apologies. There was a typo in the pidfile name left over from my testing (based on usbhid-ups rather than blazer_usb).

                              Updated version follows.

                              #!/bin/sh
                              # This file has been modified for special upsdrvctl restart
                              
                              rc_start() {
                              	echo starting NUT
                              	if [ -f /var/run/upsdrvctl_loop.pid ]
                              	then
                              		kill -9 `cat /var/db/nut/upsdrvctl_loop.pid`
                              		rm /var/run/upsdrvctl_loop.pid
                              	fi
                              	/usr/bin/killall -q -9 upsmon
                              	/usr/bin/killall -q -9 upsd
                              	/usr/bin/killall -q -9 upsdrvctl
                              	/usr/bin/killall -q -9 blazer_usb
                              	/usr/local/sbin/upsmon
                              	/usr/local/sbin/upsdrvctl start &
                              	(
                              		while true
                              		do
                              			sleep 15
                              			kill -0 `cat /var/db/nut/blazer_usb.pid` > /dev/null 2>&1 && continue
                              			/usr/local/sbin/upsdrvctl start
                              		done
                              	) &
                              	echo $! > /var/db/nut/upsdrvctl_loop.pid
                              	sleep 1
                              	/usr/local/sbin/upsd -u root
                              	return 0
                              }
                              
                              rc_stop() {
                              	echo stopping NUT
                              	if [ -f /var/db/nut/upsdrvctl_loop.pid ]
                              	then
                              		kill -9 `cat /var/db/nut/upsdrvctl_loop.pid`
                              		rm /var/db/nut/upsdrvctl_loop.pid
                              	fi
                              	/usr/bin/killall -q upsmon
                              	/usr/bin/killall -q upsd
                              	/usr/bin/killall -q upsdrvctl
                              	/usr/bin/killall -q blazer_usb
                              	return 0
                              }
                              
                              case $1 in
                              	start)
                              		rc_start
                              		;;
                              	stop)
                              		rc_stop
                              		;;
                              	restart)
                              		rc_stop
                              		rc_start
                              		;;
                              esac
                              
                              
                              1 Reply Last reply Reply Quote 0
                              • W
                                w0w
                                last edited by Dec 24, 2016, 5:12 AM Dec 24, 2016, 5:07 AM

                                @n3by:

                                strange …  If I did not made a mistake I think the script interfere with normal NUT because it will restart almost every time.

                                #!/bin/sh
                                # Script to restart NUT and USB UPS if UPS connection failed
                                upsname=$(upsc -l)
                                pattern="battery.charge:"
                                check=$(upsc $upsname | grep -o "$pattern")
                                if [ "$check" != "$pattern" ]; then
                                echo "("$check" != "$pattern"), NUT must be restarted"
                                else
                                echo ""$pattern" found, NUT is running and OK"
                                fi
                                
                                

                                For me even if I change upsname=$(upsc -l) directly to ups name it works just fine and NEVER gives me message "NUT must be restarted". If your UPS does not answer to every query, then it is the root cause of the script behavior. You should manually test script, running this several times, looking for the answer.

                                1 Reply Last reply Reply Quote 0
                                • N
                                  n3by
                                  last edited by Dec 24, 2016, 6:57 AM Dec 24, 2016, 6:41 AM

                                  @dennypage:

                                  Apologies. There was a typo in the pidfile name left over from my testing (based on usbhid-ups rather than blazer_usb).

                                  Updated version follows.
                                  ….....

                                  9960 2 /usr/local/etc/rc.d/nut.sh
                                  

                                  New update it have the same behavior… restarting.

                                  Dec 24 07:37:26 	blazer_usb 	32252 	Signal 15: exiting
                                  Dec 24 07:37:26 	upsd 	26542 	Signal 15: exiting
                                  Dec 24 07:37:26 	upsd 	26542 	mainloop: Interrupted system call
                                  Dec 24 07:37:26 	upsd 	26542 	User monuser@127.0.0.1 logged out from UPS [ActiveJet]
                                  Dec 24 07:37:26 	upsmon 	25058 	Signal 15: exiting
                                  Dec 24 07:37:20 	php-cgi 		nut_email.php: Message sent to xxxxxxxxxxxxxx OK
                                  Dec 24 07:37:20 	upsmon 	25058 	Communications with UPS ActiveJet established
                                  Dec 24 07:37:17 	upsd 	26542 	Connected to UPS [ActiveJet]: blazer_usb-ActiveJet
                                  Dec 24 07:37:15 	blazer_usb 	32252 	Startup successful
                                  Dec 24 07:37:15 	upsmon 	25058 	Poll UPS [ActiveJet] failed - Driver not connected
                                  Dec 24 07:37:10 	php-cgi 		nut_email.php: Message sent to xxxxxxxxxxxxxx OK
                                  Dec 24 07:37:10 	upsmon 	25058 	Communications with UPS ActiveJet lost
                                  Dec 24 07:37:10 	upsmon 	25058 	Poll UPS [ActiveJet] failed - Driver not connected
                                  Dec 24 07:37:08 	blazer_usb 	60207 	Signal 15: exiting
                                  Dec 24 07:37:00 	php-cgi 		nut_email.php: Message sent to xxxxxxxxxxxxxx OK
                                  Dec 24 07:37:00 	upsmon 	25058 	Communications with UPS ActiveJet established
                                  Dec 24 07:36:55 	upsd 	26542 	Connected to UPS [ActiveJet]: blazer_usb-ActiveJet
                                  Dec 24 07:36:55 	upsmon 	25058 	Poll UPS [ActiveJet] failed - Driver not connected
                                  Dec 24 07:36:53 	blazer_usb 	60207 	Startup successful
                                  Dec 24 07:36:50 	php-cgi 		nut_email.php: Message sent to xxxxxxxxxxxxxx OK
                                  Dec 24 07:36:50 	upsmon 	25058 	Communications with UPS ActiveJet lost
                                  Dec 24 07:36:50 	upsmon 	25058 	Poll UPS [ActiveJet] failed - Driver not connected
                                  Dec 24 07:36:47 	blazer_usb 	26864 	Signal 15: exiting
                                  Dec 24 07:36:35 	upsd 	26542 	User monuser@127.0.0.1 logged into UPS [ActiveJet]
                                  Dec 24 07:36:35 	upsd 	26542 	Connected to UPS [ActiveJet]: blazer_usb-ActiveJet
                                  Dec 24 07:36:33 	blazer_usb 	26864 	Startup successful
                                  Dec 24 07:36:33 	upsd 	26542 	Startup successful
                                  Dec 24 07:36:33 	upsd 	26332 	Can't connect to UPS [ActiveJet] (blazer_usb-ActiveJet): No such file or directory
                                  Dec 24 07:36:33 	upsd 	26332 	listening on 127.0.0.1 port 3493
                                  Dec 24 07:36:33 	upsd 	26332 	listening on ::1 port 3493
                                  Dec 24 07:36:32 	upsmon 	24793 	Startup successful 
                                  

                                  edit:

                                  only pid I have in /var/db/nut:
                                  blazer_usb-ActiveJet.pid
                                  upsmon.pid
                                  upsd.pid

                                  I try to use script with blazer_usb-ActiveJet.pid

                                  edit2:

                                  now it looks ok, will see in time how is doing.
                                  thank you.

                                  1 Reply Last reply Reply Quote 0
                                  • dennypageD
                                    dennypage
                                    last edited by Dec 24, 2016, 7:10 AM

                                    Did you stop the service before putting the new script in place? If not, the old script may still be running.

                                    The command to stop the script is:

                                    /usr/local/etc/rc.d/nut.sh stop

                                    After doing so, the following commands should find no processes:
                                      ps -axuw | grep ups
                                      ps -axuw | grep nut
                                      ps -axuw | grep blazer

                                    If that isn't the issue, please run the debug version below by hand. The command to do this is:

                                    /usr/local/etc/rc.d/nut.sh start

                                    Make sure the service is stopped before you start the debug script. Also understand that it will continue to product output even after the command prompt returns. To stop it, you again would execute:

                                    /usr/local/etc/rc.d/nut.sh stop

                                    Please let it run for a minute or two and post the output from the terminal. I'll have a look at it in the morning.

                                    #!/bin/sh
                                    # This file has been modified for special upsdrvctl restart
                                    
                                    rc_start() {
                                    	echo starting NUT
                                    	if [ -f /var/run/upsdrvctl_loop.pid ]
                                    	then
                                    		kill -9 `cat /var/db/nut/upsdrvctl_loop.pid`
                                    		rm /var/run/upsdrvctl_loop.pid
                                    	fi
                                    	/usr/bin/killall -q -9 upsmon
                                    	/usr/bin/killall -q -9 upsd
                                    	/usr/bin/killall -q -9 upsdrvctl
                                    	/usr/bin/killall -q -9 blazer_usb
                                    	/usr/local/sbin/upsmon
                                    	/usr/local/sbin/upsdrvctl start &
                                    	(
                                    		while true
                                    		do
                                    			sleep 15
                                    			echo "contents of /var/db/nut:"
                                    			ls -l /var/db/nut
                                    			echo "running pid of blazer_usb is" `cat /var/db/nut/blazer_usb.pid`
                                    			ps -fp `cat /var/db/nut/blazer_usb.pid`
                                    			kill -0 `cat /var/db/nut/blazer_usb.pid` && continue
                                    			echo "blazer_usb no longer running... restarting"
                                    			/usr/local/sbin/upsdrvctl start
                                    		done
                                    	) &
                                    	echo $! > /var/db/nut/upsdrvctl_loop.pid
                                    	sleep 1
                                    	/usr/local/sbin/upsd -u root
                                    	return 0
                                    }
                                    
                                    rc_stop() {
                                    	echo stopping NUT
                                    	if [ -f /var/db/nut/upsdrvctl_loop.pid ]
                                    	then
                                    		kill -9 `cat /var/db/nut/upsdrvctl_loop.pid`
                                    		rm /var/db/nut/upsdrvctl_loop.pid
                                    	fi
                                    	/usr/bin/killall -q upsmon
                                    	/usr/bin/killall -q upsd
                                    	/usr/bin/killall -q upsdrvctl
                                    	/usr/bin/killall -q blazer_usb
                                    	return 0
                                    }
                                    
                                    case $1 in
                                    	start)
                                    		rc_start
                                    		;;
                                    	stop)
                                    		rc_stop
                                    		;;
                                    	restart)
                                    		rc_stop
                                    		rc_start
                                    		;;
                                    esac
                                    
                                    
                                    1 Reply Last reply Reply Quote 0
                                    • N
                                      n3by
                                      last edited by Dec 24, 2016, 5:29 PM

                                      dennypage just to let you know that your script is working great until now, and I made your changes in nut.inc so it will survive a reboot or UPS parameter changes till package upgrade/reinstall.

                                      In case anybody else will need it; just make the appropriate changes for you in the line with "blazer_usb-ActiveJet.pid";
                                      you can find your "driver_usb-upsname.pid" in /var/db/nut/ when NUT is running…

                                      credit go to dennypage !

                                      part with changes I made in:
                                      /usr/local/pkg/nut/nut.inc

                                      function nut_write_rcfile($driver) {
                                      	nut_check_var_db();
                                      	$start .= "echo starting NUT";
                                      	$start .= "\n	if [ -f /var/run/upsdrvctl_loop.pid ]";
                                      	$start .= "\n	then";
                                      	$start .= "\n		kill -9 `cat /var/db/nut/upsdrvctl_loop.pid`";
                                      	$start .= "\n		rm /var/run/upsdrvctl_loop.pid";
                                      	$start .= "\n	fi";
                                      	$start .= "\n	/usr/bin/killall -q -9 upsmon";
                                      	$start .= "\n	/usr/bin/killall -q -9 upsd";
                                      	$start .= "\n	/usr/bin/killall -q -9 upsdrvctl";
                                      	if (isset($driver)) {
                                      		$start .= "\n	/usr/bin/killall -q -9 $driver";
                                      	}
                                      
                                      	/* Service status keys off upsmon, so start it first. */
                                      	$start .= "\n	/usr/local/sbin/upsmon";
                                      	if (isset($driver)) {
                                      		$start .= "\n	/usr/local/sbin/upsdrvctl start &";
                                      		$start .= "\n	(";
                                      		$start .= "\n		while true";
                                      		$start .= "\n		do";
                                      		$start .= "\n			sleep 15";
                                      		$start .= "\n			kill -0 `cat /var/db/nut/blazer_usb-ActiveJet.pid` > /dev/null 2>&1 && continue";
                                      		$start .= "\n			/usr/local/sbin/upsdrvctl start";
                                      		$start .= "\n		done";
                                      		$start .= "\n	) &";
                                      		$start .= "\n	echo $! > /var/db/nut/upsdrvctl_loop.pid";
                                      		/* Since we are starting the driver in backgroud, give it a moment to start. */
                                      		$start .= "\n	sleep 1";
                                      		$start .= "\n	/usr/local/sbin/upsd -u root";
                                      	}
                                      	$start .= "\n	return 0";
                                      
                                      	$stop .= "echo stopping NUT";
                                      	$stop .= "\n	if [ -f /var/db/nut/upsdrvctl_loop.pid ]";
                                      	$stop .= "\n	then";
                                      	$stop .= "\n		kill -9 `cat /var/db/nut/upsdrvctl_loop.pid`";
                                      	$stop .= "\n		rm /var/db/nut/upsdrvctl_loop.pid";
                                      	$stop .= "\n	fi";
                                      	$stop .= "\n	/usr/bin/killall -q upsmon";
                                      	if (isset($driver)) {
                                      		$stop .= "\n	/usr/bin/killall -q upsd";
                                      		$stop .= "\n	/usr/bin/killall -q upsdrvctl";
                                      		$stop .= "\n	/usr/bin/killall -q $driver";
                                      	}
                                      	$stop .= "\n	return 0";
                                      
                                      	write_rcfile(array(
                                      		"file" => "nut.sh",
                                      		"start" => $start,
                                      		"stop" => $stop
                                      		)
                                      	);
                                      

                                      Thank you very much for help to all that got involved to solve this/my problem !
                                      and
                                      Merry Christmas !

                                      1 Reply Last reply Reply Quote 0
                                      • dennypageD
                                        dennypage
                                        last edited by Dec 24, 2016, 6:37 PM

                                        @n3by:

                                        In case anybody else will need it; just make the appropriate changes for you in the line with "blazer_usb-ActiveJet.pid";
                                        you can find your "driver_usb-upsname.pid" in /var/db/nut/ when NUT is running…

                                        I forgot about the ups name in the pid file. It had to be something stupid.

                                        On the system I was testing on the ups is named "ups" and the driver name is "usbhid-ups". This results in a pid file named "usbhid-ups-ups.pid". I think I'll change the name of the ups to prevent this sort of mistake in the future. :)

                                        1 Reply Last reply Reply Quote 0
                                        • E
                                          endy66
                                          last edited by Jan 7, 2017, 8:34 AM

                                          Yesterday i saw in my pfsense, that there is an update for the nut package (2.7.4_3). Is it save to hit the update button, or will the custom Settings be lost after the update?

                                          Best Regards

                                          1 Reply Last reply Reply Quote 0
                                          • First post
                                            Last post
                                          Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.
                                            This community forum collects and processes your personal information.
                                            consent.not_received