4 This chapter describe most of the configuration and use aspects of NUT,
5 including establishing communication with the device and configuring safe
6 shutdowns when the UPS battery runs out of power.
8 There are many programs and <<Features,features>> in this
9 package. You should check out the <<Overview,NUT Overview>>
10 and other accompanying documentation to see how it all works.
12 NOTE: NUT does not currently provide proper graphical configuration tools.
13 However, there is now support for linkdoc:developer-guide[Augeas,augeas_user],
14 which will enable the easier creation of configuration tools.
15 Moreover, linkman:nut-scanner[8] is available to discover supported devices
16 (USB, SNMP, Eaton XML/HTTP and IPMI) and NUT servers (using Avahi or the classic
19 Details about the configuration files
20 -------------------------------------
25 All configuration files within this package are parsed with a common
26 state machine, which means they all can use a number of extras described here.
28 First, most of the programs use an uppercase word to declare a
29 configuration directive. This may be something like MONITOR, NOTIFYCMD,
30 or ACCESS. The case does matter here. "monitor" won't be recognized.
32 Next, the parser does not care about whitespace between words. If you
33 like to indent things with tabs or spaces, feel free to do it here.
35 If you need to set a value to something containing spaces, it has to be
36 contained within "quotes" to keep the parser from splitting up the line.
37 That is, you want to use something like this:
39 SHUTDOWNCMD "/sbin/shutdown -h +0"
41 Without the quotes, it would only see the first word on the line.
43 OK, so let's say you really need to embed that kind of quote within your
44 configuration directive for some reason. You can do that too.
46 NOTIFYCMD "/bin/notifyme -foo -bar \"hi there\" -baz"
48 In other words, *\* can be used to escape the *"*.
50 Finally, for the situation where you need to put the *\* character into your
51 string, you just escape it.
53 NOTIFYCMD "/bin/notifyme c:\\dos\\style\\path"
55 The *\* can actually be used to escape any character, but you only really
56 need it for *\*, *"*, and *#* as they have special meanings to the parser.
58 When using file names with space characters, you may end up having tricky
59 things since you need to write them inside *""* which must be escaped:
61 NOTIFYCMD "\"c:\\path with space\\notifyme\" \"c:\\path with space\\name\""
63 *#* is the comment character. Anything after an unescaped *#* is ignored.
65 Something like this...
69 ... will actually turn into "identity = my", since the *#* stops the
70 parsing. If you really need to have a *#* in your configuration, then
77 The *=* character should be used with care too. There should be only one
78 "simple" *=* character in a line: between the parameter name and its value.
79 All other *=* characters should be either escaped or whithin "quotes".
83 ... is incorrect. You should use:
94 You can put a backslash at the end of the line to join it to the next
95 one. This creates one virtual line that is composed of more than one
98 Also, if you leave the *""* quote container open before a newline, it will
99 keep scanning until it reaches another one. If you see bizarre behavior
100 in your configuration files, check for an unintentional instance of
101 quotes spanning multiple lines.
107 This chapter describe the base configuration to establish communication with
110 This will be sufficient for PDU. But for UPS and SCD, you will also need to
111 configure <<UPS_shutdown,automatic shutdowns for low battery events>>.
113 image:images/simple.png[]
115 [[Driver_configuration]]
119 Create one section per UPS in /usr/local/ups/etc/ups.conf
121 To find out which driver to use, check the <<HCL,Hardware Compatibility List>>,
124 Once you have picked a driver, create a section for your UPS in
125 ups.conf. You must supply values for "driver" and "port".
127 Some drivers may require other flags or settings. The "desc" value
128 is optional, but is recommended to provide a better description of
129 what your UPS is supporting.
131 A typical device without any extra settings looks like this:
138 NOTE: USB drivers (usbhid-ups, bcmxcp_usb, tripplite_usb, blazer_usb and
139 richcomm_usb) are special cases and ignore the 'port' value.
140 You must still set this value, but it does not matter what you set
141 it to; a common and good practice is to set 'port' to *auto*, but you can
142 put whatever you like. If you only own one UBS UPS, the driver will
143 find it automatically. If you own more than one, refer to the driver's
144 manual page for more information on matching a specific device.
146 References: linkman:ups.conf[5],
147 linkman:nutupsdrv[8],
148 linkman:bcmxcp_usb[8],
150 linkman:richcomm_usb[8],
151 linkman:tripplite_usb[8],
152 linkman:usbhid-ups[8]
156 Starting the driver(s)
157 ~~~~~~~~~~~~~~~~~~~~~~
159 Start the driver(s) for your hardware:
161 /usr/local/ups/bin/upsdrvctl start
163 Make sure the driver doesn't report any errors. It should show a
164 few details about the hardware and then enter the background. You
165 should get back to the command prompt a few seconds later. For
166 reference, a successful start of the `usbhid-ups` driver looks like this:
168 # /usr/local/ups/bin/upsdrvctl start
169 Network UPS Tools - Generic HID driver 0.34 (2.4.1)
170 USB communication driver 0.31
171 Using subdriver: MGE HID 1.12
172 Detected EATON - Ellipse MAX 1100 [ADKK22008]
174 If the driver doesn't start cleanly, make sure you have picked the
175 right one for your hardware. You might need to try other drivers
176 by changing the "driver=" value in ups.conf.
178 Be sure to check the driver's man page to see if it needs any extra
179 settings in ups.conf to detect your hardware.
181 If it says "can't bind /var/state/ups/..." or similar, then your
182 state path probably isn't writable by the driver. Check the
183 <<StatePath,permissions and mode on that directory>>.
185 After making changes, try the <<Ownership, Ownership and permissions>> step again.
187 References: man pages: linkman:nutupsdrv[8], linkman:upsdrvctl[8]
190 Data server configuration (upsd)
191 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
193 Configure upsd, which serves data from the drivers to the clients.
195 First, edit upsd.conf to allow access to your client systems. By
196 default, upsd will only listen to localhost port 3493/tcp. If you want
197 to connect to it from other machines, you must specify each interface you
198 want upsd to listen on for connections, optionally with a port number.
200 LISTEN 127.0.0.1 3493
203 NOTE: Refer to the NUT user manual <<NUT_Security,security chapter>> for
204 information on how to access and secure upsd clients connections.
206 Next, create upsd.users. For now, this can be an empty file.
207 You can come back and add more to it later when it's time to
208 configure upsmon or run one of the management tools.
210 Do not make either file world-readable, since they both hold
211 access control data and passwords. They just need to be readable by
212 the user you created in the preparation process.
214 The suggested configuration is to chown it to root, chgrp it to the
215 group you created, then make it readable by the group.
217 chown root:nut upsd.conf upsd.users
218 chmod 0640 upsd.conf upsd.users
220 References: man pages: linkman:upsd.conf[5],
221 linkman:upsd.users[5],
225 Starting the data server
226 ~~~~~~~~~~~~~~~~~~~~~~~~
228 Start the network data server:
230 /usr/local/ups/sbin/upsd
232 Make sure it is able to connect to the driver(s) on your system.
233 A successful run looks like this:
235 # /usr/local/ups/sbin/upsd
236 Network UPS Tools upsd 2.4.1
237 listening on 127.0.0.1 port 3493
238 listening on ::1 port 3493
239 Connected to UPS [eaton]: usbhid-ups-eaton
241 upsd prints dots while it waits for the driver to respond. Your
242 system may print more or less depending on how many drivers you
243 have and how fast they are.
245 NOTE: if upsd says that it can't connect to a UPS or that the data
246 is stale, then your ups.conf is not configured correctly, or you
247 have a driver that isn't working properly. You must fix this before
248 going on to the next step.
250 Reference: man page: linkman:upsd[8]
258 Make sure that the UPS is providing good status data.
260 /usr/local/ups/bin/upsc myupsname@localhost ups.status
262 You should see just one line in response:
266 OL means your system is running on line power. If it says something
267 else (like OB - on battery, or LB - low battery), your driver was
268 probably misconfigured during the <<Driver_configuration, Driver configuration>>
269 step. If you reconfigure the driver, use 'upsdrvctl stop' to stop it, then
270 start it again as shown in the <<Starting_drivers, Starting driver(s)>> step.
272 Reference: man page: linkman:upsc[8]
278 Look at all of the status data which is being monitored.
280 /usr/local/ups/bin/upsc myupsname@localhost
282 What happens now depends on the kind of device and driver you have.
283 In the list, you should see ups.status with the same value you got
284 above. A sample run on a UPS (Eaton Ellipse MAX 1100) looks like this:
287 battery.charge.low: 20
288 battery.runtime: 2525
291 device.model: Ellipse MAX 1100
292 device.serial: ADKK22008
294 driver.name: usbhid-ups
295 driver.parameter.pollfreq: 30
296 driver.parameter.pollinterval: 2
297 driver.parameter.port: auto
298 driver.version: 2.4.1-1988:1990M
299 driver.version.data: MGE HID 1.12
300 driver.version.internal: 0.34
301 input.sensitivity: normal
302 input.transfer.boost.low: 185
303 input.transfer.high: 285
304 input.transfer.low: 165
305 input.transfer.trim.high: 265
306 input.voltage.extended: no
307 outlet.1.desc: PowerShare Outlet 1
310 outlet.1.switchable: no
311 outlet.desc: Main Outlet
313 outlet.switchable: no
314 output.frequency.nominal: 50
315 output.voltage: 230.0
316 output.voltage.nominal: 230
317 ups.beeper.status: enabled
318 ups.delay.shutdown: 20
323 ups.model: Ellipse MAX 1100
324 ups.power.nominal: 1100
326 ups.serial: ADKK22008
328 ups.timer.shutdown: -1
332 Reference: man page: linkman:upsc[8],
333 <<nut-names,NUT command and variable naming scheme>>
338 NOTE: This step is not need if you installed from packages.
340 Edit your startup scripts, and make sure upsdrvctl and upsd are run every time
344 Configuring automatic shutdowns for low battery events
345 ------------------------------------------------------
347 The whole point of UPS software is to bring down the OS cleanly when you
348 run out of battery power. Everything else is roughly eye candy.
350 To make sure your system shuts down properly, you will need to perform some
351 additional configuration and run upsmon. Here are the basics.
357 When your UPS batteries get low, the operating system needs to be brought
358 down cleanly. Also, the UPS load should be turned off so that all devices
359 that are attached to it are forcibly rebooted.
361 Here are the steps that occur when a critical power event happens:
363 1. The UPS goes on battery
365 2. The UPS reaches low battery (a "critical" UPS), that is to say
370 The exact behavior depends on the specific device, and is related to:
372 - battery.charge and battery.charge.low
373 - battery.runtime and battery.runtime.low
375 3. The upsmon master notices and sets "FSD" - the "forced shutdown"
376 flag to tell all slave systems that it will soon power down the load.
378 (If you have no slaves, skip to step 6)
380 4. upsmon slave systems see "FSD" and:
382 - generate a NOTIFY_SHUTDOWN event
383 - wait FINALDELAY seconds - typically 5
384 - call their SHUTDOWNCMD
385 - disconnect from upsd
387 5. The upsmon master system waits up to HOSTSYNC seconds (typically 15)
388 for the slaves to disconnect from upsd. If any are connected after
389 this time, upsmon stops waiting and proceeds with the shutdown
392 6. The upsmon master:
394 - generates a NOTIFY_SHUTDOWN event
395 - waits FINALDELAY seconds - typically 5
396 - creates the POWERDOWNFLAG file - usually /etc/killpower
397 - calls the SHUTDOWNCMD
399 7. On most systems, init takes over, kills your processes, syncs and
400 unmounts some filesystems, and remounts some read-only.
402 8. init then runs your shutdown script. This checks for the
403 POWERDOWNFLAG, finds it, and tells the UPS driver(s) to power off
406 9. The system loses power.
408 10. Time passes. The power returns, and the UPS switches back on.
410 11. All systems reboot and go back to work.
416 [[NUT_user_creation]]
420 Create a upsd user for upsmon to use while monitoring this UPS.
422 Edit upsd.users and create a new section. upsmon will connect
423 to upsd and use this user name (in brackets) and password to
424 authenticate. This example is for a user called "monuser":
431 References: linkman:upsd[8], linkman:upsd.users[5]
433 Reloading the data server
434 ^^^^^^^^^^^^^^^^^^^^^^^^^
436 Reload upsd. Depending on your configuration, you may be able to
437 do this without stopping upsd:
439 /usr/local/ups/sbin/upsd -c reload
441 If that doesn't work (check the syslog), just restart it:
443 /usr/local/ups/sbin/upsd -c stop
444 /usr/local/ups/sbin/upsd
446 NOTE: if you want to make reloading work later, see the entry in the
447 link:FAQ.html[FAQ] about starting upsd as a different user.
452 Set the POWERDOWNFLAG location for upsmon.
454 In upsmon.conf, add a POWERDOWNFLAG directive with a filename.
455 upsmon will create this file when the UPS needs to be powered off
456 during a power failure when low battery is reached.
458 We will test for the presence of this file in a later step.
460 POWERDOWNFLAG /etc/killpower
462 References: man pages: linkman:upsmon[8],
463 linkman:upsmon.conf[5]
468 The recommended setting is to have it owned by root:nut, then make it readable
469 by the group and not world. This file contains passwords that could be used by
470 an attacker to start a shutdown, so keep it secure.
472 chown root:nut upsmon.conf
473 chmod 0640 upsmon.conf
475 This step has been placed early in the process so you secure this file before
476 adding sensitive data in the next step.
479 Create a MONITOR directive for upsmon
480 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
482 Edit upsmon.conf and create a MONITOR line with the UPS definition
483 (<upsname>@<hostname>), username and password from the <<NUT_user_creation, NUT user creation>>
484 step, and the master or slave setting.
486 If it's the master (i.e., it's connected to this UPS directly):
488 MONITOR myupsname@mybox 1 monuser mypass master
490 If it's just monitoring this UPS over the network, and some other system is the
493 MONITOR myupsname@mybox 1 monuser mypass slave
495 The number "1" here is the power value. This should always be set to 1 unless
496 you have a very special (read: expensive) system with redundant power supplies.
497 In such cases, refer to the User Manual:
499 - <<BigServers,typical setups for big servers>>,
500 - <<DataRoom,typical setups for data rooms>>.
502 References: linkman:upsmon[8], linkman:upsmon.conf[5]
504 Define a SHUTDOWNCMD for upsmon
505 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
507 Still in upsmon.conf, add a directive that tells upsmon how to shut down your
508 system. This example seems to work on most systems:
510 SHUTDOWNCMD "/sbin/shutdown -h +0"
512 Notice the presence of "quotes" here to keep it together.
514 If your system has special needs, you may want to set this to a script which
515 does local shutdown tasks before calling init.
521 /usr/local/ups/sbin/upsmon
523 If it complains about something, then check your configuration.
528 Look for messages in the syslog to indicate success. It should look something
531 May 29 01:11:27 mybox upsmon[102]: Startup successful
532 May 29 01:11:28 mybox upsd[100]: Client monuser@192.168.50.1
533 logged into UPS [myupsname]
535 Any errors seen here are probably due to an error in the config files of either
536 `upsmon` or `upsd`. You should fix them before continuing.
542 NOTE: This step is not need if you installed from packages.
544 Edit your startup scripts, and add a call to `upsmon`.
546 Make sure `upsmon` starts when your system comes up. Do it after `upsdrvctl`
547 and `upsd`, or it will complain about not being able to contact the server.
549 You may delete the POWERDOWNFLAG in the startup scripts, but it is not
550 necessary. `upsmon` will clear that file for you when it starts.
552 NOTE: Init script examples are provide in the 'scripts' directory of
553 the NUT source tree, and in the various <<_binary_packages,packages>>
559 NOTE: This step is not need if you installed from packages.
561 Edit your shutdown scripts, and add `upsdrvctl shutdown`.
563 You should configure your system to power down the UPS after the filesystems are
564 remounted read-only. Have it look for the presence of the POWERDOWNFLAG (from
565 linkman:upsmon.conf[5]), using this as an example:
567 --------------------------------------------------------------------------------
569 if (test -f /etc/killpower)
571 echo "Killing the power, bye!"
572 /usr/local/ups/bin/upsdrvctl shutdown
576 # uh oh... the UPS power-off failed
577 # you probably want to reboot here so you don't get stuck!
578 # *** see also the section on power races in the FAQ! ***
581 --------------------------------------------------------------------------------
584 ================================================================================
585 - Be careful that upsdrvctl command will probably power off your machine.
586 Don't use it unless your system is ready to be halted by force.
587 If you run RAID, read the <<_raid_warning,RAID warning>> below!
589 - Make sure the filesystem(s) containing upsdrvctl, ups.conf and your UPS
590 driver(s) are mounted (possibly in read-only mode) when the system gets to this
591 point. Otherwise it won't be able to figure out what to do.
592 ================================================================================
595 [[Testing_shutdowns]]
599 UPS equipment varies from manufacturer to manufacturer and even within
600 model lines. You should test the <<Shutdown_design,shutdown sequence>>
601 on your systems before leaving them unattended. A successful sequence
602 is one where the OS halts before the battery runs out, and the system
603 restarts when power returns.
605 The first step is to see how upsdrvctl will behave without actually turning off
606 power. To do so, use the '-t' argument:
608 /usr/local/ups/bin/upsdrvctl -t shutdown
610 It will display the sequence without actually calling the drivers.
613 You can finally test a forced shutdown sequence (FSD) using:
615 /usr/local/ups/sbin/upsmon -c fsd
617 This will execute a full shutdown sequence, as presented in
618 <<Shutdown_design,Shutdown design>>, starting from the 3rd step.
620 If everything works correctly, the computer will be forcibly powered
621 off, may remain off for a few seconds to a few minutes (depending on
622 the driver and UPS type), then will power on again.
624 If your UPS just sits there and never resets the load, you are vulnerable
625 to a power race and should add the "reboot after timeout" hack at the very
628 Also refer to the section on power races in the link:FAQ.html[FAQ].
630 Using suspend to disk
631 ~~~~~~~~~~~~~~~~~~~~~
633 Support for suspend to RAM and suspend to disk has been available in
634 the Linux kernel for a while now. For obvious reasons, suspending to
635 RAM isn't particularly useful when the UPS battery is getting low,
636 but suspend to disk may be an interesting concept.
638 This approach minimizes the amount of disruption which would be caused
639 by an extended outage. The UPS goes on battery, then reaches low
640 battery, and the system takes a snapshot of itself and halts. Then it
641 is turned off and waits for the power to return.
643 Once the power is back, the system reboots, pulls the snapshot back in,
644 and keeps going from there. If the user happened to be away when it
645 happened, they may return and have no idea that their system actually
646 shut down completely in the middle.
648 In order for this to work, you need to shutdown NUT (UPS driver, upsd
649 server and upsmon client) in the suspend script and start them again in
650 the resume script. Don't try to keep them running. The upsd server
651 will latch the FSD state (so it won't be useable after resuming) and so
652 will the upsmon client. Some drivers may work after resuming, but many
653 don't and some UPS'es will require re-initialization, so it's best not
654 to keep this running either.
656 After stopping driver, server and client you'll have to send the UPS
657 the command to shutdown only if the POWERDOWNFLAG is present. Note
658 that most likely you'll have to allow for a grace period after sending
659 'upsdrvctl shutdown' since the system will still have to take a
660 snapshot of itself after that. Not all drivers support this, so before
661 going down this road, make sure that the one you're using does.
666 If you run any sort of RAID equipment, make sure your arrays are either halted
667 (if possible) or switched to "read-only" mode. Otherwise you may suffer a long
668 resync once the system comes back up.
670 The kernel may not ever run its final shutdown procedure, so you must take care
671 of all array shutdowns in userspace before upsdrvctl runs.
673 If you use software RAID (md) on Linux, get mdadm and try using
674 'mdadm --readonly' to put your arrays in a safe state. This has to
675 happen after your shutdown scripts have remounted the filesystems.
677 On hardware RAID or other kernels, you have to do some detective work. It may
678 be necessary to contact the vendor or the author of your driver to find out
679 how to put the array in a state where a power loss won't leave it "dirty".
681 Our understanding is that most if not all RAID devices on Linux will be fine
682 unless there are pending writes. Make sure your filesystems are remounted
683 read-only and you should be covered.
687 Typical setups for enterprise networks and data rooms
688 -----------------------------------------------------
690 The split nature of this UPS monitoring software allows a wide variety of
691 power connections. This chapter will help you identify how things should
692 be configured using some general descriptions.
694 There are two main elements:
696 1. There's a UPS attached to a communication (serial, USB or network) port on
698 2. This system depends on a UPS for power.
700 You can play "mix and match" with those two to arrive at these descriptions
701 for individual hosts:
707 A small to medium sized data room usually has one C and a bunch of Bs.
708 This means that there's a system (type C) hooked to the UPS which depends
709 on it for power. There are also some other systems in there (type B)
710 which depend on that same UPS for power, but aren't directly connected to
713 Larger data rooms or those with multiple UPSes may have several "clusters"
714 of the "single C, many Bs" depending on how it's all wired.
716 Finally, there's a special case. Type A systems are connected to a UPS's
717 serial port, but don't depend on it for power. This usually happens when
718 a UPS is physically close to a box and can reach the serial port, but
719 the wiring is such that it doesn't actually feed it.
721 Once you identify a system's type, use this list to decide which of the
722 programs need to be run for monitoring:
725 - B: upsmon (as slave)
726 - C: driver, upsd, and upsmon (as master)
728 To further complicate things, you can have a system that is hooked to
729 multiple UPSes, but only depends on one for power. This particular
730 situation makes it an "A" relative to one UPS, and a "C" relative to the
731 other. The software can handle this - you just have to tell it what to do.
733 NOTE: NUT can also serve as a data proxy to increase the number of clients,
734 or share the communication load between several upsd instances.
736 image:images/advanced.png[]
738 If you are running large server-class systems that have more than one
739 power feed, see the next section for information on how to handle it
743 Typical setups for big servers with UPS redundancy
744 --------------------------------------------------
746 By using multiple MONITOR statements in upsmon.conf, you can configure an
747 environment where a large machine with redundant power monitors multiple
750 image:images/bigbox.png[]
752 Example configuration
753 ~~~~~~~~~~~~~~~~~~~~~
755 For the examples in this section, we will use a server with four power supplies
758 Two UPS, 'Alpha' and 'Beta', are each driving two of the power supplies.
759 This means that either 'Alpha' *or* 'Beta' can totally shut down and the
760 server will be able to keep running.
762 The upsmon.conf configuration that reflect this is the following:
764 MONITOR ups-alpha@myhost 2 monuser mypass master
765 MONITOR ups-beta@myhost 2 monuser mypass master
768 With that configuration, upsmon will only shut down when both UPS reaches
769 a critical (on battery + low battery) condition, since 'Alpha' and 'Beta'
770 provide the same power value.
772 As an added bonus, this means you can move a running server from one UPS
773 to another (for maintenance purpose for example) without bringing it down since
774 the minimum power will be provided at all times.
776 The MINSUPPLIES line tells upsmon that we need at least 2 power supplies
777 to be receiving power from a good UPS (on line or on battery, just not
778 on battery and low battery).
780 NOTE: we could have used a 'Power Value' of 1 for both UPS, and MINSUPPLIES
781 set to 1 too. These values are purely arbitrary, so you are free to use your
782 own rules. Here, we have linked these values to the number of power supplies
783 that each UPS is feeding (2).
786 Multiple UPS shutdowns ordering
787 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
789 If you have multiple UPSes connected to your system, chances are that you
790 need to shut them down in a specific order. The goal is to shut down
791 everything but the one keeping upsmon alive at first, then you do that one
794 To set the order in which your UPSes receive the shutdown commands, define
795 the 'sdorder' value in your ups.conf.
812 The order runs from 0 to the highest number available. So, for this
813 configuration, the order of shutdowns would be 'misc', 'littleguy', and then
816 NOTE: If you have a UPS that shouldn't be shutdown when running 'upsdrvctl
817 shutdown', set the *sdorder* to *-1*.
820 Other redundancy configurations
821 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
823 There are a lot of ways to handle redundancy and they all come down to how many
824 power supplies, power cords and independent UPS connections you have. A
825 system with a 1:1 cord:supply ratio has more wires stuffed behind it, but
826 it's much easier to move things around since any given UPS drives a smaller
827 percentage of the overall power.
829 More information can be found in the linkdoc:user-manual[NUT user manual],
830 and the various link:man/index.html[user manual pages].