Try umounting multiple times.

This commit is contained in:
Andreas B. Mundt 2023-09-02 16:06:15 +02:00
parent 431acebfa3
commit 7d7301f67d

View file

@ -4,25 +4,35 @@
set -eu set -eu
LANG=C
usr="$1" usr="$1"
uid="$2" uid="$2"
mtp="$3" mtp="$3"
lmuh="/lmn/media/$usr/home" shutdownVMs(){
lmus="/lmn/media/$usr/share" local VMs VM
VMs="$(machinectl list --no-legend)"
if [[ -n "$VMs" ]] ; then
for VM in $VMs ; do
machinectl poweroff "$VM{VM%% *}" || true
done
sleep 3
fi
## Check again:
VMs="$(machinectl list --no-legend)"
if [[ -n "$VMs" ]] ; then
sleep 3
for VM in $VMs ; do
machinectl terminate "${VM%% *}" || true
done
fi
#killall -9 virtiofsd
}
for VMname in $(sudo -u $usr XDG_RUNTIME_DIR="/run/user/$uid" \ unbindmnt(){
virsh list --state-running | grep running | awk '{print $2}'); do local lmuh="/lmn/media/$usr/home"
sudo -u $usr XDG_RUNTIME_DIR="/run/user/$uid" virsh destroy $VMname || true local lmus="/lmn/media/$usr/share"
sleep 1 local N=0 mh=true ms=true
done
#killall -9 virtiofsd
if [[ "$mtp" =~ "/srv/samba/schools" ]] ; then
N=0
mh=true
ms=true
mountpoint -q $lmuh || mh=false mountpoint -q $lmuh || mh=false
mountpoint -q $lmus || ms=false mountpoint -q $lmus || ms=false
while [[ $N -lt 10 ]] && ([[ $mh = true ]] || [[ $ms = true ]]) ; do while [[ $N -lt 10 ]] && ([[ $mh = true ]] || [[ $ms = true ]]) ; do
@ -36,5 +46,14 @@ if [[ "$mtp" =~ "/srv/samba/schools" ]] ; then
sleep 1 sleep 1
done done
systemd-cat echo "Tried $N umount(s)." systemd-cat echo "Tried $N umount(s)."
}
######################
if [[ "$mtp" =~ "/srv/samba/schools" ]] ; then
shutdownVMs
unbindmnt
fi fi
## Just umount:
exec umount "$mtp" exec umount "$mtp"