ログファイルの親ディレクトリがo+wかグループがroot以外でg+wである場合はロテートしてくれないらしい
こんな感じの設定で
/var/log/logtest/logtest.log { copytruncate size 1 rotate 5 }
# ls -ld /var/log/logtest drwxrwxr-x 2 john john 24 Jan 8 22:19 /var/log/logtest # ls -l /var/log/logtest total 0 -rw-r--r-- 1 john john 0 Jan 8 22:18 logtest.log
としているとjohnグループが書き込み可能なのでロテートがスキップされる
# cat /var/log/logtest/logtest.log hello # logrotate /etc/logrotate.d/logtest error: skipping "/var/log/logtest/logtest.log" because parent directory has insecure permissions (It's world writable or writable by group which is not "root") Set "su" directive in config file to tell logrotate which user/group should be used for rotation. # ls logtest.log
対策はエラーメッセージに書かれてあるとおりにsuを使えば良い
/var/log/logtest/logtest.log { copytruncate size 1 rotate 5 su john john }
とすると
# logrotate /etc/logrotate.d/logtest [root@localhost logtest]# ls -l total 4 -rw-r--r-- 1 john john 0 Jan 8 22:20 logtest.log -rw-r--r-- 1 john john 4 Jan 8 22:20 logtest.log.1
とロテートしてくれる。
logrotate.confにsuが設定できるできるようになったv3.8.0からしく、CentOS7は該当する。