I want systemd on mount /mnt/test to automatically call a program (in real life cryptsetup to unlock the underlying device, for testing here echo) before the file system is mounted and after it is unmounted.
With /etc/systemd/system/stickbak-encryption.service:
[Unit] Description=stickbak encryption Before=mnt-test.mount StopWhenUnneeded=true [Service] Type=oneshot ExecStart=/bin/echo Unlock device. RemainAfterExit=true ExecStop=/bin/echo Lock device. [Install] RequiredBy=mnt-test.mount and /etc/fstab (partly):
/dev/$DEVICE /mnt/test auto noauto 0 0 this works (after daemon reload and enabling the service) for systemctl start mnt-test.mount and respectively systemctl stop mnt-test.mount (as root).
On mount /mnt/test, however, systemctl status mnt-test.mount stickbak-encryption shows the latter service being inactive (dead), while the former is active (mounted).
How can I (or can I not?) set up a dependency that is honoured when /bin/mount is called as well? The status of the mount unit shows that mount /mnt/test seems to be translated to ExecMount=/bin/mount /dev/$DEVICE /mnt/test -t auto -o noauto, so apparently systemd gets notified.