Q:

Centos 7 autofs mount doesn't work right after reboot

I've setup autofs on Centos 7.  However, it seems like after reboot, it took some time to mount /home/ directory, even when I 'cd' into it.  It only succeeds after 3 tries:
[root@localhost ~] cd /home/<user>
-bash: cd: /home/<user>: No such file or directory

and, autofs is enabled, so I expect it to start after reboot:
[root@localhost etc]# systemctl status autofs
autofs.service - Automounts filesystems on demand
   Loaded: loaded (/usr/lib/systemd/system/autofs.service; enabled)
   Active: active (running) since Tue 2015-07-21 10:34:38 HKT; 1h 13min ago
  Process: 1379 ExecStart=/usr/sbin/automount $OPTIONS --pid-file /run/autofs.pid (code=exited, status=0/SUCCESS)
 Main PID: 1385 (automount)
   CGroup: /system.slice/autofs.service
           └─1385 /usr/sbin/automount --pid-file /run/autofs.pid

Jul 21 10:34:38 localhost.localdomain systemd[1]: Starting Automounts filesystems on demand...
Jul 21 10:34:38 localhost.localdomain automount[1385]: setautomntent: lookup(sss): setautomntent: No such file or directory
Jul 21 10:34:38 localhost.localdomain systemd[1]: Started Automounts filesystems on demand.

Here is /etc/auto.master:
/misc /etc/auto.misc
/net  -hosts
+dir:/etc/auto.master.d
/home /etc/auto.home
/san /etc/auto.san
+auto.master

/etc/auto.master:
* -fstype=nfs,rw 192.254.100.4:/home_external/user_home_local/&

/etc/auto.san:
mysql_db 192.254.100.4:/san_external/mysqldb

I suspect for similar reasons, when mysql starts after reboot, it has an error saying it can't 'cd' into /san/mysql_db/.  But a manual restart on mysql after the machine is booted up works.  Any ideas?  thanks vm

A:

I experienced something similar.
That is, logins of users with automounted home directories hung right after reboot, until such time as I manually started rpcbind with "systemctl start rpcbind".  This is with all the most recent Cent7 updates as of today.
I found that modifying the autofs unit file to depend on rpcbind and some other services fixed my problem.  See the "Requires=network.target rpc-statd.service rpcbind.service" line in the "After" code block below...
Before: /usr/lib/systemd/system/autofs.service
[Unit]
Description=Automounts filesystems on demand
After=network.target ypbind.service sssd.service

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

[Install]
WantedBy=multi-user.target

After: /usr/lib/systemd/system/autofs.service
[Unit]
Description=Automounts filesystems on demand
Requires=network.target rpc-statd.service rpcbind.service
After=network.target ypbind.service sssd.service

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

[Install]
WantedBy=multi-user.target

Hat tip: https://www.centos.org/forums/viewtopic.php?f=47&t=51789

