|
|
aba6ec |
diff --git a/heartbeat/VirtualDomain b/heartbeat/VirtualDomain
|
|
|
aba6ec |
index b159c2c..3a6b6a9 100755
|
|
|
aba6ec |
--- a/heartbeat/VirtualDomain
|
|
|
aba6ec |
+++ b/heartbeat/VirtualDomain
|
|
|
aba6ec |
@@ -21,11 +21,13 @@ OCF_RESKEY_force_stop_default=0
|
|
|
aba6ec |
OCF_RESKEY_autoset_utilization_cpu_default="true"
|
|
|
aba6ec |
OCF_RESKEY_autoset_utilization_hv_memory_default="true"
|
|
|
aba6ec |
OCF_RESKEY_migrateport_default=$(( 49152 + $(ocf_maybe_random) % 64 ))
|
|
|
aba6ec |
+OCF_RESKEY_CRM_meta_timeout_default=90000
|
|
|
aba6ec |
|
|
|
aba6ec |
: ${OCF_RESKEY_force_stop=${OCF_RESKEY_force_stop_default}}
|
|
|
aba6ec |
: ${OCF_RESKEY_autoset_utilization_cpu=${OCF_RESKEY_autoset_utilization_cpu_default}}
|
|
|
aba6ec |
: ${OCF_RESKEY_autoset_utilization_hv_memory=${OCF_RESKEY_autoset_utilization_hv_memory_default}}
|
|
|
aba6ec |
: ${OCF_RESKEY_migrateport=${OCF_RESKEY_migrateport_default}}
|
|
|
aba6ec |
+: ${OCF_RESKEY_CRM_meta_timeout=${OCF_RESKEY_CRM_meta_timeout_default}}
|
|
|
aba6ec |
#######################################################################
|
|
|
aba6ec |
|
|
|
aba6ec |
## I'd very much suggest to make this RA use bash,
|
|
|
aba6ec |
@@ -165,8 +167,8 @@ Restore state on start/stop
|
|
|
aba6ec |
</parameters>
|
|
|
aba6ec |
|
|
|
aba6ec |
<actions>
|
|
|
aba6ec |
-<action name="start" timeout="90" />
|
|
|
aba6ec |
-<action name="stop" timeout="90" />
|
|
|
aba6ec |
+<action name="start" timeout="$OCF_RESKEY_CRM_meta_timeout_default" />
|
|
|
aba6ec |
+<action name="stop" timeout="$OCF_RESKEY_CRM_meta_timeout_default" />
|
|
|
aba6ec |
<action name="status" depth="0" timeout="30" interval="10" />
|
|
|
aba6ec |
<action name="monitor" depth="0" timeout="30" interval="10" />
|
|
|
aba6ec |
<action name="migrate_from" timeout="60" />
|
|
|
aba6ec |
@@ -183,9 +185,17 @@ set_util_attr() {
|
|
|
aba6ec |
local cval outp
|
|
|
aba6ec |
|
|
|
aba6ec |
cval=$(crm_resource -Q -r $OCF_RESOURCE_INSTANCE -z -g $attr 2>/dev/null)
|
|
|
aba6ec |
+ if [ $? -ne 0 ] && [ -z "$cval" ]; then
|
|
|
aba6ec |
+ crm_resource -Q -r $OCF_RESOURCE_INSTANCE -z -g $attr 2>&1 | grep -e "not connected" > /dev/null 2>&1
|
|
|
aba6ec |
+ if [ $? -eq 0 ]; then
|
|
|
aba6ec |
+ ocf_log debug "Unable to set utilization attribute, cib is not available"
|
|
|
aba6ec |
+ return
|
|
|
aba6ec |
+ fi
|
|
|
aba6ec |
+ fi
|
|
|
aba6ec |
+
|
|
|
aba6ec |
if [ "$cval" != "$val" ]; then
|
|
|
aba6ec |
- outp=`crm_resource -r $OCF_RESOURCE_INSTANCE -z -p $attr -v $val 2>&1` ||
|
|
|
aba6ec |
- ocf_log warn "crm_resource failed to set utilization attribute $attr: $outp"
|
|
|
aba6ec |
+ outp=$(crm_resource -r $OCF_RESOURCE_INSTANCE -z -p $attr -v $val 2>&1) ||
|
|
|
aba6ec |
+ ocf_log warn "crm_resource failed to set utilization attribute $attr: $outp"
|
|
|
aba6ec |
fi
|
|
|
aba6ec |
}
|
|
|
aba6ec |
|
|
|
aba6ec |
@@ -193,22 +203,49 @@ update_utilization() {
|
|
|
aba6ec |
local dom_cpu dom_mem
|
|
|
aba6ec |
|
|
|
aba6ec |
if ocf_is_true "$OCF_RESKEY_autoset_utilization_cpu"; then
|
|
|
aba6ec |
- dom_cpu=$(LANG=C virsh $VIRSH_OPTIONS dominfo ${DOMAIN_NAME} | awk '/CPU\(s\)/{print $2}')
|
|
|
aba6ec |
+ dom_cpu=$(LANG=C virsh $VIRSH_OPTIONS dominfo ${DOMAIN_NAME} 2>/dev/null | awk '/CPU\(s\)/{print $2}')
|
|
|
aba6ec |
test -n "$dom_cpu" && set_util_attr cpu $dom_cpu
|
|
|
aba6ec |
fi
|
|
|
aba6ec |
if ocf_is_true "$OCF_RESKEY_autoset_utilization_hv_memory"; then
|
|
|
aba6ec |
- dom_mem=$(LANG=C virsh $VIRSH_OPTIONS dominfo ${DOMAIN_NAME} | awk '/Max memory/{printf("%d", $3/1024)}')
|
|
|
aba6ec |
+ dom_mem=$(LANG=C virsh $VIRSH_OPTIONS dominfo ${DOMAIN_NAME} 2>/dev/null | awk '/Max memory/{printf("%d", $3/1024)}')
|
|
|
aba6ec |
test -n "$dom_mem" && set_util_attr hv_memory "$dom_mem"
|
|
|
aba6ec |
fi
|
|
|
aba6ec |
}
|
|
|
aba6ec |
|
|
|
aba6ec |
+get_emulator()
|
|
|
aba6ec |
+{
|
|
|
aba6ec |
+ local emulator=""
|
|
|
aba6ec |
+
|
|
|
aba6ec |
+ emulator=$(virsh $VIRSH_OPTIONS dumpxml $DOMAIN_NAME 2>/dev/null | sed -n -e 's/[[:space:]]*<emulator>\(.*\)<\/emulator>[[:space:]]*$/\1/p')
|
|
|
aba6ec |
+ if [ -z "$emulator" ] && [ -a "$EMULATOR_STATE" ]; then
|
|
|
aba6ec |
+ emulator=$(cat $EMULATOR_STATE)
|
|
|
aba6ec |
+ fi
|
|
|
aba6ec |
+ if [ -z "$emulator" ]; then
|
|
|
aba6ec |
+ emulator=$(cat ${OCF_RESKEY_config} | sed -n -e 's/[[:space:]]*<emulator>\(.*\)<\/emulator>[[:space:]]*$/\1/p')
|
|
|
aba6ec |
+ fi
|
|
|
aba6ec |
+
|
|
|
aba6ec |
+ if [ -n "$emulator" ]; then
|
|
|
aba6ec |
+ basename $emulator
|
|
|
aba6ec |
+ else
|
|
|
aba6ec |
+ ocf_log error "Unable to determine emulator for $DOMAIN_NAME"
|
|
|
aba6ec |
+ fi
|
|
|
aba6ec |
+}
|
|
|
aba6ec |
+
|
|
|
aba6ec |
+update_emulator_cache()
|
|
|
aba6ec |
+{
|
|
|
aba6ec |
+ local emulator
|
|
|
aba6ec |
+
|
|
|
aba6ec |
+ emulator=$(get_emulator)
|
|
|
aba6ec |
+ if [ -n "$emulator" ]; then
|
|
|
aba6ec |
+ echo $emulator > $EMULATOR_STATE
|
|
|
aba6ec |
+ fi
|
|
|
aba6ec |
+}
|
|
|
aba6ec |
+
|
|
|
aba6ec |
# attempt to check domain status outside of libvirt using the emulator process
|
|
|
aba6ec |
pid_status()
|
|
|
aba6ec |
{
|
|
|
aba6ec |
local rc=$OCF_ERR_GENERIC
|
|
|
aba6ec |
- local emulator
|
|
|
aba6ec |
-
|
|
|
aba6ec |
- emulator=$(basename $(egrep '[[:space:]]*<emulator>.*</emulator>[[:space:]]*$' ${OCF_RESKEY_config} | sed -e 's/[[:space:]]*<emulator>\(.*\)<\/emulator>[[:space:]]*$/\1/'))
|
|
|
aba6ec |
+ local emulator=$(get_emulator)
|
|
|
aba6ec |
|
|
|
aba6ec |
case "$emulator" in
|
|
|
aba6ec |
qemu-kvm|qemu-system-*)
|
|
|
aba6ec |
@@ -237,13 +274,13 @@ VirtualDomain_Status() {
|
|
|
aba6ec |
status="no state"
|
|
|
aba6ec |
while [ "$status" = "no state" ]; do
|
|
|
aba6ec |
try=$(($try + 1 ))
|
|
|
aba6ec |
- status=$(virsh $VIRSH_OPTIONS domstate $DOMAIN_NAME 2>&1|tr 'A-Z' 'a-z')
|
|
|
aba6ec |
+ status=$(virsh $VIRSH_OPTIONS domstate $DOMAIN_NAME 2>&1 | tr 'A-Z' 'a-z')
|
|
|
aba6ec |
case "$status" in
|
|
|
aba6ec |
*"error:"*"domain not found"*|"shut off")
|
|
|
aba6ec |
# shut off: domain is defined, but not started, will not happen if
|
|
|
aba6ec |
# domain is created but not defined
|
|
|
aba6ec |
# Domain not found: domain is not defined and thus not started
|
|
|
aba6ec |
- ocf_log debug "Virtual domain $DOMAIN_NAME is currently $status."
|
|
|
aba6ec |
+ ocf_log debug "Virtual domain $DOMAIN_NAME is not running: $(echo $status | sed s/error://g)"
|
|
|
aba6ec |
rc=$OCF_NOT_RUNNING
|
|
|
aba6ec |
;;
|
|
|
aba6ec |
running|paused|idle|blocked|"in shutdown")
|
|
|
aba6ec |
@@ -282,12 +319,13 @@ VirtualDomain_Status() {
|
|
|
aba6ec |
# again, relying on the CRM/LRM to time us out if
|
|
|
aba6ec |
# this takes too long.
|
|
|
aba6ec |
ocf_log info "Virtual domain $DOMAIN_NAME currently has no state, retrying."
|
|
|
aba6ec |
- sleep 1
|
|
|
aba6ec |
fi
|
|
|
aba6ec |
+ sleep 1
|
|
|
aba6ec |
;;
|
|
|
aba6ec |
*)
|
|
|
aba6ec |
# any other output is unexpected.
|
|
|
aba6ec |
ocf_log error "Virtual domain $DOMAIN_NAME has unknown status \"$status\"!"
|
|
|
aba6ec |
+ sleep 1
|
|
|
aba6ec |
;;
|
|
|
aba6ec |
esac
|
|
|
aba6ec |
done
|
|
|
aba6ec |
@@ -295,7 +333,7 @@ VirtualDomain_Status() {
|
|
|
aba6ec |
}
|
|
|
aba6ec |
|
|
|
aba6ec |
verify_undefined() {
|
|
|
aba6ec |
- for dom in `virsh --connect=${OCF_RESKEY_hypervisor} list --all --name`; do
|
|
|
aba6ec |
+ for dom in `virsh --connect=${OCF_RESKEY_hypervisor} list --all --name 2>/dev/null`; do
|
|
|
aba6ec |
if [ "$dom" = "$DOMAIN_NAME" ]; then
|
|
|
aba6ec |
virsh $VIRSH_OPTIONS undefine $DOMAIN_NAME > /dev/null 2>&1
|
|
|
aba6ec |
return
|
|
|
aba6ec |
@@ -340,6 +378,7 @@ VirtualDomain_Start() {
|
|
|
aba6ec |
while ! VirtualDomain_Monitor; do
|
|
|
aba6ec |
sleep 1
|
|
|
aba6ec |
done
|
|
|
aba6ec |
+
|
|
|
aba6ec |
return $OCF_SUCCESS
|
|
|
aba6ec |
}
|
|
|
aba6ec |
|
|
|
aba6ec |
@@ -530,6 +569,7 @@ VirtualDomain_Monitor() {
|
|
|
aba6ec |
done
|
|
|
aba6ec |
fi
|
|
|
aba6ec |
|
|
|
aba6ec |
+ update_emulator_cache
|
|
|
aba6ec |
update_utilization
|
|
|
aba6ec |
|
|
|
aba6ec |
return ${rc}
|
|
|
aba6ec |
@@ -582,7 +622,7 @@ case $1 in
|
|
|
aba6ec |
esac
|
|
|
aba6ec |
|
|
|
aba6ec |
# Grab the virsh uri default, but only if hypervisor isn't set
|
|
|
aba6ec |
-: ${OCF_RESKEY_hypervisor=$(virsh --quiet uri)}
|
|
|
aba6ec |
+: ${OCF_RESKEY_hypervisor=$(virsh --quiet uri 2>/dev/null)}
|
|
|
aba6ec |
|
|
|
aba6ec |
# Set options to be passed to virsh:
|
|
|
aba6ec |
VIRSH_OPTIONS="--connect=${OCF_RESKEY_hypervisor} --quiet"
|
|
|
aba6ec |
@@ -608,6 +648,8 @@ if [ -z $DOMAIN_NAME ]; then
|
|
|
aba6ec |
exit $OCF_ERR_GENERIC
|
|
|
aba6ec |
fi
|
|
|
aba6ec |
|
|
|
aba6ec |
+EMULATOR_STATE="${HA_RSCTMP}/VirtualDomain-${DOMAIN_NAME}-emu.state"
|
|
|
aba6ec |
+
|
|
|
aba6ec |
case $1 in
|
|
|
aba6ec |
start)
|
|
|
aba6ec |
VirtualDomain_Start
|