The logrotate utility on Ubuntu automates the compression, archiving, and deletion of system log files stored in /var/log/, preventing storage solid-state drives from filling to capacity. Managed via a systemd timer (logrotate.timer), logrotate runs daily maintenance tasks. When systemd logs “Failed to start logrotate.service: Rotate log files”, log files accumulate unchecked. Resolving this issue involves verifying configuration syntax and repairing state file permissions.
Check Service Status and Systemd Journal Output
Determine the exact exit code or configuration failure preventing logrotate from completing its rotation pass.
- Open a terminal (Ctrl + Alt + T).
- Query the systemd service status:
systemctl status logrotate.service - Inspect detailed journal logs for parser errors:
sudo journalctl -u logrotate -b --no-pager - Note which specific configuration file in
/etc/logrotate.d/is flagged as erroneous.
Execute a Manual Dry-Run in Verbose Debug Mode
Running logrotate manually in test mode isolates permission violations or invalid directives without altering live log files.
- Execute a verbose dry-run:
sudo logrotate -d /etc/logrotate.conf - The utility will simulate rotating every configured log file and print line-by-line debug output.
- If an orphaned application configuration file (e.g. from an uninstalled package) references a non-existent log directory without the
missingokdirective, remove or edit the file.
Repair Permissions on /var/lib/logrotate/status
Logrotate records timestamp markers in its status ledger file. If permissions become corrupted, the service aborts.
- Inspect ownership on the status file:
ls -la /var/lib/logrotate/status - Ensure ownership is assigned to
root:rootwith 644 permissions:sudo chown root:root /var/lib/logrotate/status sudo chmod 644 /var/lib/logrotate/status - If the status file is corrupted or unreadable, remove it so logrotate can regenerate a clean ledger:
sudo rm -f /var/lib/logrotate/status sudo logrotate -v /etc/logrotate.conf