我在“logrotate.d”目录中添加了两个脚本,以便旋转我的应用程序日志。 这是其中之一的configuration:
<myLogFilePath> { compress copytruncate delaycompress dateext missingok notifempty daily rotate 30 }
在“cron.daily”目录中有一个“logrotate”脚本(它似乎每日按照cron日志运行):
#!/bin/sh echo "logrotate_test" >>/tmp/logrotate_test #/usr/sbin/logrotate /etc/logrotate.conf >/dev/null 2>&1 /usr/sbin/logrotate -v /etc/logrotate.conf &>>/root/logrotate_error EXITVALUE=$? if [ $EXITVALUE != 0 ]; then /usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]" fi exit 0
第一个回声声明正在工作。
但我发现我的应用程序日志本身并没有得到旋转,而像httpd其他日志正在旋转**
**我也看不到在所提到的“logrotate_error”文件中的任何输出 (对所有用户都有写入权限)。
但系统日志说: “logrotate:ALERTexception退出与[1]”
但是当我手动运行“cron.daily”脚本中的相同的“logrotate”,一切似乎工作正常。
为什么在日常计划中不旋转? 我在这里做错了什么?
如果我得到这个非常需要的帮助,这将是非常好的。
更新:它看起来像是因为selinux – 我的用户主目录中的日志文件受到selinux和logrotate脚本运行时的限制:
SELinux is preventing /usr/sbin/logrotate from getattr access on the file /home/user/logs/application.log
SELinux限制了对不具有所需SELinux文件上下文types的目录中的日志文件进行logrotate访问。 “/ var / log”目录中有“var_log_t”文件上下文,而logrotate能够做到这一点。 所以解决办法是在我的应用程序日志文件上设置它,它的父目录:
semanage fcontext -a -t var_log_t <directory/logfile> restorecon -v <directory/logfile>