Sep 4, 2014

Configuring our UPS in Gentoo

If we have an UPS with a communication link (serial or usb), it can be configured in Linux with Network UPS Tools (or NUT).

Installation


You need to install the sys-power/nut package. If your UPS has an USB interface, make sure you install it with the usb flag.

Configuration


Once installed, visit http://www.networkupstools.org/ and go to the Compatibility List. There you can filter your UPS Manufacturer to check the NUT driver you will be using. If your Manufacturer appears but your Device Model doesn't you can try to use the same driver as any other model like the one you have. In my case I have a PowerWalker VI 650 LCD that doesn't appear on the list, but since other models of PowerWalker are using the blazer_ser and blazer_usb drivers, I'm going to use the blazer_usb driver for this one.

Edit the configuration file /etc/nut/ups.conf to add the configuration of your UPS, mine is as follows:
[PowerWalker]
 driver = blazer_usb
 port = auto
 desc = "PowerWalker VI 650"
 norating
 novendor

Then you can try if NUT can find your UPS by running the upsdrvctl command:
# upsdrvctl start
Network UPS Tools - UPS driver controller 2.6.5
Network UPS Tools - Megatec/Q1 protocol USB driver 0.09 (2.6.5)
Supported UPS detected with mustek protocol
Vendor information unavailable
No values provided for battery high/low voltages in ups.conf

Using 'guestimation' (low: 10.400000, high: 13.000000)!
Battery runtime will not be calculated (runtimecal not set)
If the command runs without errors, you have your UPS successfully detected by NUT. Some drivers as the blazer_usb, will require extra commands to provide the battery charge and autonomy values.

Last step is configure an administration user name in /etc/nut/upsd.user. Once that is done, you can start the daemon and if you don't get any error, add it also to your runlevel.
# /etc/init.d/upsd start
 * Starting upsd ...
fopen /var/lib/nut/upsd.pid: No such file or directory
listening on 127.0.0.1 port 3493
not listening on ::1 port 3493
Connected to UPS [PowerWalker]: blazer_usb-PowerWalker
# rc-update add upsd
 * service upsd added to runlevel default

Monitoring


Once we have the daemon started, we can monitor the UPS with the upsc command. This command requires the name we gave the UPS in the /etc/nut/ups.conf file and will give us all the information about our newly-installed UPS:
# upsc PowerWalker
battery.charge: 100
battery.voltage: 13.50
battery.voltage.high: 13.00
battery.voltage.low: 10.40
battery.voltage.nominal: 12.0
device.type: ups
driver.name: blazer_usb
driver.parameter.pollinterval: 2
driver.parameter.port: auto
driver.version: 2.6.5
driver.version.internal: 0.09
input.current.nominal: 2.0
input.frequency: 50.1
input.frequency.nominal: 50
input.voltage: 231.5
input.voltage.fault: 231.5
input.voltage.nominal: 230
output.voltage: 231.5
ups.beeper.status: disabled
ups.delay.shutdown: 30
ups.delay.start: 180
ups.load: 9
ups.productid: 5161
ups.status: OL
ups.type: offline / line interactive
ups.vendorid: 0665

Jan 15, 2014

Run Flexget daemon at boot time (with init.d support)


Flexget version 1.2 and above add an option to run it as a daemon process instead of executing it several times via script or crontab. The good thing about this change is that now we can have an init script to start the daemon at boot time and forget about the needed crontab or script to run it.

Since this change isn't already on Gentoo's Portage main tree, I've opened Bug 498012 to submit the necessary changes to add it to Portage.


Applying the patch


You can find all the needed files as attachments in the submitted bug.
  • flexget-1.2.31: This file is the init.d script, it should be copied to /usr/portage/app-net/flexget/files, create the folder files if it doesn't exist.
  • flexget_conf: This file is the conf.d source needed for the init.d script to work, it should be copied to the same folder.
  • flexget-1.2.31.patch: This is the ebuild patch, needed to patch the actual flexget ebuild. To update the actual build, run the following:
    cd /usr/portage/app-net/flexget
    patch -p1 flexget-1.2.31.patch
    
  • The last step should be to regenerate the manifest file in /usr/portage/app-net/flexget, since we now have a modified ebuild, to do this, just execute the following inside that directory:
    cd /usr/portage/app-net/flexget
    ebuild flexget-1.2.31.ebuild manifest
    
Once you've finished applying the patch, you need to reinstall flexget to apply the new configuration. Then you just need to edit the contents of /etc/conf.d/flexgetd with your user and config file and you're ready to run flexget via init.d script.


Sample Configuration


# /etc/conf.d/flexgetd

# Options to pass to flexgetd at startup
# Default username to run flexgetd
FLEXGET_USER="flex_user"
# Flexget configuration file location
# Example: "/home/user/.flexget/config.yml"
FLEXGET_USER_CONFIG="/home/flex_user/.flexget/config.yml"

Remeber that you can add the init.d script to boot time with rc-update.