我在“logrotate.d”目录中添加了两个脚本,以便轮换我的应用程序日志。这是其中之一的配置:
<myLogFilePath> {
compress
copytruncate
delaycompress
dateext
missingok
notifempty
daily
rotate 30
}
Run Code Online (Sandbox Code Playgroud)
“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
Run Code Online (Sandbox Code Playgroud)
第一个 echo 语句正在运行。
但是我发现我的应用程序日志本身没有轮换,而其他日志(如 httpd)正在轮换 **
**而且我也没有在提到的“logrotate_error”文件中看到任何输出(对所有用户都有写权限)。
但是系统日志显示:“logrotate:ALERT 异常退出 [1]”
但是当我手动在“cron.daily”脚本中运行相同的“logrotate”时,一切似乎都正常。
为什么它在每日 cron 计划中不轮换?我在这里做错了吗?
如果我能得到这些急需的帮助,那就太好了。
更新: 看起来,这是因为 selinux - 我的用户主目录中的日志文件受到 selinux 的限制,并且运行 logrotate 脚本时:
SELinux is preventing /usr/sbin/logrotate from getattr access on the …Run Code Online (Sandbox Code Playgroud)