Sinatraアプリのログをローテーションする(2)
logrotate の設定をして1日待ってみたけど、ログファイルがローテーションされていない。仕方がないので、-f オプションを使って強制的に行ってみたら、次のようなメッセージが出た。
takatoh@nightschool $ sudo logrotate -f -v sombrero
reading config file sombrero
Handling 1 logs
rotating pattern: /home/sombrero/sombrero/unicorn.log forced from command line (60 rotations)
empty log files are rotated, old logs are removed
considering log /home/sombrero/sombrero/unicorn.log
error: skipping "/home/sombrero/sombrero/unicorn.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.
なんだかよくわからないけど、親ディレクトリのパーミッションがセキュアじゃないといってる?設定ファイルに su ディレクティブをセットしろともいってる。
ちょっと調べてみると、次のページが見つかった。
cf. logrotate(8) の create と su ディレクティブについて - はてダ
読んでもよくわからないんだけど、とにかく次の1行を設定ファイルに追加した。
su root root
これでどうだ。
takatoh@nightschool $ sudo logrotate -f -v sombrero
reading config file sombrero
Handling 1 logs
rotating pattern: /home/sombrero/sombrero/unicorn.log forced from command line (60 rotations)
empty log files are rotated, old logs are removed
considering log /home/sombrero/sombrero/unicorn.log
log needs rotating
rotating log /home/sombrero/sombrero/unicorn.log, log->rotateCount is 60
dateext suffix '-20150409'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
glob finding logs to compress failed
glob finding old rotated logs failed
renaming /home/sombrero/sombrero/unicorn.log to /home/sombrero/sombrero/unicorn.log-20150409
running postrotate script
今度はうまくいった?
takatoh@nightschool $ ls /home/sombrero/sombrero
CHANGES bin lib unicorn.conf views
Gemfile boot.rb public unicorn.log
Gemfile.lock config.yaml rakefile unicorn.log-20150409
app.rb config.yaml.sample start.cmd unicorn.pid
app.ru db tmp version.rb
おお、ちゃんとローテートされたファイル(unicorn.log-20150409)ができて、新しいログファイル(unicorn.log)もできている。
これでOKかな。
