[systemd-devel] How to add a dependency to a systemd.mount that is activated by /bin/mount?
Tim Landscheidt
tim at tim-landscheidt.de
Tue Sep 24 18:11:39 PDT 2013
Hi,
on Fedora 19/systemd 204, I want systemd on "mount
/mnt/test" by a non-root user to automatically call a pro-
gram as root (in real life cryptsetup to unlock the underly-
ing device, for testing here echo) before the file system is
mounted and after it is unmounted.
With /etc/systemd/system/mount-wrapper.service:
| [Unit]
| Description=mount wrapper
| 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
/etc/fstab (partly):
| /dev/$DEVICE /mnt/test auto noauto,user 0 0
and (with or without) /etc/systemd/system/mnt-test.mount:
| [Unit]
| Description=mount test
|
| [Mount]
| What=/dev/$DEVICE
| Where=/mnt/test
| Options=noauto,user
this works (after daemon reload and enabling the service)
for "systemctl start mnt-test.mount" and "systemctl stop
mnt-test.mount" respectively (as root).
On "mount /mnt/test", however, "systemctl status
mnt-test.mount mount-wrapper" 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 hon-
oured when /bin/mount is called as well? The status of the
mount unit shows that "mount /mnt/test" seems to be trans-
lated to "ExecMount=/bin/mount /dev/$DEVICE /mnt/test -t
auto -o noauto,user", so apparently systemd gets notified.
TIA,
Tim
P. S.: If there is a "more systemd" way to handle removable
encrypted media, I'm all ears :-). I've seen
/etc/crypttab & Co., but it seems to be focused on
disks that are unlocked at boot and remain enabled
till shutdown.
More information about the systemd-devel
mailing list