Keeping a long-running VPS tidy: logs and disk budgets

2026-10-29 · operationslinux

A server that runs for months rarely dies of one dramatic event. It fills up slowly, and the first symptom is something unrelated: a service refusing to start, a database writing half a page, a package manager failing with a vague error.

Start with a number

Pick a budget instead of waiting for a crisis. On a small disk I use something like: system and packages 60 %, application data 20 %, logs 10 %, headroom 10 %. The headroom is not waste — it is what turns a burst of log output into an annoyance instead of an outage.

df -h /
du -xhd1 /var 2>/dev/null | sort -h

Then find what actually grows. It is almost never what you expect. On my box the surprise was journal size, not application logs.

journald needs a ceiling too

Rotating /var/log/*.log while leaving the journal unlimited only moves the problem. In /etc/systemd/journald.conf:

[Journal]
SystemMaxUse=200M
SystemMaxFileSize=32M
MaxRetentionSec=2week

Then systemctl restart systemd-journald. Worth verifying with journalctl --disk-usage rather than trusting it.

logrotate: the part usually missed

Most distro packages ship a logrotate rule, so the trap is more often the opposite — a service you added yourself and never wrote a rule for. That log grows forever and nobody notices until the disk alarm.

/var/log/my-service/*.log {
    weekly
    rotate 4
    compress
    delaycompress
    missingok
    notifempty
    copytruncate
}

copytruncate is the compromise you make when the daemon cannot reopen its file on a signal. It is not perfectly atomic — a line written between the copy and the truncation can be lost. Fine for ordinary logs, not fine for anything you might need as evidence.

If the service supports reopening on SIGHUP, use that and skip copytruncate entirely.

Small files that are not small

Make it visible

A budget you never look at is not a budget. A five-minute timer that reports disk percentage, log directory size and journal usage catches the slow drift while there is still room to think. The alert should fire at 80 %, not 95 % — at 95 % you are already reacting.