lud: (Default)
[personal profile] lud
XenServer 6 Auto-Start VMs
In XenServer 6, Citrix made the decision to not include the option anymore to auto-start VM's when the XenServer host boots up. The reason is that this feature interfered with the HA and Failover capabilities, but nonetheless it was a nice feature for situations where only one XenServer host is used.
In XenServer 6 it is possible to auto-start VM's but it requires enabling the auto-start feature at the pool level and on each individual VM by using the CLI which is not very user friendly. Therefore, we have created a script that runs during startup of the host and will start any VM that has been tagged with the "autostart" tag. This allows for easy administration using XenCenter.
In order to install the script,  copy the contents below to the end of the /etc/rc.d/rc.local file on the XenServer host, using for example WinSCP.  Afterwards just tag the VM's you would want to auto-start using the tag "autostart". The VM's will be started with a 20 second delay between each VM.


TAG="autostart" # helper function
function xe_param()
{
PARAM=$1
while read DATA; do
LINE=$(echo $DATA | egrep "$PARAM")
if [ $? -eq 0 ]; then
echo "$LINE" | awk 'BEGIN{FS=": "}{print $2}'
fi
done
} # Get all VMs
sleep 20
VMS=$(xe vm-list is-control-domain=false | xe_param uuid) for VM in $VMS; do
echo "Raido AutoStart Script : Checking VM $VM"
VM_TAGS="$(xe vm-param-get uuid=$VM param-name=tags)" if [[ $VM_TAGS == *$TAG* ]]
then
echo "starting VM $VM"
sleep 20
xe vm-start uuid=$VM
fi done
Update: This script will do the same with vApps. If "autostart" is in the description of a vApp it will start the vApp during boot. Within a vApp you can specify multiple VM's and their boot order.
# AutoStart Vapp's that have autostart in description
# Script created by Raido Consultants - http://www.raido.be 
TAG="autostart"
# helper function
function xe_param()
{
PARAM=$1
while read DATA; do
LINE=$(echo $DATA | egrep "$PARAM")
if [ $? -eq 0 ]; then
echo "$LINE" | awk 'BEGIN{FS=": "}{print $2}'
fi
done
} # Get all Applicances
sleep 20
VAPPS=$(xe appliance-list | xe_param uuid) for VAPP in $VAPPS; do
echo "Raido AutoStart : Checking vApp $VAPP"
VAPP_TAGS="$(xe appliance-param-get uuid=$VAPP param-name=name-description)" if [[ $VAPP_TAGS == *$TAG* ]]
then
echo "starting vApp $VAPP"
xe appliance-start uuid=$VAPP
sleep 20
fi
done
6 comments
Albert wrote 2 months ago:
Hi,
I want use your script but in the 15 line is some error, when I try run this script.
/opt/autostart.sh: line 15: syntax error near unexpected token `do'
/opt/autostart.sh: line 15: `VMS=$(xe vm-list is-control-domain=false | xe_param uuid) for VM in $VMS; do'
Albert wrote 2 months ago:
Ok, I founded where is the problem, you forgot put ;
VMS=$(xe vm-list is-control-domain=false | xe_param uuid);<--- for VM in $VMS; do
echo "Raido AutoStart Script : Checking VM $VM"
VM_TAGS="$(xe vm-param-get uuid=$VM param-name=tags)";<--- if [[ $VM_TAGS == *$TAG* ]];<---
then
Frank Vandebergh wrote 2 months ago:
Hi albert, you are right. Some line breaks are lost when posting it in this blog. the "Do" should start at a new line.
JayKudo wrote 2 months ago:
Doesnt the command '
xe vm-start tags=autostart --multiple
Do the same? Just put that in your rc.local
Nik Stapley wrote 1 month ago:
I can't believe that Citrix have removed such a fundamentally required feature! If anything, I've been hoping since the release of XenServer that Citrix would offer the same auto-start features which ESX have been offering since very early versions; i.e. Autostart these VMs in this order, and these in any order and with staggered pauses as the administrator dictates. Instead Citrix take the auto-start feature away all together, seriously what is going on? If HA really has an issue with it (which it should not) then offer the administrator the option as to whether they enable such a feature or not.
Nicola Busato wrote 2 weeks ago:
I've set a more simple solution, just add to the end of the /etc/rc.d/rc.local file on the XenServer host these 2 lines:
sleep 30
xe vm-start tags=autostart --multiple
Then all VM tagged with "autostart" will automatically boot (tested on XenServer 6.0 with hotfixes XS60E001, XS60E002, XS60E003 and XS60E004)!!
Ciao
Nicola Busato


И второй способ:

Citrix XenServer 6.0 enable VM autostart
Monday, February 6th, 2012
Unlike previous versions, VMs do not have a visible property in the GUI allowing autostart. This has been claimed to collide with the HA function of the licensed version. While I believe there is a more elegant way of doing that (like – ignoring this property if HA is enabled), the following method can allow your free XenServer allow autostart of VMs:
xe pool-param-set uuid=UUID other-config:auto_poweron=true
xe vm-param-set uuid=UUID other-config:auto_poweron=true
Replace the relevant UUID values with the true required value. A small one-liner script to handle the 2nd part (enabling it for the VMs), 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
Cheers



First your going to want to get the UUID of the VM’s you wish to enable auto start on as well as the UUID of the pool these VM’s reside in.To get the list of the pool’s on your XenServer type:

xe pool-list

Copy the UUID of the pool, in my case there ist just one pool. Then issue the following command, and replace the UUID with your pools UUID.

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

Then, at the command prompt of your XenServer type:

xe vm-list

You should get a full list of the VM’s on the server, along with their name and UUID. Copy the UUID of the VM you wish to enable autostart then issue the command below, again replacing the UUID with the UUID of the VM you wish to auto start.

To Auto Start your Pool (replace UUID with the UUID of your Pool):
xe pool-param-set uuid=UUID other-config:auto_poweron=true
To Auto Start your VM (replace the UUID with the UUID of your VM):
xe vm-param-set uuid=UUID other-config:auto_poweron=true

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

And thats it, the next time you ever need to power cycle your main server, the Xen instances should power up automatically.


December 2012

S M T W T F S
      1
2345678
9101112131415
1617181920 2122
23242526272829
3031     

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jul. 26th, 2017 08:38 pm
Powered by Dreamwidth Studios