I noticed my mail.info and mail.log was starting to grow rather ... big. I then created a simple logrotate script for postfix. It would be great if it got tested and installed with the latest postfix ebuild.
Created attachment 99390 [details] postfix logrotate script qmail, exim etc users browing here by accident, This script can work for you just as well if you replace postfix with qmail inside the script, given that 'reload' restarts writing log files. If not, also replace reload with restart.
(In reply to comment #1) > Created an attachment (id=99390) [edit] > postfix logrotate script > > qmail, exim etc users browing here by accident, This script can work for you > just as well if you replace postfix with qmail inside the script, given that > 'reload' restarts writing log files. If not, also replace reload with restart. > then why don't we let logrotate provide that file instead. BTW, syglog-ng does not log to mail.* by default.
I don't know what syslog-ng does by default, but something by gentoo-default made it log to mail.* I haven't changed it, some default gentoo setting has. As for supplying it with logrotate, I don't know if it should supply the scripts for all possible apps? There's might be differences between all mailers, you have to restart your mailer and thus it's not a 'generic' solution.
I think each program should supply it's own logrotate file. I guess logrotate is fairly common on Linux/Unix machines, so I would tend to include the rotate file by default. Maybe a "logrotate" or "nologrotate" USE flag? Apache does this (without the USE flag): see bug 42537. As for Postfix: does Postfix itself writes /var/log/mail.*, or does it give that to the system logger? If the system logger writes the actual file, then Postfix doesn't need to know when the log files are rotated. If this is the case, the logrotate file should be provided by the logger - the postrotate script would then be independent of the mailer.
(In reply to comment #4) > As for Postfix: does Postfix itself writes /var/log/mail.*, or does it give > that to the system logger? If the system logger writes the actual file, then > Postfix doesn't need to know when the log files are rotated. If this is the > case, the logrotate file should be provided by the logger - the postrotate > script would then be independent of the mailer. Postfix uses the "mail" facility of system logger. Therefore it is impossible to determine location and name of mail log files, as these can be dictated by said logger configuration. There doesn't even have to be a separate log file for mail facility, if someone configures his system logger to put for example "mail" and "cron" facility logs into one file.
(In reply to comment #5) > Postfix uses the "mail" facility of system logger. Therefore it is impossible > to determine location and name of mail log files Then each of the sysloggers could provide a logrotate file according to their defaults. In the case of sysklogd, 'mail.err', 'mail.info', 'mail.log', and 'mail.warn'. Administrators changing the syslogger's default would also have to ajust the rotation file.
So there's 2 options. Supply rotate files for every MTA out there, and generate/get/assume the directory/file in question (/var/log/mail.*) or Let the packages maintain the rotate files, and set the default directory/file to whatever the packages ebuild mail loging is setup (e.g. via syslog*, seperate mailfiles, syslogs's mail facility). Since the package knows everything about the files in questions, it sounds sensible to me that MTA's supply their own rotate file. Also keeping the useless files out of the system. E.g. why need 6 rotate files for 6 MTA's installed, when i don't even have one installed. So i say/vote/opinion/whatever use the supplied script, add it to the postfix ebuild and we're all happy :) (there's a minor typo in the comment, Contributes -> Contributed)
In the case of Postfix, it doesn't know anything about the log files because it asks syslog to take care of it. That's why I was saying syslog should handle the mail.* logs. Exim, qmail, and sendmail might be different - I don't know. Basically: the package that writes the file should provide the logrotate script.
Hmm, So you either end up with a bunch of rotate files, that you may have no use off, which I find to be messy, or postfix supplies the file, but doesn't know which files need to be rotated, e.g. /var/log/mail.* or maybe a private logfile, /var/log/postfix/postfix.log since afaik you can choose wether to use syslog or built in logger. In the sense of keeping crap off systems, I still feel to add the file to postfix's ebuild. It belongs to it. Just like conf.d and init.d files belong to it aswell.
(In reply to comment #9) > In the sense of keeping crap off systems, I still feel to add the file to > postfix's ebuild. It belongs to it. Just like conf.d and init.d files belong to > it aswell. No, logrotate file does not belong to postfix, as its default setting is to log via system logger. If you change the configuration to have postfix write log files directly, then you need to provide your own logrotate script. I'm sending this bug to base-system, as they maintain metalog and sysklogd, two most common syslog daemons, both of which log mail facility to separate files. They can decide whether to add this support to the packages or not.
it's up to individual packages to install small logrotate snippets into /etc/logrotate.d/ see the logrotate USE flag
I know about the USE flag, but I agree with Sylvain - postfix doesn't know anything about log files itself. I couldn't even find a way to make postfix write its own log files, so I assume it relies on system logger. Therefore system loggers should provide logrotate scripts for mail facility log files - in fact, for any and all log files they create with default configurations. Syslog-ng does that, although that one doesn't log mail facility separately. vapier?
(In reply to comment #9) > Hmm, So you either end up with a bunch of rotate files, that you may have no > use off, which I find to be messy Actually, no. Any MTA that uses sysklogd will have its log end up in "mail.*". sysklogd doesn't need separate logrotate files for each MTA. Since each computer has no more than one syslogger, there would be only a single logrotate file for mail - even if you were to have mutliple MTAs on your system. On the other hand, if the MTA is to provide the logrotate file, it has to provide as many logrotate files as there are sysloggers in Portage, because it doesn't know which one is installed. So there you end up with multiple files that you are sure you won't use except for one. And should a new syslogger be introduced into Portage, we have to update all the packages that rely on a syslogger. (In reply to comment #9) > it's up to individual packages to install small logrotate Yes, and the package that handles those files is the syslogger's. Another situation is one where the MTA and the system logger are on different systems. Having the logrotate snippet in the MTA's package can never rotate the log files, because those are stored on another computer, which doesn't have an MTA, and therefore no logrotate snippet. Granted, that situation won't happen often, and won't be done by first-time users, but having the syslogger provide the logrotate snippet would prevent having to configure more that the syslogger redirection.
The only one that knows where stuff is being logged to is the system logger. It is up to the logger to rotate its files, nothing to do with postfix. Thats one of the joys of centralizing stuff... However, we could offer an example logrotate file that rotates mail.* files... it is silly in my opinion, but we can do it. Anyway, I don't think we'll install that by default in /etc/logrotate.d... /usr/share/doc/${PF} sounds like a plan. - ferdy
oh, i see ... i was under the impression postfix was doing the logging metalog does not need any logrotate cruft as it does file rotation itself as to whether it's better to include the snippet with the system logger or logrotate, i guess that it's prob better with the system logger as already noted
metalog has its internal logic to rotate logfiles, syslog-ng installs a configfile for logrotate which also includes rotating mail.* logfiles and sysklogd installs a cron script for logrotation which includes explanations for adding logfiles to rotate - i guess this one can be closed? doing so - feel free to reopen if you disagree.