Autostart VM in free version of XenServer 6.x

Unlike previous versions, VMs do not have a visible property in the GUI allowing autostart, which kinda sucks big time. This has been claimed to interfere with High Availability (HA) and produced unexpected results during HA functions.

So, what we are going to do?!

First approach is to set auto_poweron parameter to true at the pool and VM level.

Setting the XenServer to allow Auto-Start
1. Gather the UUID’s of the pools you wish to auto-start.
To get the list of the pool’s on your XenServer type

xe pool-list

2. Copy the UUID of the pool. If you have just one server, it will still have a pool UUID as bellow:

uuid ( RO)                : d170d718-e0de-92fc-b920-f4c59cc62e91
          name-label ( RW):
    name-description ( RW):
              master ( RO): 755d4ea3-373b-44b9-8ae3-3cd6f77a7f33
          default-SR ( RW): 51218f44-6ac6-4893-98fb-f924b08f7af9

3. Set the pool or server to allow auto-start:

xe pool-param-set uuid=UUID other-config:auto_poweron=true

Note: *Replacing UUID with the UUID of the XenServer or pool.

Setting the Virtual Machines to Auto-Start
1. Gather the UUID’s of the Virtual Machine you want to auto-start by typing:

xe vm-list

Note: This generates a list of Virtual Machines in your pool or server and their associated UUID’s.

2. Copy the UUID of the Virtual Machines you want to auto-start, and type the following command for each Virtual Machine to auto-start:

xe vm-param-set uuid=UUID other-config:auto_poweron=true

Note: *Replace UUID with the UUID of the Virtual Machine to auto-start.*

For this second part (enabling auto-start for the VMs) we can use a little one-line script, which would enable autostart for ALL vms:

for i in `xe vm-list is-control-domain=false –minimal | tr , ‘  ’`; do xe vm-param-set uuid=$i other-config:auto_poweron=true; done

Edit rc.local file to start all vms with "auto_poweron" in their other-config

Add the following lines at the end of /etc/rc.local file:

[ -e /proc/xen ] || exit 0

XAPI_START_TIMEOUT_SECONDS=240

# wait for xapi to complete initialisation for a max of XAPI_START_TIMEOUT_SECONDS
/opt/xensource/bin/xapi-wait-init-complete ${XAPI_START_TIMEOUT_SECONDS}

if [ $? -eq 0 ]; then

pool=$(xe pool-list params=uuid --minimal 2> /dev/null)

auto_poweron=$(xe pool-param-get uuid=${pool} param-name=other-config param-key=auto_poweron 2> /dev/null)
if [ $? -eq 0 ] && [ "${auto_poweron}" = "true" ]; then
logger "$0 auto_poweron is enabled on the pool-- this is an unsupported configuration."

# if xapi init completed then start vms (best effort, don't report errors)
xe vm-start other-config:auto_poweron=true power-state=halted --multiple >/dev/null 2>/dev/null || true
fi
fi

Second approach is to use vApp

1. Create vApp
2. Choose vms to vApp
3. Choose boot order and delays between starts
4. To get uuid of vApp use:

xe appliance-list name-label="name-vapp"

5. Edit rc.local file to start vApp:

echo "sleep 40" >> /etc/rc.local
echo "xe appliance-start uuid=uuid-vapp" >> /etc/rc.local

7. Save file, reboot XenServer

Links:
http://support.citrix.com/article/CTX133910
http://run.tournament.org.il/citrix-xenserver-6-0-enable-vm-autostart/
http://blog.wallenqvist.se/2012/06/04/371/
http://forums.citrix.com/message.jspa?messageID=1677077#1677077
https://github.com/xen-org/xen-api/tree/master/scripts

4 thoughts on “Autostart VM in free version of XenServer 6.x”

  1. hello, is there a way to check if autostart is enabled on a VM? i’ve used all commands above, but i don’t know if all VM have autostart enabled or not…

    thanks

Leave a Reply

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