Skip to content

Logrotate setup does not prevent /var/log filling up #103

Closed
@borpin

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.

  1. Purge and reinstall rsyslog to restore default configuration
  2. Setup rsyslog to extract emonhub messages and not put them in daemon.log or syslog 10-emonhub.conf below.
  3. Delete excessive daemon.log sudo truncate -s 0 /var/log/daemon.log
  4. Restart the rsyslog service sudo systemctl restart rsyslog.service
  5. Delete conf files installed by emoncms
sudo rm /etc/logrotate.conf
sudo rm /etc/cron.daily/logrotate
sudo rm /etc/cron.hourly/logrotate
  1. Reinstall logrotate to restore default setup
sudo apt-get purge logrotate
sudo apt-get install logrotate
  1. Install logrotate file to handle emonhub.log /etc/logrotate.d/emonhub
  2. 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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions