RubygodforemanlogrotateProcodile

Procodile の process に HUP/USR1 等のシグナルを送信してもログファイルは reopen しません

はじめに

Ruby には ForemanGod 等 process を管理してくれるツールがあり Procodile もその 1 つです。 今回 Procodile が出力する ログファイル が logrotate 時 reopen されていなかったため動きについて調査したので簡単にまとめました。

先に結論

Procodile が開いた logfile を reopen する方法は現時点存在しません。 Procodile (supervisor を含め) そのものを stop, start する必要があります。

$ bundle exec procodile stop --procfile path/to/Procfile --stop-supervisor
Stopped xxxxxx.1 (PID: xxxx)
Supervisor will be stopped when processes are stopped.
$ bundle exec procodile start --procfile path/to/Procfile

Procodile とは

Procodile は Foreman に少し似た library です。

Procodile は background で動作するように設計されており(foreground も OK)。 process を監視する supervisor を持っており、対象の process が kill された場合はそれらを respawn します。

Procodile を start すると、 Procodile の supervisor が起動し、 Procfile に記載された process を起動・監視してくれます。

Procodile の ログファイルについて

ProcodileProcfile.options に指定した log_path の path に、起動した process が出力したログを吐くことが出来ます。

# The absolute path to the application (optional but useful when working
# with symlinks)
root: /absolute/path/to/app

# The directory that all PIDs will be stored in (default is 'pids')
pid_root: tmp/procodile-pids

# The path to the log file where the procodile log will be stored. By default
# this will be `procodile.log` in the root of your application.
log_path: log/procodile.log

上記のような設定をしていた場合 /absolute/path/to/app/log/procodile.log にログが出力されます。

Procodile の process 管理について

Procodile の wiki には、 process を restart する方法について記載されています。 こちらの記述は、 Procodile が起動した process restart に関するもので、 Procodile の process restart についての記述ではありません。

また、 Procfile.options にも restart_mode を記載することが出来ますが Procodile が起動した process restart に送信する signal を定義できるだけです。

# Per-process configuration options
processes:
  web:
    # The mode that should be used when restart this process (default
    # is term-start)
    restart_mode: usr2

Procodile が開いた logfile を reopen するには、Procodile (の supervisor を含め) stop, start する必要があります。

$ bundle exec procodile stop --procfile path/to/Procfile --stop-supervisor
Stopped xxxxxx.1 (PID: xxxx)
Supervisor will be stopped when processes are stopped.
$ bundle exec procodile start --procfile path/to/Procfile

logrotate したいときは上記を考慮し logrotate の設定ファイルを記述する必要があります。

References