Hi,
On Wed, May 20, 2020 12:28 pm, Gianluca Cecchi wrote:
Il Mer 20 Mag 2020, 18:15 Derek Atkins <derek(a)ihtfp.com> ha
scritto:
[snip]
I am happy to share my startup script if someone else wants to port it to
> work with 4.4. :-)
>
> -derek
>
Interesting. yes, please.
We could try to convert to python or through ansible and/or leverage
already existing roles/modules.
Gianluca
Sure,
I cannot attach the script because it will get blocked by the mailer, so
I'll just copy-and-paste it below (which of course means that it'll be
line-wrapped, which might break it but you'll at least see what it's
doing).
The script does have some embedded assumptions about my system (like the
number of storage domains to look for).
It's broken into two parts, the script itself (start_vms.sh) and a
sysconfig script that says what VMs to start. I run start_vms.sh from
/etc/rc.d/rc.local:
/usr/local/sbin/start_vms.sh > /var/log/start_vms 2>&1 &
The /etc/sysconfig/vm_list file looks like:
default_timeout=10
# Ordered list of VMs
declare -a vm_list=(
first-vm
second-vm
)
# Timeout override (otherwise use default_timeout)
declare -A vm_timeout=(
[first-vm]=30
)
The start_vms.sh script itself:
#!/bin/bash
[ -f /etc/sysconfig/vm_list ] || exit 0
. /etc/sysconfig/vm_list
echo -n "Starting at "
date
# Wait for the engine to respond
while [ `ovirt-shell -I -c -F -T 50 -E ping 2>/dev/null | grep -c success`
!= 1 ]
do
echo "Not ready... Sleeping..."
sleep 60
done
# Now wait for the storage domain to appear active
echo -n "Engine up. Searching for disks at " ; date
# The 4.3.x engine keeps stale data, so let's wait for it to update
# to the correct state before we start looking for storage domains
sleep 60
total_disks=`ovirt-shell -I -c -E summary | grep storage_domains-total |
sed -e 's/.*: //'`
# subtract one because we know we're not using the image-repository
total_disks=`expr $total_disks - 1`
active_disks=`ovirt-shell -I -c -E summary | grep storage_domains-active |
sed -e 's/.*: //'`
while [ $active_disks -lt $total_disks ]
do
echo "Storage Domains not active yet. Only found
$active_disks/$total_disks. Waiting..."
sleep 60
active_disks=`ovirt-shell -I -c -E summary | grep
storage_domains-active | sed -e 's/.*: //'`
done
# Now wait for the data center to show up
echo -n "All storage mounted. Waiting for datacenter to be up at "
date
while [ `ovirt-shell -I -c -E 'show datacenter Default' | grep
status-state | sed -e 's/.*: //'` != 'up' ]
do
echo "Not ready... Sleeping..."
sleep 60
done
# Now start all of the VMs in the requested order.
echo -n "Datacenter up. Starting VMs at "; date
for vm in "${vm_list[@]}"
do
timeout=${vm_timeout[$vm]:-$default_timeout}
ovirt-shell -I -c -E "action vm $vm start"
sleep "$timeout"
done
Enjoy!
-derek
--
Derek Atkins 617-623-3745
derek(a)ihtfp.com
www.ihtfp.com
Computer and Internet Security Consultant