LoginSignup
8
1

More than 3 years have passed since last update.

Rails6 のちょい足しな新機能を試す 117(puma pidfile編)

Posted at

はじめに

Rails 6 に追加された新機能を試す第117段。 今回は、puma pidfile 編です。
Rails 6 では、 rails new したときに config/puma.rbpidfile の設定が追加されるようになりました。
pumactl で制御できるようにするためのようです。

なお、この修正は、Rails 5.2.4 にも反映されています。

Ruby 2.6.5, Rails 6.0.2.1, Rails 5.2.3, Rails 5.2.4.1 で確認しました。 (Rails 6.0.0 でこの修正が入っています。)

$ rails --version
Rails 6.0.2.1

Rails プロジェクトを作る

Rails プロジェクトを新たに作成します。

$ rails new rails_sandbox
$ cd rails_sandbox

config/puma.rb を確認する

config/puma.rb を確認すると pidfile の設定があることがわかります。

config/puma.rb
...
# Specifies the `pidfile` that Puma will use.
pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }

試してみる

普通に、 rails s でサーバーを起動します。

$ bin/rails s

別のコンソールから、プロジェクトのディレクトリに移動して pumactl status を実行してみます。

$ pumactl status
Puma is started

リスタートしてみます。

$ pumactl restart
Command restart sent success

rails s を実行したコンソールで puma (rails) が再起動されました。

=> Booting Puma
=> Rails 6.0.2.1 application starting in development
=> Run `rails server --help` for more startup options
Puma starting in single mode...
* Version 4.3.1 (ruby 2.6.5-p114), codename: Mysterious Traveller
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://127.0.0.1:3000
Use Ctrl-C to stop
* Restarting... # <=== ココ
=> Booting Puma
=> Rails 6.0.2.1 application starting in development
=> Run `rails server --help` for more startup options
Puma starting in single mode...
* Version 4.3.1 (ruby 2.6.5-p114), codename: Mysterious Traveller
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://127.0.0.1:3000
Use Ctrl-C to stop

Rails 5 では

Rails 5.2.4.1 では、Rails 6 と同じ動作になりますが、 Rails 5.2.3 では、 pumactl status を実行してもエラーメッセージが表示されます。

$ pumactl status
Neither pid nor control url available

参考情報

8
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
8
1