I installed OmniOS on my home filer over the Christmas break. Jumping from a Solaris Nevada build to OmniOS meant figuring out what software packages are available in the OmniOS repositories, what third-party repos are available and what software I would have to compile by hand. Given that this machine is only acting as a filer and isn't running any other services to speak of, the list of software to get up and running is small; however a critical component is apcupsd which talks to the Uninterruptible Power Supply (UPS) and cleanly powers down the filer if the power goes out for an extended time.

The hangup for me is that my UPS connects to the filer via USB, not a serial connection. It took me some hours to figure out how to get apcupsd installed with USB support. Here's how.

These are the basic steps:

  1. Install the developer software packages needed to compile C/C++ code
  2. Install libusb, a prerequisite for apcupsd
  3. Build apcupsd

Why build apcupsd at all? Why not install a binary package? I tried.

Tried Outcome
Install from [OmniOS pkg repository](http://pkg.omniti.com/omnios/release/) apcupsd not present in repo
Install from OmniTI's [non-core package repo](http://pkg.omniti.com/omniti-ms/) apcupsd not present in repo
Install from a [listed](http://omnios.omniti.com/wiki.php/Packaging) third-party repo apcupsd not present in any third-party repo
Install from the [OpenIndiana pkg repo](http://pkg.openindiana.org/dev) apcupsd not present in repo
Install a binary package from [OpenCSW](http://www.opencsw.org/packages/CSWapcupsd/) OpenCSW has an apcupsd package, however you can see by inspecting their Makefile that they do not build it with USB support

Building from source was really the only option left.

UPDATE Aug 29, 2013: I thought building from source was the only option left but Ed Begley pointed out that libusb and libusbugen are available in the OpenIndiana /hipster repo at http://pkg.openindiana.org/hipster

Install Developer Software

Being somewhat of a bare-bones OS, OmniOS doesn't install developer tools by default.

Note that this is somewhat untrue. While the OmniOS philosophy is to keep the OS lightweight, there is a small bug in the 151004 release that causes the gcc44 package to be installed by default. (http://omnios.omniti.com/ticket.php/42)

The OmniOS Wiki details how to install the dev packages in one shot. Since gcc44 was already installed on my system I opted not to include the gcc46 package and just rely on gcc44 to get the job done.

# pkg install \
   developer/object-file \
   developer/linker \
   developer/library/lint \
   developer/build/gnu-make \
   system/header \
   system/library/math/header-math

Install libusb

When using a USB-connected UPS, apcupsd depends on a third-party library for talking on the USB bus. Getting libusb installed was the trickiest part of this whole thing for me. Here are the options I explored and why none were successful.

Option Outcome
Install from OmniOS pkg repo libusb not present
Install from OmniTI's non-core repo or a listed third-party repo libusb not present
Install from OpenIndiana pkg repo libusb is present in this repo, however it depends on the SFW consolidation which contains a whole lot of software that isn't necessary on a filer and that I didn't want to install (almost 800 packages including things like PostgreSQL, Java, and PHP)
Install from OpenCSW No libusb package available
Build from source libusb 1.0 does not [support Solaris](http://www.libusb.org/wiki/libusb-1.0#OpenUSB)
Build OpenUSB which is a fork of libusb and offers support for Solaris When ./configuring libopenusb, it looks for an installed copy of libusb. Yes, really.

This is where I got stumped and started going around in circles, trying lots of Google searches, and trying to make sure I hadn't overlooked something. Then by fluke, a random Google search turned me on to an SRV4 package named SUNWlibusb. This package happened to be on the Solaris Nevada ISO and had zero dependencies. Perfect.

# lofiadm -a /Solaris/Solaris_Nevada_b129/sol-nv-b129-x86-dvd.iso
/dev/lofi/1
# mount -F hsfs /dev/lofi/1 /media
# ls -ld /media/Solaris_11/Product/SUNWlibusb*
/media/Solaris_11/Product/SUNWlibusb
/media/Solaris_11/Product/SUNWlibusbugen

There we go, the two packages needed to get USB support in apcupsd. Thankfully, OmniOS ships with the SRV4 package management tools so it was very simple to install them.

# pkgadd -d /media/Solaris_11/Product SUNWlibusb SUNWlibusbugen

One last but very important step: you must perform a reconfiguration reboot after installing libusbugen. This will force the UPS to attach to the ugen(7D) driver rather than the hid(7D) driver (which it does by default).

# touch /reconfigure
# shutdown -y -g0 -i6

If the UPS does not attach to the ugen(7D) driver at system boot, apcupsd will not be able to detect the UPS.

You can verify where your UPS has attached by looking at the system boot messages in /var/adm/messages. This is attached to hid(7D) (what we don't want):

[...] usba: [ID 912658 kern.info] USB 1.10 device (usb51d,2) operating at low speed (USB 1.x) on USB 1.10 root hub: input@1, hid0 at bus address 2
[...] usba: [ID 349649 kern.info]     American Power Conversion Back-UPS XS 1300 LCD FW:836.H8 .D USB FW:H8  BB0847008412

This is attached to ugen(7D) (exactly what we want):

[...] usba: [ID 912658 kern.info] USB 1.10 device (usb51d,2) operating at low speed (USB 1.x) on USB 1.10 root hub: input@1, ugen0 at bus address 2
[...] usba: [ID 349649 kern.info]   American Power Conversion Back-UPS XS 1300 LCD FW:836.H8 .D USB FW:H8  BB0847008412

If you have multiple USB devices on your system, look for usb51d,2 β€” it's the vendor code for APC.

Build apcupsd

I like binaries for third-party software installed under /usr/local/{bin,sbin}, config files in /etc and logs in /var/log. This is how I ran ./configure:

./configure \
  --prefix=/usr/local \
  --sbindir=/usr/local/sbin \
  --sysconfdir=/etc/apcupsd \
  --mandir=/usr/local/share/man \
  --with-log-dir=/var/log \
  --disable-cgi \
  --enable-usb

For some reason, setting -prefix is not enough. I had to also set -sbindir and -mandir.

Once configure is done, gmake install takes care of the rest and we end up with a working apcupsd:

# /usr/local/sbin/apcaccess
APC      : 001,036,0902
DATE     : 2013-01-01 10:27:52 -0700
HOSTNAME : sigma
VERSION  : 3.14.10 (13 September 2011) sun
UPSNAME  : sigma
CABLE    : USB Cable
DRIVER   : USB UPS Driver
[...]