I would like to create a service file that, when started, causes a specified filesystem to be mounted before the action of the service file is performed (as it needs that file system to be available). Furthermore, I would like this service file to fail gracefully in case the file system cannot be mounted (e.g., because it is located on a sometimes unplugged external hard drive).
My first try was simple and partly successful: add
x-systemd.automount as an option in the filesystem's fstab line. Then the filesystem is automatically mounted when the service file causes its mountpoint to be accessed. However, it does not fail gracefully in the sense that there is a long timeout and it is logged as an ERROR.
My second try was not as successful, I added
After=path-to-mountpoint.mount to the service file (
x-systemd.automount was removed): the
path-to-mountpoint.mount is not found. I guess it only is created upon successful mount, so it is not meant for what I want to do.