apcupsd running on Citrix XenServer 7.0

UPDATE: With huge thanks to reader Nick R, the following will get this same solution up-and-running in XenServer 7.0.

“In Xenserver 7, it is using systemd, so to start apcupsd, it’s: systemctl start apcupsd.service and to have it start at boot, it’s: systemctl enable apcupsd.service

Also, in Xenserver 7, you need the rpm package for Centos7 available here:

Thanks to a very bad Google translation of a German blog post at flurweg.net, I managed to get apcupsd running on Citrix XenServer 6.2 at work without any problems at all, and all was wonderful with the world… right up until I installed the Citrix XenServer 6.5 upgrade over the weekend. That zapped the existing apcupsd installation entirely, and the instructions for 6.2 no longer work for 6.5 (I am guessing because 6.5 has an X64 native dom0 and subtly different dependencies). Information on using apcupsd with XenServer at all is thin on the ground, and 6.5 even less so, so having now “repaired” this, I thought I’d document the changes I had to make from the original flurweg.net post to get apcupsd running on Citrix XenServer 6.5, while at the same time making something written in native English for those that don’t grok Google German.

apcupsd running on Citrix XenServer 6.5

The problem: Citrix XenServer includes no native UPS services or settings.

The Windows solution

From a host with XenCenter installed the following command can be issued to shut down a VM:

xe.exe -s [XenServer IP] -u root -pw [Password] vm-shutdown vm=[VM name]

However, why should we be dependent on a separate Windows system to shut down a VM host system during a power outage??

My conclusion: DON’T if a UPS can operate natively on the VM host (via USB, network or serial connection).

The Linux solution

In Linux, the solution is a cross-platform application called apcupsd that is included in most distributions or can be installed from repository (or source). Too bad it’s not included in XenServer. However, it’s possible to use the official CentOS repository RPM package (Citrix XenServer is based on CentOS 5) and manually install it on XenServer, adjusting the configuration. In this article, I’ll take you through getting the basics (sending out an email notification and shutting everything down in an orderly fashion); very much more is possible.

apcupsd on XenServer, an overview

  • apcupsd, daemon from CentOS
  • apcupsd.conf, custom configuration file that calls vm_shutdown.sh and logs an entry in XenCenter
  • vm_shutdown.sh, shell script that shuts down all VM guests on the XenServer (local VMs if the XenServer is in a pool!!)
  • sendemail, shell application to make sending UP status SMTP emails easy
  • mailconfigs, changeme, commfailure, commok, offbattery, onbattery, sendemail.conf

A TAR file of these items can be downloaded from the original blog post (see point 1 in the installation instructions below).

Apcupsd XenServer Installation Guide (Using TAR File)

  1. Download the TAR file on the XenServer host
    cd ~
    mkdir apc
    cd apc
    wget http://www.flurweg.net/linux/xenserver/apcupsd/xenserver6_apcupsd.tar
    wget http://pkgs.repoforge.org/apcupsd/apcupsd-3.14.10-1.el5.rf.x86_64.rpm
  2. Unzip files
    tar xvf xenserver6_apcupsdl.tar
  3. Install apcupsd
    yum localinstall --nogpgcheck apcupsd-3.14.10-1.el5.rf.x86_64.rpm

    If you get an error Cannot find a valid baseurl for repo: citrix, edit “/etc/yum.repos.d/Citrix.repo” and temporarily disable the repository:
    name=XenServer 6.5.0 updates

    I also had to temporarily enable the default CentOS yum repositories to clear dependencies; edit “/etc/yum.repos.d/CentOS-Base.repo and change all occurrences of enabled=0 to enabled=1.

    Remember to reverse any yum repository changes you made after apcupsd installs.

  4. Backup the distribution configuration files
    mkdir -p /etc/apcupsd/org
    cp /etc/apcupsd/* /etc/apcupsd/org
  5. Copy the new configuration files (answering YES [y] to overwrite)
    cp -f etc/apcupsd/* /etc/apcupsd/
  6. Customize mail settings for your environment
    nano /etc/apcupsd/sendemail.conf
  7. Install sendemail
    cp usr/bin/sendemail /usr/bin
    chmod +x /usr/bin/sendemail
  8. Test email notifications
    sh /etc/apcupsd/changeme
  9. Customise apcupsd settings for your environment (the included configuration is for a Smart-UPS communicating via USB)
    nano /etc/apcupsd/apcupsd.conf
  10. Start apcupsd
    /etc/init.d/apcupsd start

General information about apcupsd

Check UPS communication:

Test/configure the UPS:
/etc/init.d/apcupsd stop
/etc/init.d/apcupsd start

And this is where my take on the original flurweg.net post stops. There is further information in the post, but we’re not using it; YMMV.

twittergoogle_plusby feather

Published by PantsManUK

Twenty-plus years in IT and/or gaming in one form or another. My proudest moment was getting through Jet Pac on the Sinclair Spectrum 48K ;-)

Join the Conversation


  1. Thank you for your help,

    To ease the yum command, you can add : –disablerepo citrix –enablerepo base
    This will reduce the work needed and the chance to do unwanted changes in repository config files.

  2. all good, but:
    /etc/init.d/apcupsd start
    No such file or directory
    Whats is wrong?

    1. Many thanks for the updated information Nick. We’ve not yet upgraded to 7, but it’ll happen at some point. Do you mind if I update the article by posting your comment verbatim?

  3. This works like a freaking, cosy, warm charm on my XenServer 7.0 with the newly bought Smart-UPS C1500VA 2U LCD.

    Thank you so much!

  4. You are the MAN. Wanted to say thanks for this – after hours of screwing around with NUT and hid drivers that don’t work, this saved me and now this UPS is working the right way!

  5. My server hangs on shutdown I have looked at the /var/log/apcupsd.events and it says everything is fine. I would like to turn off the Xenserver splash screen (but that seems to have changed in this version) to see what is halting the proper shutdown any suggestions would be greatly appeciated

Leave a comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Bad Behavior has blocked 550 access attempts in the last 7 days.