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:
https://pkgs.org/centos-7/epel-x86_64/apcupsd-3.14.12-1.el7.x86_64.rpm.html”

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:
    [citrix]
    name=XenServer 6.5.0 updates
    mirrorlist=http://updates.vmd.citrix.com/XenServer/6.5.0/domain0/mirrorlist
    #baseurl=http://updates.vmd.citrix.com/XenServer/6.5.0/domain0/
    gpgcheck=1
    gpgkey=http://updates.vmd.citrix.com/XenServer/RPM-GPG-KEY-6.5.0
    enabled=0

    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:
apcaccess

Test/configure the UPS:
/etc/init.d/apcupsd stop
apctest
/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.

twitterby feather

So… Tangential much?!

Can you upgrade from Windows XP to Windows 7 *without* losing all your programs, settings, etc? Answer to that is “yes, with a but”.

It’s easy enough in principle, you just have to upgrade from Windows XP to Windows Vista, and then you go from Windows Vista to Windows 7. I hope you have (a) a known good full backup, and (b) 48-96 hours to spare, cause neither of those upgrades is likely to be terribly quick on a machine that’s been in use for a good few years.

“Why do you pose the question?”, you might be asking? Well, at work we still have a few machines running XP, and I’m OK with that. Microsoft have shown that even though they don’t support it any more, they are still patching any giant holes (IE anyone?). The only problem is that one of those XP machines is a laptop used by a remote developer, and latest OpenVPN is exhibiting some weird inconsistencies with XP (sometimes won’t connect to Windows network shares, definitely won’t connect to Exchange server, and refuses to post info back to one of our internal web services). I’m in conversation with both OpenVPN and pfSense about it, but I’m thinking the quickest fix might well be to upgrade the laptop in question.

Which brings us to the second option that Microsoft offer us: clean install Windows 7 and reinstall programs, settings, etc. It can be a metric tonne quicker (hour to do a fresh Windows 7 install, and maybe a few hours to reinstall all the truly important programs that the machine in question has), and it will reset any “winrot” that the machine has. Plus, no need to get a copy of Vista (not everyone has access to MSDN).

The decision isn’t mine in this case, but if it were, I know which option I would choose (hint: the quicker one).

twitterby feather

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