diff options
Diffstat (limited to 'core/modules/run-virt/data/opt/openslx/vmchooser/vmchooser-run_virt')
-rwxr-xr-x | core/modules/run-virt/data/opt/openslx/vmchooser/vmchooser-run_virt | 55 |
1 files changed, 51 insertions, 4 deletions
diff --git a/core/modules/run-virt/data/opt/openslx/vmchooser/vmchooser-run_virt b/core/modules/run-virt/data/opt/openslx/vmchooser/vmchooser-run_virt index ca881f29..f2fa4a89 100755 --- a/core/modules/run-virt/data/opt/openslx/vmchooser/vmchooser-run_virt +++ b/core/modules/run-virt/data/opt/openslx/vmchooser/vmchooser-run_virt @@ -182,13 +182,60 @@ main() { run_hooks "pre-exec" "$PLUGIN_ID" "$IMGUUID" + # Launch COWGUI in CoW-Edit-Mode + local cowpid cowurl vmpidfile + cowpid= + vmpidfile= + if [ -n "$DMSD_COW_SESSION" ]; then + vmpidfile="$( mktemp -p "/run/user/$( id -u )" )" + cowurl="${SLX_VMCHOOSER_BASE_URL//"/vmchooser/"/"/cow/"}" + ( + cntr=0 + while true; do + writelog "Launching CoW-GUI" + cowgui --sessionid "$DMSD_COW_SESSION" --url "$cowurl" --pid "$DNBD3_PID" --status "$TMPDIR/cow/status" && break + # Unclean exit, let's see if it's worth relaunching + state="$( curl -m 3 -sS -L "$cowurl/status/$DMSD_COW_SESSION" | jq -r .state )" + [ -z "$state" ] && break + [ "$state" = "PROCESSING" ] && break + [ "$state" = "ERROR" ] && break + [ "$state" = "COMPLETELY_DONE" ] && break + (( cntr++ > 10 )) && break + done + writelog "Final cow state: $( curl -m 3 -sS -L "$cowurl/status/$DMSD_COW_SESSION" )" + [ -s "$vmpidfile" ] && kill "$( cat "$vmpidfile" )" + ) & + cowpid=$! + fi + writelog "VM command: ${VIRTCMD} ${VIRTCMDOPTS[*]}" - # This will start the VM (no eval needed!) + # Prepare short config dir, needed because libvirt is stupid and likes + # to create very long UNIX socket names and then chokes on them. + cd="$( mktemp -d "/tmp/lvXXX" )" + if [ -z "$cd" ]; then + cd="/tmp/lv${UID}$(( RANDOM % 10000 ))" + rm -rf -- "$cd" + mkdir -p "$cd" + fi + # This will start the VM writelog "---------- BEGIN VM command output ----------" - local retval - "${VIRTCMD}" "${VIRTCMDOPTS[@]}" &>> "${LOGFILE}" + local retval vmpid + XDG_CONFIG_HOME="$cd" "${VIRTCMD}" "${VIRTCMDOPTS[@]}" &>> "${LOGFILE}" & + vmpid=$! + [ -n "$vmpidfile" ] && echo "$vmpid" > "$vmpidfile" + wait "$vmpid" retval=${?} - writelog "---------- END VM command output ----------" + writelog "------- END VM command output ($retval) --------" + + if [ -n "$DNBD3_PID" ]; then + writelog "Killing dnbd3-fuse" + kill "$DNBD3_PID" + fi + # If cow, wait for GUI + if [ -n "$cowpid" ]; then + writelog "Waiting for CoW-GUI" + wait "$cowpid" + fi run_hooks "post-exec" "$PLUGIN_ID" "$IMGUUID" |