common/fs: /mnt/servo/* ftp auto/re-mounting in a way which does better rate limiting

This commit is contained in:
2024-07-29 07:11:52 +00:00
parent f1c76ada43
commit d76d50f1c4

View File

@@ -153,32 +153,63 @@ let
systemd.mounts = let systemd.mounts = let
fsEntry = config.fileSystems."${localPath}"; fsEntry = config.fileSystems."${localPath}";
in [{ in [{
bindsTo = [ "${systemdName}.service" ];
where = localPath; where = localPath;
what = fsEntry.device; what = fsEntry.device;
type = fsEntry.fsType; type = fsEntry.fsType;
options = lib.concatStringsSep "," fsEntry.options; options = lib.concatStringsSep "," fsEntry.options;
# bindsTo X: when X is stopped, or exits, causes this unit to also be stopped. also, causes X to be started when this unit is started.
# bindsTo = [ "${systemdName}.service" ];
# startLimitBurst = 2;
# startLimitIntervalSec = 120;
onSuccess = [ "${systemdName}-trigger.service" ];
}]; }];
systemd.services."${systemdName}-trigger" = {
description = "re-establish the mount to ${localPath}";
conflicts = [ "${systemdName}.service" ];
before = [ "${systemdName}.service" ]; #< XXX: "that to ensure that the conflicting unit is stopped before the other unit is started, an After= or Before= dependency must be declared. It doesn't matter which of the two ordering dependencies is used, because stop jobs are always ordered before start jobs" (man systemd.unit)
onSuccess = [ "${systemdName}.service" ];
serviceConfig.Type = "oneshot";
serviceConfig.ExecStart = lib.getExe' pkgs.coreutils "true";
};
systemd.services."${systemdName}" = { systemd.services."${systemdName}" = {
description = "re-mount ${localPath} when it fails"; # TODO: remove the trigger, and use `bindsTo = ${systemdName}.mount` here.
after = [ "network-online.target" ]; # unitConfig.RequiresMountsFor = [ localPath ];
requires = [ "network-online.target" ]; serviceConfig.Restart = "on-failure";
wantedBy = [ "default.target" ];
partOf = [ "${systemdName}.mount" ];
upholds = [ "${systemdName}.mount" ];
requiredBy = [ "${systemdName}.mount" ];
serviceConfig.Type = "simple";
# serviceConfig.ExecStartPre = "${lib.getExe' pkgs.systemd "systemctl"} start ${systemdName}.mount";
# serviceConfig.ExecStop = "${lib.getExe' pkgs.systemd "systemctl"} stop ${systemdName}.mount";
serviceConfig.ExecStart = "${lib.getExe' pkgs.coreutils "sleep"} infinity";
serviceConfig.Restart = "always";
serviceConfig.RestartSec = "10s"; serviceConfig.RestartSec = "10s";
serviceConfig.RestartMaxDelaySec = "120s"; serviceConfig.RestartMaxDelaySec = "120s";
serviceConfig.RestartSteps = "5"; serviceConfig.RestartSteps = "5";
serviceConfig.Type = "oneshot";
serviceConfig.RemainAfterExit = true;
serviceConfig.ExecStart = "${lib.getExe' pkgs.systemd "systemctl"} start ${systemdName}.mount";
# serviceConfig.Type = "simple";
# serviceConfig.ExecStart = "${lib.getExe' pkgs.coreutils "sleep"} infinity";
}; };
# systemd.services."${systemdName}" = {
# description = "re-mount ${localPath} when it fails";
# after = [ "network-online.target" ];
# requires = [ "network-online.target" ];
# wantedBy = [ "default.target" ];
# # partOf X: when X is *explicitly* stopped or restarted, this unit is also stopped/restarted.
# # partOf = [ "${systemdName}.mount" ];
# # upholds X: as long as this unit is active, X will be started any time it's found to be inactive or failed (immediately).
# upholds = [ "${systemdName}.mount" ];
# # requiredBy X: when X is started, this unit is caused to be started, and when this unit is *explicitly* stopped, then X will be stopped.
# # requiredBy = [ "${systemdName}.mount" ];
# # bindsTo X: when X is stopped, or exits, causes this unit to also be stopped. also, causes X to be started when this unit is started.
# # bindsTo = [ "${systemdName}.mount" ];
# serviceConfig.Type = "simple";
# # serviceConfig.ExecStartPre = "${lib.getExe' pkgs.systemd "systemctl"} start ${systemdName}.mount";
# # serviceConfig.ExecStop = "${lib.getExe' pkgs.systemd "systemctl"} stop ${systemdName}.mount";
# serviceConfig.ExecStart = "${lib.getExe' pkgs.coreutils "sleep"} infinity";
# serviceConfig.Restart = "always";
# serviceConfig.RestartSec = "10s";
# serviceConfig.RestartMaxDelaySec = "120s";
# serviceConfig.RestartSteps = "5";
# };
# systemd.services."automount-servo-${utils.escapeSystemdPath subdir}" = let # systemd.services."automount-servo-${utils.escapeSystemdPath subdir}" = let
# fs = config.fileSystems."/mnt/servo/${subdir}"; # fs = config.fileSystems."/mnt/servo/${subdir}";
# in { # in {