feat: Add systemd service to monitor boot disk space

This commit introduces a new systemd service that runs daily to check the disk usage of the /boot partition. If utilization exceeds a set threshold, it triggers a warning email. This will ensure prompt alerts on critically low boot disk space, helping in maintaining a stable system.
This commit is contained in:
Harald Hoyer 2024-05-17 16:29:30 +02:00
parent bd2e13a215
commit 16e744e39e
2 changed files with 55 additions and 24 deletions

View file

@ -328,11 +328,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1711763326, "lastModified": 1715901937,
"narHash": "sha256-sXcesZWKXFlEQ8oyGHnfk4xc9f2Ip0X/+YZOq3sKviI=", "narHash": "sha256-eMyvWP56ZOdraC2IOvZo0/RTDcrrsqJ0oJWDC76JTak=",
"owner": "lnl7", "owner": "lnl7",
"repo": "nix-darwin", "repo": "nix-darwin",
"rev": "36524adc31566655f2f4d55ad6b875fb5c1a4083", "rev": "ffc01182f90118119930bdfc528c1ee9a39ecef8",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -397,11 +397,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1712765858, "lastModified": 1715872464,
"narHash": "sha256-gWRdIXmNsgOKFNiFOAzo4hleJsl03vu9nLPrkmwmTwY=", "narHash": "sha256-mkZ3hrPG7d+qL7B6pQcrNfPh2mnQEJR3FHK93qCp6Uk=",
"owner": "nix-community", "owner": "nix-community",
"repo": "disko", "repo": "disko",
"rev": "53c4cc48b71bbd98d65fb4c7bc0e2ea22d9a6672", "rev": "5f6dbcce99d60dd77f96dfc66d06bbea149a40e1",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -858,11 +858,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1712386041, "lastModified": 1715381426,
"narHash": "sha256-dA82pOMQNnCJMAsPG7AXG35VmCSMZsJHTFlTHizpKWQ=", "narHash": "sha256-wPuqrAQGdv3ISs74nJfGb+Yprm23U/rFpcHFFNWgM94=",
"owner": "nix-community", "owner": "nix-community",
"repo": "home-manager", "repo": "home-manager",
"rev": "d6bb9f934f2870e5cbc5b94c79e9db22246141ff", "rev": "ab5542e9dbd13d0100f8baae2bc2d68af901f4b4",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -1393,11 +1393,11 @@
}, },
"nixpkgs-stable_2": { "nixpkgs-stable_2": {
"locked": { "locked": {
"lastModified": 1712437997, "lastModified": 1715458492,
"narHash": "sha256-g0whLLwRvgO2FsyhY8fNk+TWenS3jg5UdlWL4uqgFeo=", "narHash": "sha256-q0OFeZqKQaik2U8wwGDsELEkgoZMK7gvfF6tTXkpsqE=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "e38d7cb66ea4f7a0eb6681920615dfcc30fc2920", "rev": "8e47858badee5594292921c2668c11004c3b0142",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -1441,11 +1441,11 @@
}, },
"nixpkgs_4": { "nixpkgs_4": {
"locked": { "locked": {
"lastModified": 1712588820, "lastModified": 1715668745,
"narHash": "sha256-y31s5idk3jMJMAVE4Ud9AdI7HT3CgTAeMTJ0StqKN7Y=", "narHash": "sha256-xp62OkRkbUDNUc6VSqH02jB0FbOS+MsfMb7wL1RJOfA=",
"owner": "nixos", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "d272ca50d1f7424fbfcd1e6f1c9e01d92f6da167", "rev": "9ddcaffecdf098822d944d4147dd8da30b4e6843",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -1477,11 +1477,11 @@
"snowfall-lib": "snowfall-lib" "snowfall-lib": "snowfall-lib"
}, },
"locked": { "locked": {
"lastModified": 1712647695, "lastModified": 1715612543,
"narHash": "sha256-z+RokYZ7t95/SbPExDaRYC+Jhi1Wu4UN5ooJB36Ra5Y=", "narHash": "sha256-6mOnzd+TFLel9vxxbkUjzwKZWHZko9h6DbxXK86VukI=",
"owner": "matter-labs", "owner": "matter-labs",
"repo": "nixsgx", "repo": "nixsgx",
"rev": "871d35a3c99e6de9ad64ba36b30d7a49357cafb1", "rev": "b792d5ea46a8600b9a03c2a3bf51dc106f8bcfdd",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -2281,11 +2281,11 @@
"nixpkgs-stable": "nixpkgs-stable_2" "nixpkgs-stable": "nixpkgs-stable_2"
}, },
"locked": { "locked": {
"lastModified": 1712617241, "lastModified": 1715482972,
"narHash": "sha256-a4hbls4vlLRMciv62YrYT/Xs/3Cubce8WFHPUDWwzf8=", "narHash": "sha256-y1uMzXNlrVOWYj1YNcsGYLm4TOC2aJrwoUY1NjQs9fM=",
"owner": "Mic92", "owner": "Mic92",
"repo": "sops-nix", "repo": "sops-nix",
"rev": "538c114cfdf1f0458f507087b1dcf018ce1c0c4c", "rev": "b6cb5de2ce57acb10ecdaaf9bbd62a5ff24fa02e",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -2556,11 +2556,11 @@
}, },
"unstable": { "unstable": {
"locked": { "locked": {
"lastModified": 1712608508, "lastModified": 1715787315,
"narHash": "sha256-vMZ5603yU0wxgyQeHJryOI+O61yrX2AHwY6LOFyV1gM=", "narHash": "sha256-cYApT0NXJfqBkKcci7D9Kr4CBYZKOQKDYA23q8XNuWg=",
"owner": "nixos", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "4cba8b53da471aea2ab2b0c1f30a81e7c451f4b6", "rev": "33d1e753c82ffc557b4a585c77de43d4c922ebb5",
"type": "github" "type": "github"
}, },
"original": { "original": {

View file

@ -67,5 +67,36 @@
]; ];
}; };
systemd.services = {
check_boot = {
serviceConfig = {
Type = "oneshot";
Environment = "PATH=/run/current-system/sw/bin";
ExecStart = toString (
pkgs.writeShellScript "check_boot.sh" ''
CURRENT=$(df /boot | grep /boot | awk '{ print $5}' | sed 's/%//g')
THRESHOLD=85
if [ "$CURRENT" -gt "$THRESHOLD" ] ; then
${pkgs.mailutils}/bin/mail -s '/boot Disk Space Alert' harald << EOF
Your /boot partition remaining free space is critically low. Used: $CURRENT%
EOF
fi
''
);
};
wantedBy = [ "default.target" ];
};
};
systemd.timers = {
check_boot = {
timerConfig = {
OnCalendar = "daily";
};
wantedBy = [ "timers.target" ];
};
};
system.stateVersion = "23.05"; system.stateVersion = "23.05";
} }