Autofs is not working on boot - restarting service helps

I’m using autofs to mount a nfs share on boot (from my fileserver to my kodi), with raspbian this was working (though I must admit that that was an older version and dietpi is a fresh install now).

When I reboot my rpi 3 I’m getting:

# systemctl status autofs
● autofs.service - Automounts filesystems on demand
   Loaded: loaded (/lib/systemd/system/autofs.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2020-12-29 11:49:36 GMT; 8min ago
  Process: 359 ExecStart=/usr/sbin/automount $OPTIONS --pid-file /var/run/autofs.pid (code=exited, status=0/SUCCESS)
 Main PID: 379 (automount)
    Tasks: 4 (limit: 1635)
   CGroup: /system.slice/autofs.service
           └─379 /usr/sbin/automount --pid-file /var/run/autofs.pid

Dec 29 11:49:36 tv.cyber1000wn.local systemd[1]: Starting Automounts filesystems on demand...
Dec 29 11:49:36 tv.cyber1000wn.local systemd[1]: Started Automounts filesystems on demand.
Dec 29 11:49:39 tv.cyber1000wn.local automount[379]: add_host_addrs: hostname lookup failed: Temporary failure in name resolution

And a call to /mnt/autofs/fileserver/xyz doesn’t return anything.
If I restart with systemctl restart autofs it is working (until I reboot), so I think it might be a problem with the sequence with systemd, but couldn’t solve the problem so far.

My /lib/systemd/system/autofs.service looks like this (I haven’t changed here anythings, it’s the original file):

[Unit]
Description=Automounts filesystems on demand
After=network.target ypbind.service sssd.service network-online.target remote-fs.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/var/run/autofs.pid
EnvironmentFile=-/etc/default/autofs
ExecStart=/usr/sbin/automount $OPTIONS --pid-file /var/run/autofs.pid
ExecReload=/bin/kill -HUP $MAINPID
TimeoutSec=180

[Install]
WantedBy=multi-user.target

Any idea whats’s going on here or how I can’t analyze this further?

Thanks!

Hi,

yes your service is starting to early and it has issues to resolve host name.

Dec 29 11:49:39 tv.cyber1000wn.local automount[379]: add_host_addrs: hostname lookup failed: Temporary failure in name resolution

I guess it is starting before network connections are up and running. You would need to delay service start. This could be done by adding an additional requirement in your service file into the [Unit] section

add dietpi-boot.service into After condition like this

After=network-online.target dietpi-boot.service

But why you are using a service to mount the NFS share. It should be possible to have it stored inside /etc/fstab as well, Might be more easier.

Thanks again! This works …

But why you are using a service to mount the NFS share.

I’m using this setup for years, sometimes when my fileserver wasn’t running it blocked my startup until timeout. And one time I had a fallback “server” (my router) - autofs is more flexible. But normally my server is running and I haven’t tested another approach for years. It was more like “never change a running system” … Perhaps I’ll overthing this.

Is there something we can do about this service-file /lib/systemd/system/autofs.service or is this coming from base-os of dietpi?
As said I did just a apt-get install autofs, so I expected it to work right away …

In my post I offered a solution. probably you overlooked it.