home-manager: Make unmounts more robust

Try to unmount normally a few times, and if that fails, unmount lazily
to at least clean up the mount point before the fuse process is killed.
This commit is contained in:
talyz 2020-06-20 14:56:23 +02:00
parent 5b3345400c
commit 4d2cfadbc1
No known key found for this signature in database
GPG key ID: 2DED2151F4671A2B

View file

@ -86,7 +86,20 @@ in
fi
'';
stopScript = pkgs.writeShellScript "unmount-${name}" ''
fusermount -uz "${mountPoint}"
triesLeft=6
while (( triesLeft > 0 )); do
if fusermount -u "${mountPoint}"; then
exit 0
else
(( triesLeft-- ))
if (( triesLeft == 0 )); then
echo "Couldn't perform regular unmount of ${mountPoint}. Attempting lazy unmount."
fusermount -uz "${mountPoint}"
else
sleep 5
fi
fi
done
'';
in
{
@ -173,7 +186,20 @@ in
in
''
if [[ -n ''${mountedPaths["${mountPoint}"]+x} ]]; then
fusermount -u "${mountPoint}"
triesLeft=3
while (( triesLeft > 0 )); do
if fusermount -u "${mountPoint}"; then
break
else
(( triesLeft-- ))
if (( triesLeft == 0 )); then
echo "Couldn't perform regular unmount of ${mountPoint}. Attempting lazy unmount."
fusermount -uz "${mountPoint}" || true
else
sleep 1
fi
fi
done
fi
'';