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:
parent
0032016cfa
commit
86b3ff2cb0
|
@ -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";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue