#!/bin/bash # ===================================================================== # Runs from ExecStopPost=, so it happens however qemu died - clean exit, # SIGTERM, SIGKILL, OOM, or a crash. That is the whole reason it exists # as a unit hook rather than as code in vmd: the archived sub-agent stack # recorded a cancellation and killed nothing, and the run carried on. # # It runs as owuivm, which owns the overlay and the session directory's # contents, so it needs no privilege at all to undo its own mess. vmd # reaps again when it starts; neither is trusted to be the one that ran. # # Deliberately never fails: a teardown that exits non-zero puts the unit # into `failed` and the next `systemctl start` needs a reset-failed first, # which turns a transient into a wedge. # ===================================================================== set -u SESSION="${OWUIVM_SESSION:-}" [[ "$SESSION" =~ ^[0-9a-f]{32}$ ]] || exit 0 RUN="/run/owuivm/$SESSION" # The overlay is disposable by definition - every session starts from the # frozen base - so it goes unconditionally rather than being kept "just # in case". Anything worth keeping was written to the project share. DISK="${OWUIVM_DISK:-}" case "$DISK" in @POOL_ROOT@/vmrun/*.qcow2) rm -f -- "$DISK" 2>/dev/null ;; esac rm -f -- "$RUN"/qmp.sock "$RUN"/ga.sock "$RUN"/broker.sock \ "$RUN"/vnc.sock "$RUN"/OVMF_VARS.fd 2>/dev/null # Tells vmd the machine is gone without it having to race systemd's own # state, and gives the orphan reaper something to find if vmd was not # running at the time. : > "$RUN/STOPPED" 2>/dev/null exit 0