I’ve got a QNAP NAS and two Linux servers. Whenever the power goes down, the UPS kicks in and shut downs the NAS and the Linux servers, all good. The servers + NAS are automatically started when the power comes back on line using WOL. All good.
The problem is that I have apps running using Docker which heavily rely on connections to the NAS. As the Linux servers boot quicker than the NAS, the mount points are not mounted, and thus everything falls apart. Even when I manually re-mount, it’s not propagated to the Docker instances. All mount points use NFS.
Currently, I just reboot the Linux servers manually, and then all works well.
Probably easiest would be to run a cron job to check the mounts every x minutes, and if they are not mounted, then just reboot. The only issue is that this may cause an infinite loop of reboots if e.g. the NAS has been turned off.
I could also install a monitoring solution, but I’ve seen so many options that I’m not sure which one to do. If it’s easier with a monitoring solution, I’d like the simplest one. Cockpit Project looks cool and has a tab with Storage, and lists NFS mounts, but unsure if I can get alerts if they are not available.
freeearth@discuss.tchncs.de 8 months ago
Just specaluting… is it possible to mount NFS through systemd and make docker service dependent from that mount?
avidamoeba@lemmy.ca 8 months ago
This is the answer. You can straight up make things dependent on .mount units that represent stuff in fstab. To add, you can create any number of systemd services that just check if something is “as you want it” and only then “start”. You simply make the Exec line “/bin/bash -c ‘your script here’”. Then you make whatever else you want dependent on it. For example I have such a unit that monitors for Internet connection by checking some public DNS servers. Then I have services that depend on Internet connection dependent on that.
samwwwblack@lemm.ee 8 months ago
You can use
RequiresMountsFor=
(egRequiresMountsFor=/media/storage-volume1
) instead of manually adding.mount
toAfter
/Requires
- you can then use.mount
files or fstab as you’re stipulating the path rather than a potentially changeable systemd unit name.The systemd.mount manpage also strongly recommends using fstab for human added mount points over
.mount
files.sylverstream@lemmy.nz 8 months ago
That’s interesting! I’ve converted all my docker run commands to docker compose, as I found that easier to manage. But, I guess you can’t do the dependencies like you have. Also, yours has the advantage it always pulls the latest.
sylverstream@lemmy.nz 8 months ago
Sorry, I’m absolutely not a Linux expert :) I use /etc/fstab for the mounts, and to manually re-mount I run “mount -a”.
avidamoeba@lemmy.ca 8 months ago
This is a great opportunity to learn a bit of systemd then. Look at my other comment.