Skip to content
This repository was archived by the owner on Mar 19, 2022. It is now read-only.

Latest commit

 

History

History
52 lines (42 loc) · 2.21 KB

File metadata and controls

52 lines (42 loc) · 2.21 KB

Day 18

Notes

  • logrotate --debug /etc/logrotate.conf gives dump of what actually will be performed without actually performing it. So it becomes handy for testing the configuration changes made to /etc/logrotate.d/apache2
  • Apparently, logrotate is handled by systemd timer (see systemctl status logrotate, and systemctl status logrotate.timer) instead of cron (see less /etc/cron.daily/logrotate which has a line skip in favour of systemd timer).
  • /etc/logrotate.d/apache2 already had daily in it so I changed the no.of copies it keeps to 10 from 12 and compression from default (gzip) to bzip2
/etc/logrotate.d/apache2
/var/log/apache2/*.log {
        daily
        missingok
        rotate 10
        compress
        compresscmd /usr/bin/bzip2
        delaycompress
        ...
  • Created a file /var/log/mylogfile.log, changed its perm to -rw-r--r-- root adm and echoed some text into it. (Making a secret dir like this is soo cool, just change the perm to 710 root normaluser).
  • Created corresponding logrotate config for the above file
/etc/logrotate.d/mylogfile
/var/log/mylogfile.log {
        size 2
        rotate 1
        maxage 2
        su root adm
        compress
        compresscmd /usr/bin/bzip2
        notifempty
        copytruncate
}

The line su root adm is copied from /etc/logrotate.conf into this because I intend to run this conf file standalone (for immediate testing, although this conf file is included in the main conf file /etc/logrotate.conf) as -

sudo logrotate /etc/logrotate.d/mylogfile

This will create /var/log/mylogfile.log.1.bz2 with the contents from /var/log/mylogfile.log and truncate the later to 0. You can view the former by less or zless.

  • Seen /var/log/apache2/ for the logs the next day, they had changed extensions, as expected.

Readings