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

前端之家收集整理的这篇文章主要介绍了从后缀启动的脚本增加日志文件的文件大小前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
每当将消息发送到特定地址时,我都使用Postfix来运行脚本.该脚本是一个Perl脚本,它使用 Log4perl将日志写入文件.日志文件由Log4perl每天轮换.

除了一个小角落外,它运作良好.当日志的文件大小超过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

是否有任何选项可以更改以删除从脚本创建的日志文件文件大小的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:myscript@mymachine.example.net        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=<20141213015922.EB5EA80196@mymachine.example.net>
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=<root@othermachine.example.net>,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=<20141213015939.B625B1228002@othermachine2.example.net>
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=<root@othermachine2.net>,size=712,nrcpt=1 (queue active)
Dec 13 10:59:40 mymachine postfix/local[21269]: CA0AB80190: to=<myscript@mymachine.example.net>,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=<20141213015940.3B8FD80196@mymachine.example.net>
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=<root@othermachine2.example.net>,delays=0/0/0/0.03,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=<myscript@mymachine.example.net>,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的filesize为50MB(51200000字节)时,会发生此错误.

EDIT2:

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

解决方法

这确实是从后缀继承的限制.原因是,当您通过将交付指向管道来写入脚本时,那将被视为邮箱,就像您直接写入文件一样.因此,后缀传递代理上设置的任何限制都将由脚本继承.

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

>您更改后缀配置中的限制;你已经确定了限制的来源.
>您经常运行logrotate,因此文件不会超过50 MB.
>您更改脚本以使用Log::Dispatch::FileRotate中提供的logrotate函数,以便文件在超过50 MB时自动旋转.

原文链接:https://www.f2er.com/Perl/172410.html

猜你在找的Perl相关文章