Without log rotation, application logs grow forever until they fill the disk — logrotate is the standard, cron-driven tool that prevents exactly that on virtually every Linux server.
/var/log/myapp/*.log {
daily
rotate 14
compress
delaycompress
missingok
notifempty
create 0640 myapp myapp
postrotate
systemctl reload myapp > /dev/null 2>&1 || true
endscript
}
# Test a config without actually rotating anything sudo logrotate -d /etc/logrotate.d/myapp # Force a rotation right now, for testing sudo logrotate -f /etc/logrotate.d/myapp
Why postrotate Matters
Many applications keep a log file open by file descriptor, not by name — simply renaming the file (which is what rotation does) doesn’t make the app start writing to the new file. The postrotate script’s reload/restart signal tells the application to reopen its log file, without which it keeps writing to the now-renamed (and eventually compressed) old file forever.