UPS shutdown



  • Hello,

    I am proud of PFsense but I need one feature which will help me and help lot of people who lives in places with power interruption problems.

    I would like that pfsense have a UPS shutdown module on low battery.

    Regards,

    LuckyBoy79



  • A package of NUT (Network UPS Tools) is almost certainly what you're after.

    Not that there is one, yet  :)



  • The issue I see is that most people arn't buying a UPS just for their pfsense box. I have a Belkin 1500VA UPS running my rack with 2 servers, couple of switches, and pfsense. Interfacing it with the UPS software would make it more ideal. However since I run the embedded version of pfsense its not as big of a deal for me.

    I know both APC and Belkin have networking versions of their software for multiple server shutdowns. Does NUT interface with those in anyway? Maybe theres a way it could receive a network broadcast from the software in some way?



  • This seems like a popular package request.  Perhaps you guys can starta  bounty?



  • I already started to test with UPSD, but there is still no GUI and I'm not too familiar with how to get it started automatically when pfsense starts… or the pfsense package system...  :'(

    I'd prefer upsd because it's the most compatible UPS software i think... there also is a bsd port that's working with pfsense (at least in my tests)

    perhaps anyone posts a bounty for scott or if noone does  ??? then I definitively need help with that one...

    so...

    Martin



  • @trendchiller:

    I already started to test with UPSD, but there is still no GUI and I'm not too familiar with how to get it started automatically when pfsense starts… or the pfsense package system...  :'(

    I'd prefer upsd because it's the most compatible UPS software i think... there also is a bsd port that's working with pfsense (at least in my tests)

    perhaps anyone posts a bounty for scott or if noone does  ??? then I definitively need help with that one...

    so...

    Martin

    UPSD doesn't seem to be the most compatible. When I looked at the freebsd ports theres 5 different version one for each type of ups (apcupsd, bkpupsd, mgeupsd, openupsd, upsd). Where NUT is just one binary that includes the files for all UPS versions. Atleast thats what I saw.

    However in terms of implementing UPSD looks to be easier as its just the daemon, config and rc file.

    NUT would allow users with linux, freebsd, windows, etc to interface together and shutdown all systems connected to the UPS as there are multiple versions.

    Also NUT has snmp which would be nice as I should be able to interface it into my existing Belkin software solution on my 2 servers.

    When I have free time I'll work on trying to get NUT to work and look at building a package. I need to get my spare box and ups setup to do this so I really don't know the timeframe.

    The nut daemon is called upsd so maybe there is some confusion there.



  • so you are right… when upsd supports more ups'ses it'll be better, since there is just one package needed... so i'll have a look at it too...  ;)

    Thanks for advice...

    Martin



  • I would certainly be in favour of using NUT.

    I am already using it on a Linux server that would should down a couple of Linux and Windows machines from the server. This would be a great addition to pfSense,



  • Disreguard this post I figured it out.

    So in

    http://ftp-mirror.internap.com/pub/FreeBSD/ports/i386/packages-6.0-release/All/

    the nut package seems to include everything but upsdrvctl which is needed to start the driver control part of nut.



  • I have made some progress on this. Again I need to get my other box setup with its own ups setup to continue.

    http://wgnrs.dynalias.com:81/pfsense/nut

    Make sure you read through the files before you run anything as this is all in the devel phase. The files needed are in place and the user and group are there.



  • I've gotten NUT up and running on pfSense. Here is the install script I am running. Everything is hardcoded and I've tested it from a clean install of pfsense in VMware with a UPS on the serial port and below is the output. The hard part of this is making a web interface that will be able to change the numerous settings required. I will work on that.

    Once I get it all working if anybody would like to make a donation for my time it would be appreciated.

    http://wgnrs.dynalias.com:81/pfsense/nut/installnut.sh

    
    installnut.sh                                 100% of 2733  B 3360 kBps
    -                                             100% of  799 kB  876 kBps
    Network UPS Tools - UPS driver controller 2.0.2
    Network UPS Tools (version 2.0.2) - APC Smart protocol driver
            Driver version 1.99.7, command table version 2.0
    Detected SMART-UPS 700 [XS9904001510] on /dev/ttyd0
    Network UPS Tools upsd 2.0.2
    Connected to UPS [sparky]: apcsmart-ttyd0
    Synchronizing....done
    OL LB
    Network UPS Tools upsmon 2.0.2
    Using power down flag file /etc/killpower
    
    UPS: sparky@10.10.1.200 (master) (power value 1)
    
    Broadcast Message from admin@pfsense.local
            (no tty) at 21:57 UTC...
    
    UPS sparky@10.10.1.200 battery is low
    
    


  • @rsw686:

    I've gotten NUT up and running on pfSense. Here is the install script I am running. Everything is hardcoded and I've tested it from a clean install of pfsense in VMware with a UPS on the serial port and below is the output. The hard part of this is making a web interface that will be able to change the numerous settings required. I will work on that.

    Once I get it all working if anybody would like to make a donation for my time it would be appreciated.

    http://wgnrs.dynalias.com:81/pfsense/nut/installnut.sh

    Awesome !!!! Thanks for working on this !



  • Okay I've run into a snag. Can one of the devs tell me how I can change the url for the package manager so I can test this out?



  • I have a working package. However it needs error handling and features to be added, which I will work on.  Heres the package edit screen. And below that the log from clicking change. You can see it stops the old and starts the service back up. Also it starts successfully on reboot.

    **I really needs one of the devs help in getting the package manager to work. If I can change the url somehow to run it off my server. I looked into it and it talks to xmlrpc.php. I can't test the install and uninstall functions and have to perform them at the command line.

    Also the global booting variable is false when the packages are being synced. Is there a way to know when the system is booting so the sync package command doesn't start the package, that way when the rc.d scripts execute it will start. Otherwise it starts, stops, then starts again.**

    Oct 21 03:50:09 	upsmon[2160]: UPS sparky@10.10.1.200 battery is low
    Oct 21 03:50:09 	upsmon[2160]: UPS sparky@10.10.1.200 battery is low
    Oct 21 03:50:09 	upsd[2157]: Client monuser@10.10.1.200 logged into UPS [sparky]
    Oct 21 03:50:09 	upsd[2157]: Connection from 10.10.1.200
    Oct 21 03:50:09 	upsmon[2159]: Startup successful
    Oct 21 03:50:09 	upsd[2157]: Startup successful
    Oct 21 03:50:07 	upsd[2156]: Connected to UPS [sparky]: apcsmart-ttyd0
    Oct 21 03:50:07 	apcsmart[2155]: Startup successful
    Oct 21 03:49:57 	php: nut: Starting service
    Oct 21 03:49:57 	php: nut: Taking control of port
    Oct 21 03:49:56 	php: nut: Releasing control of port
    Oct 21 03:49:55 	apcsmart[1970]: Signal 15: exiting
    Oct 21 03:49:55 	upsd[1972]: Signal 15: exiting
    Oct 21 03:49:55 	upsmon[1975]: Signal 15: exiting
    Oct 21 03:49:55 	php: nut: Stopping service
    


  • Wanted to add when the power fails it starts shutdown and halts the box. This is from remote syslog. I need to set the delay as right now it shutsdown immediately on powerfail.

    10-21-2006	01:17:08	Daemon.Info	10.10.1.200	Oct 21 05:18:05 upsd[622]: Signal 15: exiting
    10-21-2006	01:17:06	Auth.Notice	10.10.1.200	Oct 21 05:18:03 shutdown: halt by root:
    10-21-2006	01:17:06	Daemon.Info	10.10.1.200	Oct 21 05:18:03 upsd[622]: Host 10.10.1.200 disconnected (read failure)
    10-21-2006	01:17:01	Daemon.Notice	10.10.1.200	Oct 21 05:17:58 upsmon[625]: Auto logout and shutdown proceeding
    10-21-2006	01:17:01	Daemon.Critical	10.10.1.200	Oct 21 05:17:58 upsmon[625]: Executing automatic power-fail shutdown
    10-21-2006	01:17:01	Daemon.Info	10.10.1.200	Oct 21 05:17:58 upsd[622]: Client monuser@10.10.1.200 set FSD on UPS [sparky]
    10-21-2006	01:17:01	Daemon.Notice	10.10.1.200	Oct 21 05:17:58 upsmon[625]: UPS sparky@10.10.1.200 on battery
    


  • Left to it's own devices NUT would normally trigger a shutdown on LB (low battery).  This should be the correct process (otherwise you'll start a shutdown if the power goes out for a fraction of a second, probably not what you want).

    I'd also be interested in a client only option - for those of us already running a NUT server.



  • Thats probably what it is as the UPS I was testing with is old and has a low battery condition. I have others but there used for production boxes. The client is easy to implement as well. What I'm trying to figure out is how to change the pacakge url so I can install and uninstall the package to test everything out.



  • @rsw686:

    Okay I've run into a snag. Can one of the devs tell me how I can change the url for the package manager so I can test this out?

    "xmlrpcbaseurl" => "www.pfsense.com",
        "xmlrpcpath" => "/pfSense/xmlrpc.php",

    in /etc/inc/globals.inc

    –Bill



  • @billm:

    @rsw686:

    Okay I've run into a snag. Can one of the devs tell me how I can change the url for the package manager so I can test this out?

    "xmlrpcbaseurl" => "www.pfsense.com",
        "xmlrpcpath" => "/pfSense/xmlrpc.php",

    in /etc/inc/globals.inc

    –Bill

    Thanks I had looked in the globals.inc before but I don't have the xmlrpc.php file. I got a copy of the xmlrpc.php and will try this out.

    http://cvstrac.pfsense.com/rlog?f=www/xmlrpc/xmlrpc.php



  • I got the package installer up and running on my local server. I can install the package now and have worked on the gui interface for it. I need to implement this in the backend code. Hopefully in a week I will have it committed and you all can start testing it out.



  • Tomorrow (Friday) it should be committed. I just have to add more models to the list and check a few things.

    The interface is shown in the above post. Its plain but gets the job done. Suggestions would be appreciated. However due to the package system generating the page theres not much more I can do unless I want to build my own configuration page, which I might work on later.

    Local, local monitoring with remote access, and remote monitoring are all supported.



  • The package is committed. Let me know how it works. I've only gotten to test it on a APC Smart-UPS. If there are cable types, etc you need added let me know. I went through the list and added all the major brands, etc.



  • This is as far as I get when trying to install nut:

    Downloading package configuration file… done.
    Saving updated package information... done.
    Downloading nut and its dependencies...

    It will hang there at downloading dependencies and will never complete.



  • @yoda715:

    This is as far as I get when trying to install nut:

    Downloading package configuration file… done.
    Saving updated package information... done.
    Downloading nut and its dependencies...

    It will hang there at downloading dependencies and will never complete.

    The FreeBSD mirror containing the dependencies was up and down all morning. I thought it was back up. I will see if theres another one I can use instead.



  • I've added more cable types and made some changes to get USB UPS's working. You need to specify auto as the port if using USB. I have also built the development tree version of newhidups, which should be tested soon. If it resolves more of the issues I will commit it. If anybody is interested in testing it contact me either by private message or email. Any feedback on this package would be appreciated.



  • How do I add my ups driver to NUT ( powercom ) ?

    How to change the shutdown times?

    thanks  ;)



  • Would be nice to implement a screen showing the status of the UPS…  ;D



  • I have done a rewrite of the NUT package which cleaned up the code, and fixed permission errors. I have also added a status tab which displays the model, status, load, battery charge/voltage, input/output voltage. and temperature.

    Feedback on if the package works for you, what doesn't work, ideas for improvement would be appreciated.



  • hmmm, does not work for me…

    seems not to find my smart-ups via calbe (com1)  :'(

    I configured every setting that's NOT optional... and I get the following:

    Feb 15 22:51:45 php: nut: Service failed to start: check configuration
    Feb 15 22:51:45 php: nut: Starting service
    Feb 15 22:50:44 php: nut: Service failed to start: check configuration
    Feb 15 22:50:43 php: nut: Starting service
    Feb 15 22:49:34 php: /pkg_mgr_install.php: Beginning package installation for nut.

    UPS Monitoring   LOCAL
    Local UPS Name UPS_IDEN
    Local UPS Model SMART-UPS
    Local UPS Port    COM1 (ttyd0)

    any idea ?



  • @trendchiller:

    hmmm, does not work for me…

    seems not to find my smart-ups via calbe (com1)  :'(

    I configured every setting that's NOT optional... and I get the following:

    Feb 15 22:51:45 php: nut: Service failed to start: check configuration
    Feb 15 22:51:45 php: nut: Starting service
    Feb 15 22:50:44 php: nut: Service failed to start: check configuration
    Feb 15 22:50:43 php: nut: Starting service
    Feb 15 22:49:34 php: /pkg_mgr_install.php: Beginning package installation for nut.

    UPS Monitoring   LOCAL
    Local UPS Name UPS_IDEN
    Local UPS Model SMART-UPS
    Local UPS Port    COM1 (ttyd0)

    any idea ?

    You need to specify a cable type, that is why is it in () next to Smart-UPS. If that is an APC cable look at both ends. In the plastic it will have the cable number engraved. Specify that cable in the nut cable type selection.



  • Hmmm, did it that way, but it does not work either :-(

    And the service is being started, tells me successful, but then does not start at all  :-\



  • @trendchiller:

    Hmmm, did it that way, but it does not work either :-(

    And the service is being started, tells me successful, but then does not start at all  :-\

    What color is your serial cable and what number is on it? I will look into it. I have an APC Smart UPS with a gray cable, number 940-0095B. There are about 10 different cables so it is important that you actually look at the cable for the number. If you pick the wrong cable type it will not work. It would be helpful if you could provide more information.



  • Heres a snapshot of my configuration and the status. The cable I have is technically for a Back-UPS Pro UPS, I have a few UPS's and cables have gotten swapped around. I did test with the actual Smart-UPS cable and it works as well. The protocol is the same, but every model cable is wired slightly different. The UPS model Smart-UPS, Back-UPS Pro tells the driver what subset of the protocol the UPS supports, such as temperature, etc



  • The cable I have is a 940-004C cable…
    Should be working with the Rack Smart UPS 1000 I think...



  • @trendchiller:

    The cable I have is a 940-004C cable…
    Should be working with the Rack Smart UPS 1000 I think...

    I figured it out. I went through and read the man pages on the apcsmart driver. Turns out it only supports two cables, unlike other documentation I have read. I went as far as going through the actual code to confirm this. I am updating the NUT package to reflect this. You need to find one of the below cables to get it working.

    "This driver expects to see a 940-0024C cable or  a  clone  by  default.
          You can switch to the 940-0095B dual-mode cable support with the cable=
          definition described below.

    If your 940-0024C cable is broken or missing, use this diagram to build
          a clone:

    http://random.networkupstools.org/cables/940-0024C.jpg"



  • By chance did you read the cable number wrong and it is really 940-0024C. 2 might look like 0 in the dark on plastic. ;D Try reinstalling the package and configuring it with that cable setting.



  • you were right… error while reading...

    it's the 24 cable...

    but after reinstalling it does still not work :-(



  • @trendchiller:

    you were right… error while reading...

    it's the 24 cable...

    but after reinstalling it does still not work :-(

    I'm really confused. I have both cables 940-0024C and 940-0095B sitting here in front of me and they both work. I have an APC SmartUPS 700. Are you sure the cable is good? Have you tested it with the APC monitoring software by chance?

    Also if the nut status screen shows wait, refresh your browser as its still negotiating with the UPS.



  • How can I check, why the service won't start ?
    any idea ?



  • @trendchiller:

    How can I check, why the service won't start ?
    any idea ?

    Configure nut via the webgui. Then go to the console and run

    /usr/local/libexec/nut/upsdrvctl start

    You should see something like

    Detected SMART-UPS 700 [serialnum] on /dev/ttyd0

    Otherwise it will give you an error message. The config files are stored in /usr/local/etc/nut/ If you get it working let me know what you changed to make it work.

    After you get that far then you run the following commands. Be sure to replace myups with the name you gave your ups in the nut config.

    /usr/local/sbin/upsd
    /usr/local/sbin/upsmon myups@localhost

    Both the above commands should tell you they were successfully executed.


Log in to reply