0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

NGINX Unitのログをlogrotateでローテートしたことを通知したい

Posted at

nginxでは kill -USR1 でアクセスログ・エラーログが新しいものに切り替える「ログローテーション」を
nginxに通知して正しくログを書き込む機能があります。

kill -USR1 `cat master.nginx.pid`

Log Rotation | NGINX
https://www.nginx.com/resources/wiki/start/topics/examples/logrotation/

では NGINX Unitの場合はどうでしょうか?
NGINX Unitのドキュメントを探しても「ログローテーション」についての記載がありませんでした。

NGINX Unitでも同様に kill -USR1 でローテートが通知できる

……ですが、 お察しの通り NGINX Unitの場合でも同様に kill -USR1 を実行することで、ログがローテートされたことを通知できます。

kill -USR1 `cat /var/run/unit.pid`

logrotateの設定で postrotate にこのコマンドを仕込むと、logrotateでログローテーションの通知がされます。

logrotate.conf
/var/log/nginx/unit.log {
    missingok
    hourly
    rotate 24
    dateext
    dateformat -%Y%m%d%H
    postrotate
        [ -s /var/run/unit.pid ] && kill -USR1 `cat /var/run/unit.pid`
    endscript
}

また、 NGINX Unitに USR1 シグナルが送信されると、NGINX Unitのログに次の出力がされるため、ローテートが通知されたことがわかります😀

unit.log
2018/11/02 16:58:02 [notice] 1#1 signal 10 (SIGUSR1) recevied, log files rotation
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?