How to Shutdown Your Servers In Case of Power Failure — UPS, NUT & Co.

Published by Stephan on

At our school there are always power outages. Sometimes they last only a few seconds, sometimes several hours. To ensure that our IT infrastructure does not suffer from this, we have installed a UPS for our servers and network devices. These help to bridge short power outages (up to 1 hour) or fluctuations in current. For any lengthy outages, we automatically shut down our servers when the UPS reaches critical battery level. For this we use NUT (Network UPS Tools).

Our setup consists of the following components:

Set up UPS in NUT on the Raspberry Pi

For the Raspberry Pi we use the standard Raspian Stretch Lite Image. Note that SSH has not been enabled by default since 2016. The different ways to reactivate SSH are documented here. After reactivating SSH, you can now log on to the Raspberry Pi (the IP of the Raspberry Pi can be found out from a computer in the same network with avahi-browse -ar or you can connect a monitor and keyboard). We will need the IP later, so it makes sense to give the Raspberry Pi a static IP.

Next we install the NUT server with

If the UPS is connected via USB (as in our case), you can check with lsusb if it was detected. This is what the output on the Raspberry Pi looks like:

In the first line you can see that our Liebert UPS has been recognized.

Now we have to configure our UPS in the file /etc/nut/ups.conf. For our UPS, the entry looks like this:

On the Network UPS Tools website, you will find a list of all supported UPS and which driver works best.

Next, we want to test whether the settings are correct, the UPS Daemon can communicate with the UPS. For this purpose we start upsd with

A successful output should look something like this:

NUT contains a small program to test the communication with UPS. It is called upsc and outputs all readable UPS parameters.

Now our UPS is successfully installed. Next we set up the NUT server, the UPS monitor upsmon and two more users for the master and the slaves.

Configuring the NUT Server

In /etc/nut/nut/nut.conf we specify that the Raspberry Pi is our master:

The UPS Daemon (upsd) is running on the NUT server. It is responsible for the (physical) connection to UPS. The individual clients/slaves use the upsmon to access the status of the UPS. In this way, multiple clients can always know the status of the UPS and, if necessary, initiate shutdown when UPS delivers the status “On Low Battery”.

In order for our NUT server to be accessible from the net, the following lines have to be added to /etc/nut/upsd.conf (adjust IP please):

Next, we define the users that a client can use to log on to the master (in the file /etc/nut/upsd.user):

In order for upsmon to monitor the UPS, we now need to add a final entry in /etc/nut/upsmon.conf:

In order to know if all services are running correctly, you can check the status of the server and the local clients on the Raspberry Pi (because it should be shut down when there is no more power) with the following commands:

Now our master is set up and the clients or slaves can be configured.

Set up clients/slaves (e. g. server, other computers)

First, the necessary packages must be installed on a client:

This time we only have to edit two files. In /etc/nut/nut/nut.conf we set the mode:

Then we need to tell upsmon which UPS to monitor (in /etc/nut/upsmon.conf):

The IP and password have to be adjusted. Please also note the slave at the end! Finally, restart the corresponding service and check that everything is running:

Congratulations! Now everything should be set up, but how can you test that it really works?

Testing shutdown

The following command triggers the shutdown signal (as it would be in the event of a power failure):


NUT is another great open source project that allows very flexible customizations. This PDF contains many more (complex) application scenarios. While I’m writing this article, we’re out of power again and all our servers have been shut down 🙂

Categories: HowTo



I'm a teacher and IT system administrator in an international school. I love open source software and I used it over a decade in my private and work life. My passion is to solve problems with open source software!


How To Measure Particulate Matter With a Raspberry Pi | Open School Solutions · February 24, 2018 at 8:01 pm

[…] do you use a Raspberry Pi […]

How to update Check_MK | Open School Solutions · March 20, 2018 at 8:01 pm

[…] our IT infrastructure. It is easy to use and we always know the status of our network components, servers, printers, etc. Until now we used the “old-stable” version (1.2.8), but the CPU usage […]

How To Shut Down XenServer automatically With NUT | Open School Solutions · April 21, 2018 at 7:46 pm

[…] and with the help of our UPS we can at least bridge them a little. On our UPS hangs a Raspberry Pi, which is configured as a NUT server. If the power fails and the UPS switches to battery operation, the Raspberry Pi sends a command to […]

Leave a Reply

Your email address will not be published.