Performing automated shutdown during a power failure using a USB-UPS with NUT - XCP-ng 8.2
-
Hey there,
I have a very specific question:
Is there a way to get PowerChute running on a XCP-ng Host? I already found this article from Citrix:
https://support.citrix.com/article/CTX119910
and this from APC:
https://www.apc.com/us/en/faqs/FA159764/The problem is I don't have a Network Management Card installed or the possibility of adding one. I'm dependent on a USB Connection. So I was wondering how I can configure a shutdown of all VMs and the Host with a USB Connection? It's important for me to understand the process. Do I need an seperate PC to manage this? Is there a solution with USB passthrough and one VM executes a shutdown script on the Host? I would be thankful on some help/related articles or anything you can give me to figure it out myself.
I'm running on XCP-ng Version 8.2 an I have a APC Back-UPS 700.
-
I found this post:
https://voice1.me/automated-shutdown-xenserver-7-x-with-network-ups-tool/I just used the Driver type for USB: usbhid-ups
You can find the correct driver type for your system here:
https://networkupstools.org/stable-hcl.htmlHere is the guide for USB (partly copied from the article):
IMPORTANT: The way I made is is not recommend! Your pfSense should normally not run on a VM using this method but it still works. It's recommended to use a physical pfSense to perform this setup.
Requirement:
- a VM running pfSense
- all VMs on your XCP-ng host have to run guest gtilities.
- a USP with USB Connection
- XCP-ng Center
- Connecting the USP to a VM via USB
- Plug-in the USP via USB into the Server
- Enable USB-passthrough in the USB Tab of your Host (XCP-ng Center)
- Shutdown the pfSense, attach the USB device to the pfSense VM in the Properties Tab of the VM
- Start the VM
- Installing NUT
If you are using pfSense, you can install nut from the Package Manager. Once installed you will be able to access the setup from Services > UPS.
- Select “Local USB” from the UPS Type and provide a UPS Name.
- add this to your uspd.conf:
ACL all 0.0.0.0/0 ACCEPT all
- add this to your uspd.users:
[(YOUR USERNAME)] password = (YOUR PASSWORD) allowfrom = all instcmds = ALL
Attention! The username has to be written with the brackets! ie: [admin]
- click on save and pfSense should now detect your UPS and give you its information in the UPS Dashboard.
- Configure the XCP-ng host as NUT slave (pfSense is master)
- By default the built in repository does not have the required library, so we need to enable the epel repository before we can install the nut-client
yum --enablerepo=* install epel-release yum --enablerepo=* install nut-client.x86_64
- Now we need to tell NUT that we want it to listen to an existing NUT Server, in other words, we want to be a “client”.
nano /etc/ups/nut.conf MODE=netclient
- Now that NUT knows it will be retrieving information from another network server, we need to tell it what network server to “MONITOR”. You will need to modify only 2 variables in the file /etc/ups/upsmon.conf but take a look around because you can tweak how the NUT Client responds by modifying the settings in this file. For now, lets just tell NUT where to retrieve its information from.
nano /etc/ups/upsmon.conf MONITOR (NAME OF YOUR UPS)@(PFSENSE IP) 1 (USERNAME) (PASSWORD) slave SHUTDOWNCMD "/etc/ups/xen-shutdown.sh"
- You probably already have a SHUTDOWNCMD in your configuration Just add a comment “#” to the start of the line and add the one provided above. Speaking of the SHUTDOWNCMD, you will notice that we are calling a specific script. This script can be downloaded here.
cd /etc/ups wget https://raw.githubusercontent.com/serrc-techops/NUT-Configuration/master/slave/xen/xen-shutdown.sh chmod +x xen-shutdown.sh
!!! I wasn't able to perform the next step because the service started to fail afterwards!!!
The shutdown still works. I try to figure out a solution and add it here.So on a power failure, the NUT Master sends a message to all subscribed NUT Clients, and the NUT Client shuts down based on its configuration. Wonderful Now our Xen Guests can shutdown, and so can our server. But what happens when we power them back up? We need to make sure that NUT starts on our XenServer.
- To do so create a new file, /etc/systemd/system/nut-monitor.service and add the following to it.
[Unit] Description=Network UPS Tools - XenServer Shutdown After=local-fs.target network.target [Service] ExecStart=/usr/sbin/upsmon PIDFile=/run/nut/upsmon.pid Type=forking [Install] WantedBy=multi-user.target
Now that we have a system startup script in place, lets make sure it runs on start up.
systemctl enable nut-monitor.service systemctl daemon-reload systemctl start nut-monitor
- Testing shutdown
- Execute this command in the Shell of your pfSense:
This will simulate a power cut!!!
upsmon -c fsd
If you have any questions ask me below.
There is one problem: you have to reattach the USB to the VM after every host reboot!
-
@hannes_5253 Any reason for not prefering to run the NUT server directly on the XCP-NG host ?
-
@peek said in Performing automated shutdown during a power failure using a USB-UPS with NUT - XCP-ng 8.2:
@hannes_5253 Any reason for not prefering to run the NUT server directly on the XCP-NG host ?
I didn't got it with the Host, maybe I'm too stupid.
-
I'm using XCP-ng and except for requiring the testing repo, (specifically only for NUT), it's working perfectly. The package name is a bit "non-standard".
yum --enablerepo=* install nut.x86_64
The UPS is connected over USB and on a power failure, the hypervisor shuts all the VMs gracefully down with a simple "shutdown -h +0" specified in upsmon.conf.
-
@hannes_5253
This is a failure re getting usb pass through on boot up of VM correctly.
We use GPS usb devices for time keeping and despite hacking the various files (overridden on upgrades/patches etc) this issue has never been resolved despite comments on this board.UPS & GPS support is important for obvious reasons, and needs an educated review into the problem.
We moved our UPS to a NetBsd server (not a VM, a separate system) and used NUT (added outside the tight xcp-nt regime) to
provide the essential power loss situation of the hypervisors.Same with GPS, hosted on same BSD system.
-
@peek Thanks for the answer! I did this. I have to take another look at the configuration.
-
@aimdev thanks for the information!
-
@peek said in Performing automated shutdown during a power failure using a USB-UPS with NUT - XCP-ng 8.2:
yum --enablerepo=* install nut.x86_64
This video solved it for me (altough its in german)
YouTube TutThread can be closed.
-
Would you mind posting exactly the steps you did to make it work? That might be really helpful for the community
(and maybe pushed to our official doc at some point!)
-
I was able to make NUT work with XCP-NG. I used and followed the instructions in this post.
On issuing the command:
[21:56 xenserver1 ups]# ./xen-shutdown.sh
All VMs shutdown EXCEPT for the Xen Orchestra. I tried remove and reinstall Xen Tools
apt install xe-guest-utilities
I'm on Ubuntu 18.04
Is there something that should be done with Xen Orchestra? Like I said, all other VMs shutdown quickly and properly. I only have Ubuntu 18.04 and one instance of FreePBX. FreePBX shutdown properly too.
Update: it seems that after 5-10 minutes (not sure yet as I haven't timed it), the entire XCP-NG does shutdown but not sure if it was a forced of graceful shutdown on the VM running XO.