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"
|
mtp="$3"
|
||||||
|
|
||||||
shutdownVMs(){
|
shutdownVMs(){
|
||||||
local VMs VM
|
local VM
|
||||||
VMs="$(machinectl list --no-legend)"
|
for VM in $(sudo -u $usr XDG_RUNTIME_DIR="/run/user/$uid" \
|
||||||
if [[ -n "$VMs" ]] ; then
|
XDG_CONFIG_HOME="/tmp/$uid/.config/" \
|
||||||
for VM in $VMs ; do
|
XDG_CACHE_HOME="/var/cache/user/$uid/" \
|
||||||
machinectl poweroff "$VM{VM%% *}" || true
|
virsh list --state-running | \
|
||||||
done
|
sed -nE "s/.*\s+(\S+)\s+running/\1/p") ; do
|
||||||
sleep 3
|
sudo -u $usr XDG_RUNTIME_DIR="/run/user/$uid" \
|
||||||
fi
|
XDG_CONFIG_HOME="/tmp/$uid/.config/" \
|
||||||
## Check again:
|
XDG_CACHE_HOME="/var/cache/user/$uid/" \
|
||||||
VMs="$(machinectl list --no-legend)"
|
virsh destroy "$VM" 2>&1 | systemd-cat || true
|
||||||
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
|
|
||||||
done
|
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
|
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
|
fi
|
||||||
|
|
||||||
## Just umount:
|
## Just umount:
|
||||||
|
|
Loading…
Add table
Reference in a new issue