feat(systemd): add check_root service and timer

A new systemd service, `check_root`, has been added which checks disk usage of the root directory. If usage exceeds 85%, an email alert is sent. In addition to this service, a corresponding systemd timer is added to trigger this check daily.
This commit is contained in:
Harald Hoyer 2024-05-17 16:58:44 +02:00
parent 0032016cfa
commit 86b3ff2cb0

View file

@ -98,5 +98,36 @@
}; };
}; };
systemd.services = {
check_root = {
serviceConfig = {
Type = "oneshot";
Environment = "PATH=/run/current-system/sw/bin";
ExecStart = toString (
pkgs.writeShellScript "check_root.sh" ''
CURRENT=$(df / | grep / | 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 root partition remaining free space is critically low. Used: $CURRENT%
EOF
fi
''
);
};
wantedBy = [ "default.target" ];
};
};
systemd.timers = {
check_root = {
timerConfig = {
OnCalendar = "daily";
};
wantedBy = [ "timers.target" ];
};
};
system.stateVersion = "23.05"; system.stateVersion = "23.05";
} }