A Linux administrator is configuring a service named webapp.service that depends on a remote NFS share. This share must be mounted at /srv/data before the service can start. Using a traditional /etc/fstab entry for this mount causes significant delays during the system boot process if the NFS server is unavailable. Which of the following is the BEST systemd-native approach to ensure the webapp.service only attempts to start after the NFS share is successfully mounted, while also preventing long boot delays?
Add the x-systemd.automount option to the /etc/fstab entry for the /srv/data mount point and add Requires=remote-fs.target to webapp.service.
Modify the webapp.service unit file to include an ExecStartPre=/usr/bin/mount /srv/data directive to ensure the mount is present before the main process starts.
Create a srv-data.mount unit file to define the NFS mount and add Requires=srv-data.mount and After=srv-data.mount to the [Unit] section of webapp.service.
Create a custom service unit named mount-nfs.service that contains the ExecStart=/usr/bin/mount /srv/data command, and add Wants=mount-nfs.service to webapp.service.
The correct approach is to create a dedicated systemd mount unit for the NFS share and then define this mount unit as a dependency for the webapp.service. A systemd .mount unit, named after its mount point (e.g., srv-data.mount), is the standard way to manage mount points. By adding Requires=srv-data.mount and After=srv-data.mount to the [Unit] section of the webapp.service file, systemd ensures that it will only start the web application service after it has successfully activated the srv-data.mount unit.
Using x-systemd.automount in /etc/fstab is a valid way to prevent boot delays by mounting the share on-demand, but it doesn't create an explicit start-order dependency for the service. The service could potentially start and fail before the on-demand mount is triggered and completed. Creating a separate .service unit to run the mount command is not the intended or most efficient method, as .mount units are specifically designed for this purpose. Using ExecStartPre in the service file to run the mount command is an imperative, not declarative, approach and is less robust for managing dependencies than using proper unit relationships.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What is a systemd .mount unit, and how does it differ from using /etc/fstab for mounting?
Open an interactive chat with Bash
What is the purpose of the Requires and After directives in a systemd service file?
Open an interactive chat with Bash
How does the x-systemd.automount option in /etc/fstab work, and why might it not be ideal for service dependencies?
Open an interactive chat with Bash
CompTIA Linux+ XK0-006 (V8)
Services and User Management
Your Score:
Report Issue
Bash, the Crucial Exams Chat Bot
AI Bot
Loading...
Loading...
Loading...
IT & Cybersecurity Package Join Premium for Full Access