LoginSignup
6
2

More than 1 year has passed since last update.

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

Last updated at Posted at 2023-01-26

はじめに

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 が出力したログを吐くことが出来ます。

Procfile.options
# 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 を定義できるだけです。

restart_mode を term-start から usr2 に変更する場合
# 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

6
2
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
6
2