feat(nfs-mount): disable automout service if nas not on network.
This commit is contained in:
parent
e6d21b8850
commit
0e96cd7d38
1 changed files with 29 additions and 1 deletions
|
@ -1,8 +1,22 @@
|
|||
{
|
||||
config,
|
||||
pkgs,
|
||||
lib,
|
||||
...
|
||||
}: {
|
||||
}: let
|
||||
auto_mount = pkgs.writeShellScriptBin "auto_mount" ''
|
||||
timeout 1 ${pkgs.bash}/bin/bash -c ": < /dev/tcp/192.168.0.4/2049"
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
systemctl stop mnt-share.automount
|
||||
echo "Nas device not available"
|
||||
else
|
||||
systemctl start mnt-share.automount
|
||||
echo "Nas device available"
|
||||
fi
|
||||
exit 0
|
||||
'';
|
||||
in {
|
||||
options = {
|
||||
crony.nfs-share.enable = lib.mkEnableOption "Setup personal nfs share mount.";
|
||||
};
|
||||
|
@ -14,5 +28,19 @@
|
|||
fsType = "nfs";
|
||||
options = ["_netdev" "noauto" "x-systemd.automount" "x-systemd.mount-timeout=10" "timeo=14" "x-systemd.idle-timeout=600"];
|
||||
};
|
||||
|
||||
systemd.timers.auto_mount = {
|
||||
enable = true;
|
||||
timerConfig = {
|
||||
OnBootSec = "1m";
|
||||
# OnUnitActiveSec = "1m";
|
||||
};
|
||||
wantedBy = ["timers.target"];
|
||||
};
|
||||
|
||||
systemd.services.auto_mount = {
|
||||
serviceConfig.Type = "oneshot";
|
||||
serviceConfig.ExecStart = "${auto_mount}/bin/auto_mount";
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue