Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
borpin opened this issue May 1, 2019 · 3 comments
Closed

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

borpin opened this issue May 1, 2019 · 3 comments

Comments

@borpin
Copy link
Contributor

borpin commented May 1, 2019

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
}
@borpin
Copy link
Contributor Author

borpin commented Oct 25, 2019

This should be fixed by Log2Ram and non SD install script changes.

@borpin borpin closed this as completed Oct 25, 2019
@camelcamro
Copy link

it is still filling up. but if i check the files via du , then i have only
df -h
log2ram 50M 29M 22M 58% /var/log

du -h /var/log
root@emonpi:/var/log# du -h
4,0K ./redis
0 ./private
0 ./mysql
4,0K ./mosquitto
232K ./logrotate
188K ./emonpilcd
4,0K ./emonhub
28K ./emoncms
28K ./apt
0 ./apache2
1,7M

is there no cleanup script to keep log2ram clean and purged ?

@borpin
Copy link
Contributor Author

borpin commented Dec 15, 2022

This is closed. If you believe there is an issue, please open a new one a reference this.

Please also format your message correctly so code/bash output is easily read.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants