Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save klingtnet/0b6b6e95cf650eb125070b0dc65e228a to your computer and use it in GitHub Desktop.
Save klingtnet/0b6b6e95cf650eb125070b0dc65e228a to your computer and use it in GitHub Desktop.
How to unmount webdrives on shutdown with systemd

The systemd service file that is triggered before the shutdown.target (note that systemd targets are somewhat similar to RunLevels of SysVinit):

# /etc/systemd/system/unmount-webdrives-on-shutdown.service
[Unit]
Description=Unmount webdrives before shutdown
Before=shutdown.target

[Service]
Type=oneshot
ExecStart=/bin/bash /usr/local/bin/unmount-webmounts.sh

[Install]
WantedBy=multi-user.target

This is the script that is responsible for unmounting the webdrives, in this case some FUSE WebDAV mounts:

$ cat /usr/local/bin/unmount-webmounts.sh
#!/bin/bash

MNTS=(
	'/mnt/webdav.example.com
	'/mnt/webdav.somewhere.else
)

for mp in ${MNTS[@]}; do
	mountpoint --quiet "$mp" && umount "$mp" || true
done

Last but not least, reload the systemd daemon systemctl daemon-reload and enable the service sudo systemctl enable unmount-webdrives-on-shutdown.service.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment