check network mount before backup - fail if disconnected

This commit is contained in:
Joseph Hanson 2025-02-23 20:25:53 -06:00
parent d3d9e0fd1a
commit 4493b2519d
Signed by: jahanson
SSH key fingerprint: SHA256:vy6dKBECV522aPAwklFM3ReKAVB086rT3oWwiuiFG7o

View file

@ -1,12 +1,15 @@
{ lib, config, ... }: {
with lib; lib,
let config,
pkgs,
...
}:
with lib; let
cfg = config.mySystem.services.forgejo; cfg = config.mySystem.services.forgejo;
http_port = 3000; http_port = 3000;
serviceUser = "forgejo"; serviceUser = "forgejo";
domain = "git.hsn.dev"; domain = "git.hsn.dev";
in in {
{
options.mySystem.services.forgejo = { options.mySystem.services.forgejo = {
enable = mkEnableOption "Forgejo"; enable = mkEnableOption "Forgejo";
package = mkOption { package = mkOption {
@ -27,6 +30,18 @@ in
}; };
}; };
# Add path unit to check mount point before backup
# We don't want to backup to the file system in case of network mount failure
systemd.services."forgejo-dump-path-check" = {
description = "Check if Forgejo backup mount point exists and is mounted";
before = ["forgejo-dump.service"];
requiredBy = ["forgejo-dump.service"];
serviceConfig = {
Type = "oneshot";
ExecStart = "${pkgs.util-linux}/bin/mountpoint /mnt/storagebox";
};
};
services.forgejo = { services.forgejo = {
enable = true; enable = true;
package = cfg.package; package = cfg.package;
@ -34,7 +49,9 @@ in
dump = { dump = {
enable = true; enable = true;
backupDir = "/mnt/storagebox/forgejo/backup"; backupDir = "/mnt/storagebox/forgejo/backup";
type = "tar.gz";
}; };
database.type = "postgres"; database.type = "postgres";
# Enable support for Git Large File Storage # Enable support for Git Large File Storage
lfs.enable = true; lfs.enable = true;
@ -97,7 +114,7 @@ in
sopsFile = ./secrets.sops.yaml; sopsFile = ./secrets.sops.yaml;
owner = serviceUser; owner = serviceUser;
mode = "400"; mode = "400";
restartUnits = [ "forgejo.service" ]; restartUnits = ["forgejo.service"];
}; };
}; };
} }