+-----------------------------------------------------------------------
| Running nut on OpenBSD
+-----------------------------------------------------------------------

NUT is split into separate components. A hardware driver interfaces
with the device and sends information to upsd. A monitor (upsmon)
connects to upsd and shuts down the machine when necessary.

These components can reside on separate computers (i.e. UPS monitored
by various computers may communicate with a central upsd, and a whole
network may run upsmon to allow for shutdown).

On OpenBSD, daemons from packages are usually started by adding to the
pkg_scripts line in /etc/rc.conf.local. For NUT, machines running
upsd or the hardware driver should include "upsd" in this line, and all
machines should include "upsmon". Where you run both, upsd should
be started first. For example you could use this line:

	pkg_scripts=upsd upsmon [...any other daemons...]

Network devices
---------------
To reduce dependencies for the basic NUT package, some network devices
are supported by optional subpackages: nut-snmp (for SNMP-based devices),
nut-xml (for Eaton/MGE devices using an XML/HTTP protocol).

Connecting to a remote server running nutd(8) requires only the basic
NUT package which also includes the file you are reading now.

Configuring NUT
---------------
The following files must be edited for a typical installation.

* ups.conf

Details of UPS device/s are held here. These may either be directly
connected, or network devices (this can include a NUT server running on
another machine). Configuration sections for this file can be generated
for network and USB devices using nut-scanner(8). This is in the main
NUT package but picks up dependencies at runtime, so if you wish
to scan for network devices, just make sure the relevant package
is installed before you run the scanner.

To scan for network devices, specify start and end IP addresses:

	# nut-scanner -s 192.168.17.1 -e 192.168.17.20

* upsd.users

upsd(8) user authentication is configured here.

* upsmon.conf

This file informs upsmon(8) which devices (configured in ups.conf) it
should monitor. It also contains passwords to authenticate to upsd(8).

Device permissions
------------------
For locally connected UPS devices, the userid running NUT (normally
_ups) must have access to the relevant device nodes.

RS232: Either add _ups to group "dialer" or change the group ownership
of the relevant /dev/tty* device to _ups.

USB: Use "usbdevs -vd" (as root) to identify the specific controller
(/dev/usbXX) and ugen (/dev/ugenXX) device nodes, then adjust permissions
to allow _ups to have write access (e.g. chmod g+w and chgrp _ups).

Special notice for USB devices
------------------------------
Some USB devices (especially APC ones) are reported to only work with
NUT if the device is attached to ugen(4). Normally these devices attach
to upd(4) to provide system power sensors (see "sysctl hw.sensors").
In some cases, where a device is attached to a device driver other than
ugen(4), for example upd or uhid, it cannot also be used with NUT.

Preventing the attachment is possible but requires kernel changes.

If you do not use a USB keyboard/mouse, you can simply disable the upd
and uhidev drivers. Use the bsd.re-config(5) mechanism by adding the
following lines to /etc/bsd.re-config

  disable uhidev
  disable upd

and run /usr/libexec/reorder_kernel. Or, as a one-off, you can patch an
existing kernel using config(8) with the same 'disable' commands, or
boot into UKC ("boot -c") and enter the disable commands.

With a USB keyboard/mouse, you will need to target the UPS device id.
Fetch kernel sources if you don't already have them, add the device to
the usbd_quirk_entry table in /sys/dev/usb/usb_quirks.c, and build a
new kernel. Either use an existing ID from /sys/dev/usb/usbdevs (these
are for devices which are known to have problems sharing upd and NUT):

  { USB_VENDOR_APC, USB_PRODUCT_APC_UPS, ANY, { UQ_BAD_HID }},
  { USB_VENDOR_APC, USB_PRODUCT_APC_UPS5G, ANY, { UQ_BAD_HID }},

or add it numerically, e.g.

  { 0x051d, 0x0003, ANY, { UQ_BAD_HID }},

Then follow the usual steps to build a kernel.

Starting the daemons
--------------------
To start the daemons without rebooting you can use:

	# /etc/rc.d/upsd start
	# /etc/rc.d/upsmon start

NUT documentation refers to a nut.conf file; this can be ignored, it is
only used with their System V init scripts, and not OpenBSD's rc scripts.

It is recommended that you test a full cycle of rebooting, checking
that the daemons are running correctly ("upsc <upsname>" will display
information retrieved by NUT from the UPS), allowing the machine
to be shut down by the UPS, and returning power.
