Logrotate setup does not prevent /var/log filling up #103
Closed
Description
The current logrotate mechanism does not prevent /var/log filling up.
I propose a new mechanism that diverts the log messages from emonhub that currently end up in both daemon.log and syslog to its own log file and then rotate hourly. The rotated logs will be concatenated together to provide a daily log, rotated and retained for X days.
There are discussions ongoing on employing Log2Ram in the future, but this will work in the meantime.
This setup will leave all existing package rotation schemas alone.
- Purge and reinstall rsyslog to restore default configuration
- Setup rsyslog to extract emonhub messages and not put them in daemon.log or syslog
10-emonhub.confbelow. - Delete excessive daemon.log
sudo truncate -s 0 /var/log/daemon.log - Restart the rsyslog service
sudo systemctl restart rsyslog.service - Delete conf files installed by emoncms
sudo rm /etc/logrotate.conf
sudo rm /etc/cron.daily/logrotate
sudo rm /etc/cron.hourly/logrotate
- Reinstall logrotate to restore default setup
sudo apt-get purge logrotate
sudo apt-get install logrotate
- Install logrotate file to handle emonhub.log
/etc/logrotate.d/emonhub - Make logrotate run hourly
sudo mv /etc/cron.daily/logrotate /etc/cron.hourly/
/etc/rsyslog.d/10-emonhub.conf
template(name="EmonhubMsg" type="string" string="%msg:::drop-last-lf%\n")
if ( $programname == 'emonhub' or $programname == 'emonhub.py' ) then {
action(type="omfile" file="/var/log/emonhub/emonhub.log" template="EmonhubMsg")
stop
}
/etc/logrotate.d/emonhub
/var/log/emonhub/emonhub.log {
rotate 6
daily
size 2M
maxsize 2M
missingok
copytruncate
notifempty
postrotate
mv /var/log/emonhub/emonhub.log.1 /home/pi/data/
cat /home/pi/data/emonhub.log.1 >> /home/pi/data/emonhub.log
rm /home/pi/data/emonhub.log.1
endscript
}
/home/pi/data/emonhub.log {
su pi pi
rotate 10
daily
compress
missingok
notifempty
}
Metadata
Assignees
Labels
No labels