增加从postfix启动的脚本的日志文件的文件大小

我使用Postfix在邮件发送到特定地址时运行脚本。 该脚本是一个Perl脚本,它使用Log4perl将日志写入文件。 Log4perl每天都在轮转日志文件。

除了一个小angular落的情况下,它运作良好。 日志文件大小超过50MB时,脚本无法写入日志文件。

在对Postfix进行一些研究之后,看起来这可能是Postfix的一个限制。 这是postconf中可能相关的输出的一部分。

 $ postconf | grep size berkeley_db_create_buffer_size = 16777216 berkeley_db_read_buffer_size = 131072 body_checks_size_limit = 51200 bounce_size_limit = 50000 header_size_limit = 102400 mailbox_size_limit = 51200000 message_size_limit = 10240000 tcp_windowsize = 0 $ postconf | grep virtual_mailbox_limit virtual_mailbox_limit = 51200000 

是否有任何可以更改的选项来删除从脚本创build的日志文件的文件大小的50MB限制

以下是完整性的Log4perl设置。

 $ cat /some/path/to/my/log4perlsettings.cfg log4perl.logger.mylog = DEBUG,LOGGER log4perl.appender.LOGGER = Log::Dispatch::FileRotate log4perl.appender.LOGGER.TZ=PST log4perl.appender.LOGGER.DatePattern=yyyy-MM-dd log4perl.appender.LOGGER.filename = /some/path/to/my/logs/logfile.log log4perl.appender.LOGGER.mode = append log4perl.appender.LOGGER.max = 30 log4perl.appender.LOGGER.layout = PatternLayout log4perl.appender.LOGGER.layout.ConversionPattern = [%d] %P %p %r %H %F %L %C - %m%n 

这些可能不相关,但这里是Postfix的别名设置:

 $ grep -r myscript /etc/postfix/ /etc/postfix/virtual:[email protected] myscript $ grep -r myscript /etc/aliases myscript: "|/some/path/to/my/script.pl" 

编辑

这里是/var/log/maillog的输出。 这很多次重复。

 Dec 13 10:59:22 mymachine postfix/cleanup[22052]: EB5EA80196: message-id=<[email protected]> Dec 13 10:59:22 mymachine postfix/bounce[22431]: 7C11080190: sender non-delivery notification: EB5EA80196 Dec 13 10:59:22 mymachine postfix/qmgr[2109]: EB5EA80196: from=<>, size=3456, nrcpt=1 (queue active) Dec 13 10:59:22 mymachine postfix/qmgr[2109]: 7C11080190: removed Dec 13 10:59:23 mymachine postfix/smtp[22342]: EB5EA80196: to=<[email protected]>, relay=mail.example.net[192.168.1.11]:25, delay=0.04, delays=0.01/0/0/0.03, dsn=2.0.0, status=sent (250 ok 1418435963 qp 19340) Dec 13 10:59:23 mymachine postfix/qmgr[2109]: EB5EA80196: removed Dec 13 10:59:39 mymachine postfix/smtpd[21267]: connect from unknown[192.168.2.12] Dec 13 10:59:39 mymachine postfix/smtpd[21267]: CA0AB80190: client=unknown[192.168.2.12] Dec 13 10:59:39 mymachine postfix/cleanup[21893]: CA0AB80190: message-id=<[email protected]> Dec 13 10:59:39 mymachine postfix/smtpd[21267]: disconnect from unknown[192.168.2.12] Dec 13 10:59:39 mymachine postfix/qmgr[2109]: CA0AB80190: from=<[email protected]>, size=712, nrcpt=1 (queue active) Dec 13 10:59:40 mymachine postfix/local[21269]: CA0AB80190: to=<[email protected]>, relay=local, delay=0.43, delays=0.02/0/0/0.4, dsn=5.3.0, status=bounced (Command died with status 27: "/some/path/to/my/script.pl". Command output: Cannot write to '/some/path/to/my/logs/logfile.log': File too large at /usr/local/share/perl5/Log/Dispatch/File.pm line 141. ) Dec 13 10:59:40 mymachine postfix/cleanup[22052]: 3B8FD80196: message-id=<[email protected]> Dec 13 10:59:40 mymachine postfix/bounce[22431]: CA0AB80190: sender non-delivery notification: 3B8FD80196 Dec 13 10:59:40 mymachine postfix/qmgr[2109]: 3B8FD80196: from=<>, size=2897, nrcpt=1 (queue active) Dec 13 10:59:40 mymachine postfix/qmgr[2109]: CA0AB80190: removed Dec 13 10:59:40 mymachine postfix/smtp[21679]: 3B8FD80196: to=<[email protected]>, relay=mail.example.net[192.168.1.11]:25, delay=0.04, delays=0/0/0/0.03, dsn=2.0.0, status=sent (250 ok 1418435980 qp 19356) Dec 13 10:59:40 mymachine postfix/qmgr[2109]: 3B8FD80196: removed 

重要的路线可能是这一个:

 Dec 13 10:59:40 mymachine postfix/local[21269]: CA0AB80190: to=<[email protected]>, relay=local, delay=0.43, delays=0.02/0/0/0.4, dsn=5.3.0, status=bounced (Command died with status 27: "/some/path/to/my/script.pl". Command output: Cannot write to '/some/path/to/my/logs/logfile.log': File too large at /usr/local/share/perl5/Log/Dispatch/File.pm line 141. ) 

/some/path/to/my/logs/logfile.log的文件大小是50MB(51200000字节)时,此错误开始发生。

编辑2

当从命令行调用perl脚本(即,不从Postfix调用)时,perl脚本运行正确。

这确实是从后缀inheritance的限制。 原因在于,当您通过将订单交付给pipe道来写入脚本时,则将其视为邮箱,就像直接写入文件一样。 因此,无论在后缀传递代理上设置的限制都将由脚本inheritance。

我可以想到三种方法来解决这个问题:

  1. 你改变你的后缀configuration的限制; 你已经指出了限制的来源。
  2. 您经常运行logrotate,以便文件不会超过50 MB。
  3. 您可以更改脚本以使用Log :: Dispatch :: FileRotate中提供的logrotate函数,以便在文件超过50 MB时自动旋转文件。