Logrotate:Postrotate setfacl 失败,没有这样的文件或目录错误

Logrotate:Postrotate setfacl 失败,没有这样的文件或目录错误

/var/log/squid3/我为和设置了一些扩展 ACL 条目/var/log/squid3/access.log

sudo setfacl -m u:jetty:r-x,g:adm:r-x /var/log/squid3
sudo setfacl -m u:jetty:r--,g:adm:r-- /var/log/squid3/access.log

由于日志每天都在轮换,我每天都会丢失 ACL。

我进行了编辑sudo nano /etc/logrotate.d/squid3,但是没有作用。

running postrotate script
setfacl: /var/log/squid3/access.log: No such file or directory
error: error running shared postrotate script for '/var/log/squid3/*.log '

我的 squid3 logrotate 片段:

/var/log/squid3/*.log {
        daily
        compress
        delaycompress
        rotate 2
        missingok
        nocreate
        sharedscripts
        prerotate
                test ! -x /usr/sbin/sarg-reports || /usr/sbin/sarg-reports
        endscript
        postrotate
                test ! -e /var/run/squid3.pid || test ! -x /usr/sbin/squid3 || /usr/sbin/squid3 -k rotate
                /usr/bin/setfacl -m u:jetty:r--,g:adm:r-- /var/log/squid3/access.log
        endscript
}

试运行结果如下sudo logrotate -vdf /etc/logrotate.d/squid3

reading config file /etc/logrotate.d/squid3

Handling 1 logs

rotating pattern: /var/log/squid3/*.log  forced from command line (2 rotations)
empty log files are rotated, old logs are removed
considering log /var/log/squid3/access.log
  log needs rotating
considering log /var/log/squid3/cache.log
  log needs rotating
rotating log /var/log/squid3/access.log, log->rotateCount is 2
dateext suffix '-20140307'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
compressing log with: /bin/gzip
renaming /var/log/squid3/access.log.2.gz to /var/log/squid3/access.log.3.gz (rotatecount 2, logstart 1, i 2), 
renaming /var/log/squid3/access.log.1.gz to /var/log/squid3/access.log.2.gz (rotatecount 2, logstart 1, i 1), 
renaming /var/log/squid3/access.log.0.gz to /var/log/squid3/access.log.1.gz (rotatecount 2, logstart 1, i 0), 
rotating log /var/log/squid3/cache.log, log->rotateCount is 2
dateext suffix '-20140307'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
compressing log with: /bin/gzip
renaming /var/log/squid3/cache.log.2.gz to /var/log/squid3/cache.log.3.gz (rotatecount 2, logstart 1, i 2), 
renaming /var/log/squid3/cache.log.1.gz to /var/log/squid3/cache.log.2.gz (rotatecount 2, logstart 1, i 1), 
renaming /var/log/squid3/cache.log.0.gz to /var/log/squid3/cache.log.1.gz (rotatecount 2, logstart 1, i 0), 
running prerotate script
running script (multiple) with arg /var/log/squid3/*.log : "
        test ! -x /usr/sbin/sarg-reports || /usr/sbin/sarg-reports
"
renaming /var/log/squid3/access.log to /var/log/squid3/access.log.1
renaming /var/log/squid3/cache.log to /var/log/squid3/cache.log.1
running postrotate script
running script (multiple) with arg /var/log/squid3/*.log : "
        test ! -e /var/run/squid3.pid || test ! -x /usr/sbin/squid3 || /usr/sbin/squid3 -k rotate
        /usr/bin/setfacl -m u:jetty:r--,g:adm:r-- /var/log/squid3/access.log
"
removing old log /var/log/squid3/access.log.3.gz
removing old log /var/log/squid3/cache.log.3.gz

强制运行会出现错误:

sudo logrotate -vf /etc/logrotate.d/squid3 
reading config file /etc/logrotate.d/squid3

Handling 1 logs

rotating pattern: /var/log/squid3/*.log  forced from command line (2 rotations)
empty log files are rotated, old logs are removed
considering log /var/log/squid3/access.log
  log needs rotating
considering log /var/log/squid3/cache.log
  log needs rotating
rotating log /var/log/squid3/access.log, log->rotateCount is 2
dateext suffix '-20140307'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
compressing log with: /bin/gzip
renaming /var/log/squid3/access.log.2.gz to /var/log/squid3/access.log.3.gz (rotatecount 2, logstart 1, i 2), 
renaming /var/log/squid3/access.log.1.gz to /var/log/squid3/access.log.2.gz (rotatecount 2, logstart 1, i 1), 
renaming /var/log/squid3/access.log.0.gz to /var/log/squid3/access.log.1.gz (rotatecount 2, logstart 1, i 0), 
old log /var/log/squid3/access.log.0.gz does not exist
rotating log /var/log/squid3/cache.log, log->rotateCount is 2
dateext suffix '-20140307'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
compressing log with: /bin/gzip
renaming /var/log/squid3/cache.log.2.gz to /var/log/squid3/cache.log.3.gz (rotatecount 2, logstart 1, i 2), 
renaming /var/log/squid3/cache.log.1.gz to /var/log/squid3/cache.log.2.gz (rotatecount 2, logstart 1, i 1), 
renaming /var/log/squid3/cache.log.0.gz to /var/log/squid3/cache.log.1.gz (rotatecount 2, logstart 1, i 0), 
old log /var/log/squid3/cache.log.0.gz does not exist
running prerotate script
renaming /var/log/squid3/access.log to /var/log/squid3/access.log.1
renaming /var/log/squid3/cache.log to /var/log/squid3/cache.log.1
running postrotate script
setfacl: /var/log/squid3/access.log: No such file or directory
error: error running shared postrotate script for '/var/log/squid3/*.log '

答案1

第一个猜测是,当执行/var/log/squid3/access.log该命令时该文件还没有被重新创建。setfacl

要解决这个问题,请nocreate在您的 logrotate 配置中删除或将其替换为create <mode> <owner> <group>在执行 postrotate 命令之前重新创建日志文件。

相关内容