fix(libvirt): match hook with changes made to manage vnc pipes

main
Tsu-ba-me 1 year ago committed by Yanhao Lei
parent f45a49dc11
commit 8b741eb04a
  1. 86
      libvirt/hooks/qemu.d/ws

@ -4,52 +4,40 @@
# operations, i.e., started, stopped. # operations, i.e., started, stopped.
# #
# TODO: re-enable after the possible libvirt deadlock is fixed. function log {
exit 0 echo "$(date -Is):libvirt_hooks:ws; $@" >>/var/log/anvil.log;
}
{
echo "wsargs=$@" log "wsargs=$@"
domain_xml=$(</dev/stdin) domain_xml=$(</dev/stdin)
guest_name="$1" guest_name="$1"
operation="$2" operation="$2"
# Operation migrate will: # Operation migrate will:
# 1. Trigger migrate->prepare->start->started operation on the destination host. # 1. Trigger migrate->prepare->start->started operation on the destination host.
# 2. Trigger stopped->release operations on the source host. # 2. Trigger stopped->release operations on the source host.
if [[ "$operation" == "started" || "$operation" == "stopped" ]] if [[ ! $operation =~ ^(started|stopped)$ ]]
then then
ws_open_flag="" exit
ws_port_flag="" fi
ws_suuid_flag=""
ws_open_flag=""
if [[ "$operation" == "started" ]] ws_port_flag=""
then
ws_open_flag="--open" if [[ $operation == "started" ]]
then
# Cannot call $ virsh vncdisplay... because libvirt hooks ws_open_flag="--open"
# cannot call anything related to libvirt, i.e., virsh, because
# a deadlock will happen. # Cannot call $ virsh vncdisplay... because libvirt hooks
server_vnc_port=$( grep "<graphics.*type=['\"]vnc['\"]" <<<$domain_xml | grep -oPm1 "(?<=port=['\"])\d+" ) # cannot call anything related to libvirt, i.e., virsh, because
ws_port_flag="--server-vnc-port ${server_vnc_port}" # a deadlock will happen.
server_vnc_port=$( grep "<graphics.*type=['\"]vnc['\"]" <<<$domain_xml | grep -oPm1 "(?<=port=['\"])\d+" )
server_uuid=$( grep -oPm1 "(?<=<uuid>)[^\s]+(?=<)" <<<$domain_xml ) ws_port_flag="--server-vnc-port ${server_vnc_port}"
ws_suuid_flag="--server-uuid ${server_uuid}" fi
local_host_uuid=$(</etc/anvil/host.uuid) ws_command_args="--server \"$guest_name\" $ws_port_flag $ws_open_flag"
update_sql="UPDATE servers SET server_host_uuid = '$local_host_uuid' WHERE server_name = '$guest_name';" log "wscmd=$ws_command_args"
echo "wsupdate=$update_sql"
anvil-access-module --query "$update_sql" --mode write striker-manage-vnc-pipes $ws_command_args &
fi
ws_command_args="--server \"$guest_name\" $ws_suuid_flag --server-host-uuid local $ws_port_flag --component ws $ws_open_flag"
echo "wscmd=$ws_command_args"
striker-manage-vnc-pipes --server "$guest_name" $ws_suuid_flag --server-host-uuid local $ws_port_flag --component ws $ws_open_flag
echo "wscmd_exit=$?"
# Don't interrupt libvirt regardless of whether websockify gets setup
# successfully.
exit 0
fi
} >>/var/log/anvil.log

Loading…
Cancel
Save