2026-01-13 09:59:39 -03:00
|
|
|
#!/usr/bin/env bash
|
2026-10-03 01:25:25 -05:00
|
|
|
# Kubelet owns image and container-log rotation; this guard only protects
|
|
|
|
|
# constrained log mounts and caps the host journal. It never restarts k3s.
|
2026-01-13 09:59:39 -03:00
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
|
|
journald_dropin="/host/etc/systemd/journald.conf.d/99-logging.conf"
|
2026-10-03 01:25:25 -05:00
|
|
|
expected="[Journal]
|
2026-03-31 00:06:44 -03:00
|
|
|
Storage=volatile
|
|
|
|
|
RuntimeMaxUse=200M
|
|
|
|
|
RuntimeKeepFree=512M
|
|
|
|
|
MaxFileSec=1h"
|
2026-10-03 01:25:25 -05:00
|
|
|
if [[ ! -f "$journald_dropin" ]] || [[ $(cat "$journald_dropin") != "$expected" ]]; then
|
|
|
|
|
mkdir -p "$(dirname "$journald_dropin")"
|
|
|
|
|
printf '%s\n' "$expected" > "$journald_dropin"
|
|
|
|
|
chroot /host /bin/systemctl restart systemd-journald
|
2026-01-13 09:59:39 -03:00
|
|
|
fi
|
|
|
|
|
|
2026-04-27 16:31:57 -03:00
|
|
|
trim_constrained_pod_logs() {
|
|
|
|
|
local base usage
|
|
|
|
|
for base in /host/mnt/astraios/var/log /host/var/log.hdd; do
|
|
|
|
|
if [ ! -d "${base}/pods" ]; then
|
|
|
|
|
continue
|
|
|
|
|
fi
|
|
|
|
|
usage="$(df -P "${base}" | awk 'NR==2 {gsub(/%/, "", $5); print $5}')"
|
2026-04-27 16:42:02 -03:00
|
|
|
if [ -z "${usage}" ] || [ "${usage}" -lt 75 ]; then
|
2026-04-27 16:31:57 -03:00
|
|
|
continue
|
|
|
|
|
fi
|
2026-04-27 16:49:11 -03:00
|
|
|
find "${base}/pods" -type f \( -name '[1-9]*.log' -o -name '*.log.20*' \) -size +1M -print -exec truncate -s 0 {} \; 2>/dev/null || true
|
2026-05-21 13:26:58 -03:00
|
|
|
# Some nodes keep active container logs on tiny zram-backed /var/log.
|
|
|
|
|
# Trim noisy live logs before kubelet loses the ability to create pods.
|
|
|
|
|
find "${base}/pods" -type f -name '0.log' -size +1M -print -exec truncate -s 1M {} \; 2>/dev/null || true
|
2026-04-27 16:31:57 -03:00
|
|
|
if [ -d "${base}/containers" ]; then
|
|
|
|
|
find "${base}/containers" -xtype l -print -delete 2>/dev/null || true
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while true; do
|
|
|
|
|
trim_constrained_pod_logs
|
|
|
|
|
sleep 600
|
|
|
|
|
done
|