Also available in Spanish: leer en castellano.
Some problems announce themselves loudly. This one did not. My Orange Pi boards kept hitting the same quiet wall: the folder where the system writes its logs filled up, and then services simply could not write any more. Nothing dramatic, just a growing list of things that stopped working for no obvious reason.
The cause turned out to be a sensible design choice. On Armbian and many Debian-based ARM boards, /var/log lives in RAM (in zram or tmpfs, with tools like armbian-ramlog or log2ram) to spare the SD card from constant writes. It is a good idea, and it makes the folder small. When it fills, it stays full.
Digging into how it all works, I realised the answer was not to fight the design but to look after it: a small system service that quietly purges old logs before the folder fills up. That is logguard.
What it does
A systemd timer runs a Python script (standard library only) every minute. If the free space drops below a threshold, 15 % by default, it moves the old logs to a persistent folder outside /var/log, keeps them for 24 hours, and then purges them. It escalates step by step and stops as soon as there is enough room again:
- Rotated logs go to the archive, compressed, oldest first.
- Stale files, not rotated but untouched for a day, follow them.
- The journal is vacuumed to a size you choose.
- Optionally,
logrotateis forced. - As a last resort, it saves the tail of the biggest active text logs and truncates them. Binary files are never truncated.
Careful by design
A tool that deletes logs should be cautious, so logguard is:
- It never moves or truncates a file that a process has open, except for the last-resort truncation of text logs.
- Each run goes into its own dated directory, so purging never depends on file times, and it never deletes a directory that does not look like one of its own batches.
- If the archive destination is short of space, it does not archive.
- A lock prevents two runs from overlapping.
- If it cannot recover enough space, it exits with an error, so the service shows as failed in systemd and you find out.
And when there is nothing to clean, it writes nothing to the journal. A guard should be quiet.
Try it
Download the .deb from the releases page. It is architecture independent, so it works on armhf and arm64 alike:
sudo apt install ./logguard_1.0.5_all.deb
logguard --status
On install it enables and starts the timer, and on upgrade it keeps your /etc/logguard.conf. logguard -n -v does a dry run with verbose output, so you can see what it would do before it does anything.
Standing on good shoulders
logguard does not replace the tools around it; it lives alongside them. Thanks to the Armbian project and to log2ram for making RAM logs a practical choice, to systemd for the timer, and to logrotate for doing the everyday rotation that logguard only steps in to support.
The code is on GitHub under the MIT license. If you keep Orange Pis at home, you may also like lanwatch and internet-check.