You are not logged in.
Hi,
I would like to know which is the best solution to solve the following problem:
I have an headless server where a lot of services are running, two of those need to access to an external disk connect via USB. The disk is mounted via /etc/fstab using auto option.
Sometimes the disk is not ready as the system start so the mount fails stopping the boot process waiting for an user option (but since it is an headless server... Nobody could push any button).
If I understood correctly fstab entries are automatically converted to systemctl unit, so I was wondering how I can put a timeout/retry to this autogenerated unit, and then put a drop-in snippet to other two units depending on it in order to wait that the USB disk is mounted in order to be started.
Thank you.
Ciao.
Offline
The disk is mounted via /etc/fstab using auto option
Try using these options instead:
x-systemd.automount,nofailSee systemd.mount(5) & systemd.automount(5)
Jin, Jîyan, Azadî
Offline
I think I've solved with this solution.
I've create a unit /etc/systemd/system/media-xyz.mount with this content:
[Unit]
Description = Big USB disk
[Mount]
What = /dev/sdb1
Where = /media/xyz
Type = ext4
Options = rw,user
TimeoutSec = 10
[Install]
RequiredBy = transmission.service
RequiredBy = plexmediaserver.serviceAnd then enable the service.
It seems to work, but I am not pretty sure that it's the best way to do it.
Offline
With this solution you only have the 'Requires=' part, not the 'After=' part; so it could work, but it is not sure that the two units will be started after the mount point.
You could try instead to keep the /etc/systemd/system/media-xyz.mount unit without the 'RequiredBy' lines:
[Unit]
Description = Big USB disk
[Mount]
What = /dev/sdb1
Where = /media/xyz
Type = ext4
Options = rw,user
TimeoutSec = 10(You don't need to enable the mount unit)
And adding in the [Unit] section of the two services transmission.service and plexmediaserver.service this line:
RequiresMountsFor=/media/xyz
which should take care of the 'Requires=' and 'After=' for the mount unit required to access the specified path (see man systemd.unit).
But if your solution works, this is good, but with the 'After=' part it should be better.
Offline