Logrotate根据cron运行,但日志不旋转

我通过cron与脚本运行logrotate

 [alex@leia ~]$ cat /etc/cron.daily/logrotate #!/bin/sh /usr/sbin/logrotate /etc/logrotate.conf >/dev/null EXITVALUE=$? if [ $EXITVALUE != 0 ]; then /usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]" fi exit 0 

根据系统日志,它应该工作:

 Dec 14 03:21:01 leia run-parts(/etc/cron.daily)[3041]: starting logrotate Dec 14 03:21:01 leia run-parts(/etc/cron.daily)[3063]: finished logrotate 

我期望这也运行以下指令:

 [alex@leia ~]$ cat /etc/logrotate.d/www-data_uwsgi_nginx /home/www-data/*/logs/*/*log { rotate 5 size 20M nocompress missingok postrotate touch /tmp/uwsgi-reload [ ! -f /var/run/nginx.pid ] || kill -USR1 `cat /var/run/nginx.pid` endscript sharedscripts } 

但! 它不会在/home/www-data下旋转日志。 其他日志得到旋转。 如果我手动运行logrotate

 [alex@leia ~]$ sudo logrotate /etc/logrotate.conf 

确实旋转了有问题的日志。

我看到了SELinux问题的相关问题 ,并试图解决这个问题 ,但对我来说并没有帮助。


编辑:根据要求,/ /etc/logrotate.conf的内容:

 # see "man logrotate" for details # rotate log files weekly weekly # keep 4 weeks worth of backlogs rotate 4 # create new (empty) log files after rotating old ones create # use date as a suffix of the rotated file dateext # uncomment this if you want your log files compressed #compress # RPM packages drop log rotation information into this directory include /etc/logrotate.d # no packages own wtmp and btmp -- we'll rotate them here /var/log/wtmp { monthly create 0664 root utmp minsize 1M rotate 1 } /var/log/btmp { missingok monthly create 0600 root utmp rotate 1 } # system-specific logs may be also be configured here. 

我在#centos上寻求帮助,看来SELinux是个问题。 根据aureport -a SELinux否认在logrotate_t上下文中访问主目录中具有user_home_t标签的文件 – 一旦你知道SELinux是如何工作的,这并不是什么大惊喜!

我决定重新标记日志文件的目录(尾随.*使修改recursion):

 # semanage fcontext -a -t var_log_t "/home/www-data/.*/logs/.*" # restorecon -r /home/www-data/*/logs 

我select了var_log_t标签,因为它有点意义,碰巧是我知道应该工作。 我想使用一个更有意义的标签,但是我不知道如何列出工作标签。 创造一个新的政策或许是可能的,但这对我的目的似乎过分了。

我将不得不等待几天,然后看看它是否有效,但我怀疑它会!

编辑:它像一个魅力工作! 我现在很开心。