Our core infrastructure at the school is secured with a UPS. Unfortunately we always have power failures (mostly short ones) 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 all connected servers after a certain charging status. These then automatically shut down. All our virtual machines, backup systems and servers will be shut down. However, one essential server was still missing: the virtualization host. So today I would like to briefly describe how to shut down XenServer automatically by setting it up as a NUT client.

Installing the NUT Client

XenServer is based on CentOS, but the installation of third-party packages is not allowed. You should also be aware that you may no longer receive support (if you have a support contract) if you install additional packages.

In order to install the NUT client, we have to modify our XenServer 7 in the file /etc/yum.repos.d/CentOS-Base.repo. In the section [extras] we replaced $releaseserver in the line baseurl with a 7.

Then we can set up the Epel Repo and install the NUT client:

Now let’s see which package provides our NUT client and install it:

NUT Client Setup

Now that the NUT client is installed, we need to configure it so that our XenServer shuts down in case of power failure. First we have to create a file to tell NUT that our XenServer is a client:

The main configuration takes place in the file /etc/ups/upsmon.conf. There we change two lines:

Depending on the configuration of the NUT master, the UPS name, the IP, as well as the user name and password must still be adapted here.

Before our XenServer shuts down, it must switch off all virtual machines first. I found the following script, which we download and make executable.

So that the NUT client also starts automatically, we still have to set up a systemd service. We create the file /etc/systemd/system/nut-monitor.service and insert the following content:

Now we activate this service and start it:

With systemctl status nut-monitor we can see if everything is running:

Testing Automatic Shutdown

First we can test the script to shut down the XenServer and see if all started VMs are shut down. To do this, we simply execute the script:

To simulate a power failure and we can issue the following command on the NUT Master:

After that you have to switch on all devices manually or wake them up via Wake-on-Lan.

Conclusion

NUT is a great project and it allows us very flexible scenarios. Currently we have only one large UPS connected to the NUT Master, but it is also conceivable to connect several UPS to the NUT Master. In combination with Check_MK we can constantly monitor the status of the UPS and also get statistics on how often the power has failed.

Categories: HowTo

Stephan

Stephan

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!

Leave a Reply

Your email address will not be published. Required fields are marked *