Umount script: Kill blocking processes and destroy VMs.
This commit is contained in:
parent
11042c2e52
commit
a1e47cf64b
1 changed files with 18 additions and 38 deletions
|
@ -9,50 +9,30 @@ uid="$2"
|
|||
mtp="$3"
|
||||
|
||||
shutdownVMs(){
|
||||
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
|
||||
}
|
||||
|
||||
unbindmnt(){
|
||||
local lmuh="/lmn/media/$usr/home"
|
||||
local lmus="/lmn/media/$usr/share"
|
||||
local N=0 mh=true ms=true
|
||||
|
||||
mountpoint -q $lmuh || mh=false
|
||||
mountpoint -q $lmus || ms=false
|
||||
while [[ $N -lt 10 ]] && ([[ $mh = true ]] || [[ $ms = true ]]) ; do
|
||||
if [[ $mh = true ]] ; then
|
||||
umount "$lmuh" && mh=false
|
||||
fi
|
||||
if [[ $ms = true ]] ; then
|
||||
umount "$lmus" && ms=false
|
||||
fi
|
||||
N=$((N + 1))
|
||||
sleep 1
|
||||
local VM
|
||||
for VM in $(sudo -u $usr XDG_RUNTIME_DIR="/run/user/$uid" \
|
||||
XDG_CONFIG_HOME="/tmp/$uid/.config/" \
|
||||
XDG_CACHE_HOME="/var/cache/user/$uid/" \
|
||||
virsh list --state-running | \
|
||||
sed -nE "s/.*\s+(\S+)\s+running/\1/p") ; do
|
||||
sudo -u $usr XDG_RUNTIME_DIR="/run/user/$uid" \
|
||||
XDG_CONFIG_HOME="/tmp/$uid/.config/" \
|
||||
XDG_CACHE_HOME="/var/cache/user/$uid/" \
|
||||
virsh destroy "$VM" 2>&1 | systemd-cat || true
|
||||
done
|
||||
systemd-cat echo "Tried $N umount(s)."
|
||||
}
|
||||
|
||||
######################
|
||||
|
||||
if [[ "$mtp" =~ "/srv/samba/schools" ]] ; then
|
||||
## This is the first mount we need to get rid of:
|
||||
if [[ "$mtp" =~ "/lmn/media/$usr/share" ]] ; then
|
||||
shutdownVMs
|
||||
unbindmnt
|
||||
sleep 5 # leave some time to write caches …
|
||||
sudo -u ${usr} killall gvfsd | systemd-cat
|
||||
sudo -u ${usr} killall dbus-daemon | systemd-cat
|
||||
systemctl kill system-virtiofs.slice
|
||||
# debug to find processes blocking umount:
|
||||
# lsof > /tmp/lsof.log
|
||||
fi
|
||||
|
||||
## Just umount:
|
||||
|
|
Loading…
Add table
Reference in a new issue