Working on a friends server earlier this morning I noticed that he had logrotate configured but he did not have a configuration file for Postfix. Below is the quick one I whipped up for his environment including a brief explanation of each line of the configuration file below the script. Following the explanation of the various configurations is the command to actually force logrotate to run in debug mode so you can see what happens.
Gentoo Linux Postfix Logrotate Script:
- /var/log/mail.* {
- missingok
- notifempty
- weekly
- rotate 3
- compress
- sharedscripts
- postrotate
- /etc/init.d/postfix reload > /dev/null 2>&1 || true
- endscript
- }
The above logrotate configuration file should go in the /etc/logrotate.d directory and be named postfix. Open your favorite text editor and paste the above into it and then save the file with the name “postfix”.
Postfix Logrotate Configuration Script Options:
- missingok: it is ok if the log files are missing
- notifempty: will not rotate the log files if they are empty
- weekly: rotate the logs weekly
- rotate 3: log files will be rotated 3 times before they are removed from the server
- compress: when the log files are rotated they will be compressed with gzip
- sharedscripts: specifies that the postrotate script will only be run once after all postfix logs are rotated.
- postrotate: will run the script on the next line after all logs have rotated
- endscript: end of the postrotate script
There are many other options for logrotate as well. You can rotate on a different amount of time or based on the size of the log file. Use the logrotate manpage if you require more information about other options available. The below command is how logrotate can be forced to run and output the actions in debug mode.
Force Logrotate To Run And Output In Debug Mode:
- server etc # logrotate -fd /etc/logrotate.conf
The above will spit out a bunch of data regardless of if it actually rotates logs or not. The initial output data will list all of the configuration files loaded into logrotate followed by the actual results of each log file it encounters. You now have Postfix mail logs rotating on your Gentoo Linux server.