4 Apache のログをたくさん残す

ログファイルは現在 /opt/local/var/log/apache2/error_log, /opt/local/var/log/apache2/access_log にある。

設定ファイルは、 /opt/local/etc/logrotate.conf である。 ここに rotate の回数を書くのだった。

これは 「WWW(Apache)のログとその解析」, 「Apache のログのローテート」 で設定した気がする。

sudo port unload logrotate
sudo port load logrotate

あ、logrotate 壊れている??

以前用意した設定ファイル /opt/local/etc/logrotate.conf, /opt/local/etc/logrotate.d/httpd は残っているね。

あ、途中で Apache を macOS に付属していたものから、 MacPorts で導入するものに変えたので、設定を変える必要があるんだ。 お粗末。

例えばログファイルを格納するディレクトリィは、 /var/log/apache2/ でなくて、 /opt/local/var/log/apache2/ にしたんだった。 process ID を記録しておくファイルのパスも変わっている。 そこで次のように直す。
/opt/local/etc/logrotate.d/httpd
/opt/local/var/log/apache2/*log {
    missingok
    notifempty
    sharedscripts
    postrotate
        /bin/kill -HUP `cat /opt/local/var/run/apache2/httpd.pid 2>/dev/null` 2> /dev/null || true
    endscript
}

/Library/LaunchDaemons/org.macports.logrotate.plist もなくなっている。 なぜなくなったの?

sudo cp -p /opt/local/share/logrotate/org.macports.logrotate.plist.example /Library/LaunchDaemons/org.macports.logrotate.plist
sudo vi /Library/LaunchDaemons/org.macports.logrotate.plist

登録する
sudo port load logrotate

今度は通った。

設定を変えたとき
sudo port unload logrotate
sudo port load logrotate

やってみてもエラーにはならない。

いわゆるドライ・ラン (設定のチェック)
logrotate -d -v /opt/local/etc/logrotate.conf

ローテーションの強制実行
sudo logrotate -f -v /opt/local/etc/logrotate.conf

やれやれ。

問題なく動いているソフトであっても、 頭からすっぽ抜けている状態で、 設定を少しでも変えるのは大変だ。

今回は、 /opt/local/etc/logrotate.conf だけでなく、 /opt/local/etc/logrotate.d/httpd にも情報が入っていたのが間違いの元でした。

月に一度はログのチェックをして、ちゃんと動いていることを確認するべし、と。 自動化するべきだろうね。



桂田 祐史