How to set a service to start after autofs has started with systemd

rhelsystemd

I have to set up a license server on a RHEL7 machine with systemd. The license server should start upon boot and load a license file from a shared disk on the network. So I need to wait for the network to start and for autofs to finish mounting NFS disks. I have this service file:

[Unit]
Description=Flexnet license server
Wants=network.target network-online.target autofs.service
After=network.target network-online.target autofs.service

[Service]
Type=forking
User=licenseuser
Group=devusers
ExecStart=/soft/flexera/glnxa64/lmgrd -c /soft/licenses/license.dat -L /home/licenseuser/license.log

# Give a reasonable amount of time for the server to start up/shut down
TimeoutSec=300

[Install]
WantedBy=multi-user.target

The service starts after autofs has started but before autofs has mounted all of the disks so the license server cannot be started.

Best Answer

You should add in the following

[Unit]
RequiresMountsFor=<path required>

This will ensure the path is accessible before starting the service and also will mount it if it's not already (unless it has noauto specified). Check with your manpages (man systemd.unit) if the option is supported in your system as mine is quite bleeding edge.