LoginSignup
18
17

More than 5 years have passed since last update.

pumaでコントロールサーバを使うときはトークンをつけた方が良いよ

Posted at

Rubyのウェブアプリケーションサーバにpumaというのがあります。

で、そのpumaにはコントロールサーバという仕組みがあります。その仕組みを使うと、指定したURLにHTTPリクエストを送るだけでpumaの再起動や停止が行えます。使い方は下記の通り。

$ puma -S tmp/puma.state --control unix://tmp/pumactl.sock & # 起動
$ pumactl -S tmp/puma.state restart # 再起動
$ pumactl -S tmp/puma.state stop # 停止

で、結論から言うと、まあタイトル通りなのですが、コントロールサーバを使うときは、上記だけでは少しおっかなく、トークン(--control-tokenオプション)も使った方が良いよ、ということです。何故か。下記のケースで少し面倒なことになります。

$ puma -S tmp/puma.state --control unix://tmp/pumactl.sock &
$ grep token tmp/puma.state
    :control_auth_token: 87475081db4cf2d91e949f846fbcf69
$ puma -S tmp/puma.state --control unix://tmp/pumactl.sock & # ミスでもう一度起動してしまった
/home/takkkun/example/vendor/bundle/ruby/1.9.1/gems/puma-1.6.3/lib/puma/server.rb:117:in `initialize': Address already in use - bind(2) (Errno::EADDRINUSE)
...
$ grep token tmp/puma.state
    :control_auth_token: d327cd9e14391fcee9a9ddc9f749af1
$ pumactl -S tmp/puma.state stop
Unauthorized access to server (wrong auth token)

とまあ起動が失敗したにも関わらず、pumaサーバの状態を保持する.stateファイル(中身はただのYAML)に記載されたトークンの値が上書きされてしまい、pumactlのときにトークンが違うよと言われてしまいます。

--control-tokenオプションでトークンを指定しない場合、トークンはランダムで生成されたものが使われます。ランダムになってしまうのがイヤなので、トークンは自身で設定した方が良いよ、というお話でした。

18
17
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
18
17