5

I’m running jessie/sid with systemd 208 and try to convert the following wildcard autofs configuration to either an /etc/fstab or .mount/.automount definition.

$ cat /etc/auto.master
/home/* -fstype=nfs homeserver:/exp/home/&

(homeserver runs a Solaris with each subdirectory in /exp/home/ being a separate share.)

Is there a way to emulate wildcard maps with systemd?

2

I suppose no. The .mount/.automount unit name has to be equal to the mount path, escaped with systemd-escape --path. And the only way in systemd to instantiate units is "template syntax" of a form foo@bar.type. Hence it is at least not possible to have a dynamically instantiated mount unit.

Just use autofs. systemd is not a replacement for everything.

| improve this answer | |
  • Was having the problem that automount would hang on shutdown/reboot, so I was looking for a more integrated solution to hopefully avoid this. – Debilski Jan 13 '15 at 10:37
  • 1
    @Debilski: This is a distinct problem. You can try to add ordering dependencies to autofs.service to prevent it from stopping too late. Maybe After=network.target helps. Just remember that you don't need to edit the whole unit file -- there are drop-in files exactly for that purpose ;) – intelfx Jan 13 '15 at 11:40
  • Yes, that was my workaround in the end as well. – Debilski Jan 13 '15 at 11:55
2

You could use systemd's generator interface. Basically, it creates service files on the fly upon start or reload.

We have a range of machines (called "dema" plus some number) in our cluster, which all export the same directory (their physical disk). I used the generator interface to create one .mount and one .automount file for each machine:

#!/bin/sh

svc_dir=/run/systemd/generator

for i in $(seq 1 99); do
    # this must match the mount path, / is converted to -
    unit_bn=cluster-dema$i
    cat << EOF > "${svc_dir}/${unit_bn}.automount"
[Unit]
Description=dema${i}s localdisks automount point
Documentation=file:///usr/lib/systemd/system-generators/dema-automount-generator
Before=remote-fs.target

[Automount]
Where=/cluster/dema$i
EOF

    cat << EOF > "${svc_dir}/${unit_bn}.mount"
[Unit]
Description=dema${i}s localdisks
Documentation=file:///usr/lib/systemd/system-generators/dema-automount-generator

[Mount]
What=dema$i:/localdisks
Where=/cluster/dema$i
Type=nfs
Options=rw,nosuid,nodev,hard,intr,rsize=8192,wsize=8192,noauto,x-systemd.automount
EOF
    ln -s "../${unit_bn}.automount" "${svc_dir}/remote-fs.target.requires"
done

The script has to be placed into /usr/lib/systemd/system-generators and executable. After putting it there, call systemd daemon-reload and you should find the units in /run/systemd/generator. There are activated on next reboot and can be manually started, of course, by calling systemd start oneofthenames.automount.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.