Automated XenServer host & VM shutdown

A client is currently implementing Citrix XenServer 5.0 and had hit a snag trying to get the new XenServer hosts communicating with their APC UPS. They had read How to Integrate XenServer and APC PowerChute but the example given is very basic and not dynamic; the script needs to know the pool master and the names of all your VMs. But the script was a great starting point and with the XenServer CLI documentation I was able to create a dynamic shutdown script.

The script runs on a physical box with XenCenter (or at least with the command line xe tool). A username, password and two XenServer IP addresses are specified in the script. Why two XenServer IPs? In case the first XenServer is down/has changed IP etc – a basic fall back plan. When the script runs it disables all hosts in the pool, shutsdown all the VMs in the pool and finally shutsdown all the hosts in the pool.

For this particular client they have the APC software installed on the same physical box as XenCenter and have configured the software to run this script when the UPS reaches a critical level.

Download the script here and use as you please – just leave my details at the top.

10 Comments

  1. Jason,

    Thank you for such a nice script to shutdown the XenServer VMs and Host. This worked without an issue on the first try.

    I was wondering if you could help me out by giving me some pointers how I could get this script to shutdown multiple XenServers VMs and Hosts.

    Thanks again.

  2. Jason Poyner says:

    Hi Craig,

    The script will shutdown all VMs and all XenServer hosts in a resource pool. Is this the functionality you are after?

  3. Jason,

    Yes, that is what I was looking for. I am migrating all my VMs from VMware to XenServer. I have now created a resource pool with the host machines inside and your script is shutting down all the VMs and Hosts gracefully.

    Thanks again for your script!

  4. Codevark says:

    A great script. Thanks for the work!! This would have SMA last weekend when our building lost power and everything flailed horribly.

  5. Fredrik says:

    Looks greate, but if one have multiple pools one would need one version of the script per pool?

  6. Babul Miah says:

    Excellent script. Thank you very much for sharing.
    I was wondering if you could tell us how one could add a line or two of codes to:
    (1) check if the pool has HA enabled and
    (2) if it does then temporarily disable it.
    This is because xenserver otherwise would not allow shutting down the VMs and Hosts?
    Thank you once again.

  7. Azhar Ahmed says:

    Dear Sir,

    Please help me about Xen Server….Because i face some issue and doesnot perform in this task….

    1. Schedule set of Shutdown on Xen Server.
    2. Schedule set of Start and Shutdown on VM Xen Sever.
    3. Schedule set of VM Backup of Xen server.

  8. Holger says:

    Ladies and Gentlemen, this script was exactly what I was looking for, many many thanks for that. I have a xenserver 7. how small is the world thanks to the internet. Best greetings from germany holgi

  9. Sandro says:

    Seems very good. Thanks for making it available.

Leave a Reply

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

Contact Deptive

Location
Level 13 (Regus)
92 Albert St
Auckland
We also have a virtual office in Wellington.

Contact Details

0800 000 141

Postal Address
PO Box 34797,
Birkenhead, Auckland 0746