LoginSignup
4
3

More than 5 years have passed since last update.

rackとpuma

Last updated at Posted at 2017-07-13

rackとpumaに関して

Rack仕様で実装したアプリはRack対応のサーバで運用することができる。

使い方

$ bundle install --path=./vendor/bundler
$ bundle exec ruby 01_rack_app.rb
$ bundle exec rackup 02_config.ru
$ bundle exec rackup 02_config.ru -s WEBrick -o 0.0.0.0 -p 8000
$ bundle exec rackup 02_config.ru -s puma -o 0.0.0.0 -p 8000
$ bundle exec pumactl -F 03_config.rb start                                                   
Puma starting in single mode...
* Version 3.9.1 (ruby 2.2.4-p230), codename: Private Caller
* Min threads: 0, max threads: 16
* Environment: development
* Daemonizing...
$ ls /tmp/ | grep puma
puma-status-1499925598625-15294
puma_sample.pid
puma_sample.state
$ bundle exec pumactl -F 03_config.rb status                                                  
Puma is started
$ bundle exec pumactl -F 03_config.rb stop                                                    
Command stop sent success
$ ls /tmp/ | grep puma
puma_sample.state

Gemfile

source 'https://rubygems.org'

gem 'puma'
gem 'rack'

01_rack_app.rb

require 'rack'
require 'rack/handler/puma'
app = Proc.new do |env|
  ['200', {'Content-Type' => 'text/html'}, ['hello rack']]
end
#Rack::Handler::WEBrick.run app, Port:8000
Rack::Handler::Puma.run app, Port:8000

02_config.ru

app = Proc.new do |env|
  ['200', {'Content-Type' => 'text/html'}, ['hello rackup']]
end

run app

03_config.rb

require "puma"

app do |env|
  [200, { 'Content-Type' => 'text/plain' }, ["hello pumactl"]]
end

daemonize true
port 8000
pidfile "/tmp/puma_sample.pid"
state_path "/tmp/puma_sample.state"

activate_control_app('auto', auth_token: "12345")
4
3
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
4
3