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:
parent
bd2e13a215
commit
16e744e39e
2 changed files with 55 additions and 24 deletions
|
@ -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";
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue