I've got the power (english version)

This is a translation of an old post in french, see the original here.

No, I've not become Fred Almighty and that's happy, it would be a mess :D
In the scope of non-profit activities, I received a wonderful UPS that I had to configure for FreeBSD.

At the beginnning, to be honest, I was not really motivated to configure this beast for the Wonderful OS especially after seeing that all different tools where in Java[1].
After having my server configured to access it from home[2] and plugged to the UPS through the USB cable, I've been looking for a way to make it work.
A small query on Internet and I have found a small load monitor running of FreeBSD named Nut which is hosted by Eaton... This seems to be good while your UPS is a Eaton Ellipse ASR750 ;-)

A quick tour of supported hardware is a piece of cake and confirms that everything will be alright.
So, I install Nut through the classical way :

root@rcjserveur : ~> cd /usr/ports/sysutils/nut/ && make install clean

Configuration is not so hard even if I have to change few points like compared to this :
For ups.conf, keep it simple :

[eaton]
        driver = usbhid-ups
        port = auto
        desc = "EATON UPS"


hosts.conf

#
MONITOR eaton@localhost "UPS Eaton Ellipse"
# MONITOR su2200@10.64.1.1 "Finance department"
# MONITOR matrix@shs-server.example.edu "Sierra High School data room #1"


For upsd.users

Sorry, I won't give you this one, there are some credentials in it !!!


In upsmon.conf

...
MONITOR eaton@localhost 1 my_user my_password master
...
SHUTDOWNCMD "/sbin/shutdown -p +0"


Everything seemed to be ok but...
The main problem came from the rights on the USB as usual. In fact, at login time or at startup, rights are really generics.
Happily, FreeBSD is here to help you and give you the answer tanks to ''devd'' and to its configuration curiously named ''devd.conf''. For your information, I found this solution more elegant and more generic than using devfs.

attach 100 {
        match "vendor" "0x0463";
        match "product" "0xffff";
        action "/usr/sbin/chown -R -L uucp:uucp /dev/$device-name";
};

Off course, these values are not randomly chosen, a quick use of ''usbconfig'' gives you the hints

root@rcjserveur : ~> usbconfig -u 4 -a 2 dump_device_desc
ugen4.2: <ELLIPSE EATON> at usbus4, cfg=0 md=HOST spd=LOW (1.5Mbps) pwr=ON
  bLength = 0x0012 
  bDescriptorType = 0x0001 
  bcdUSB = 0x0110 
  bDeviceClass = 0x0000 
  bDeviceSubClass = 0x0000 
  bDeviceProtocol = 0x0000 
  bMaxPacketSize0 = 0x0008 
  idVendor = 0x0463 
  idProduct = 0xffff 
  bcdDevice = 0x0001 
  iManufacturer = 0x0001  <EATON>
  iProduct = 0x0002  <ELLIPSE>
  iSerialNumber = 0x0004  <BDCK520CF>
  bNumConfigurations = 0x0001 



Tests were simple too. I just checked that I could see the charge of the machine while telling myself that for a shutdown script, I'll look at it later.
Well, as Murphy's law tells, it was checked by itself as there was a power outage on friday evening until monday morning. Seeking in the logs, I found the Holy Graal :

Mar 11 17:28:35 RCJServeur upsmon[32074]: UPS eaton@localhost on battery
...
Mar 11 17:42:16 RCJServeur upsmon[32074]: UPS eaton@localhost battery is low
Mar 11 17:42:16 RCJServeur upsmon[32074]: Executing automatic power-fail shutdown
Mar 11 17:42:16 RCJServeur upsmon[32074]: Auto logout and shutdown proceeding
Mar 11 17:42:21 RCJServeur shutdown: power-down by fred: 
Mar 11 17:42:23 RCJServeur upsd[32047]: mainloop: Interrupted system call

Great, the server shut down correctly when the UPS was out of power. Well done Fred, you've got the power !!!
What surprised me is that the server started up by itself when power came back and despite the fact that I did'nt configure anything for that :)
Well, this is not really a problem so I can sleep well :D

Notes

[1] I work with it all the day, so I won't play with it on my spare time also ;-)

[2] Won't tell you how, it would be too risky, bitthirsty hackers !!

Ajouter un commentaire

Le code HTML est affiché comme du texte et les adresses web sont automatiquement transformées.

La discussion continue ailleurs