31

Normally, when you run rails server it starts Webrick. If you install the 'thin' gem, then 'thin' starts instead. I would like to do the same thing with the 'puma' server.

I see that the start command within railties (lib/rails/commands) calls super, but I can't find what the various options for 'super' are. I have also reviewed many references to Rails within 'thin'.

I found a Changelog entry entitled "Added Thin support to script/server. #488 [Bob Klosinski]" from Oct. of 2008, but that code area has changed significantly since that commit (a93ea88c0623b4f65af98c0eb55924c335bb3ac1).

If someone could direct me to the right section of code, that would be very helpful.

Arslan Ali
  • 17,418
  • 8
  • 58
  • 76
Matt Scilipoti
  • 1,091
  • 2
  • 11
  • 15

4 Answers4

59

After some digging, I've found this answer: https://stackoverflow.com/a/14911994/604526

To make Puma the default, paste this code into script/rails above require 'rails/commands':

require 'rack/handler'
Rack::Handler::WEBrick = Rack::Handler.get(:puma)

Puma is the default server now if you use rails s

rails s
=> Booting Puma
=> Rails 3.2.12 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Connecting to database specified by database.yml
Puma 1.6.3 starting...
* Min threads: 0, max threads: 16
* Environment: development
* Listening on tcp://0.0.0.0:3000

Rails 4

With Rails 4 you simply have to add the puma-gem to the Gemfile. (Tested with Rails 4.0.2 and Puma 2.6.0)

Joshua Pinter
  • 45,245
  • 23
  • 243
  • 245
Simon Woker
  • 4,994
  • 1
  • 27
  • 41
19

At least in Rails 4, you just need to add the following to your Gemfile

gem 'puma'

then run 'bundle', and then when you run 'rails server' and Puma will be used.

Ryan
  • 2,073
  • 1
  • 19
  • 33
  • 1
    This works. Now if only I could figure out how to make it automatically load config/puma.rb when running `rails server`... – odigity Aug 01 '14 at 18:37
  • 2
    echo 'alias start_puma="bundle exec puma -p 3000 -S ~/puma -C config/puma.rb"' >> ~/.bash_profile && source ~/.bash_profile THEN USE start_puma – blnc Aug 20 '14 at 00:20
  • Just tested on Rails 4.2 and running `bundle exec rails s` will launch puma and load the configuration settings from `config/puma.rb` all automatically. – Joshua Pinter Aug 20 '19 at 02:16
11

This works for me. Ruby 2.0.0 Rails 3.2.13 Puma 1.6.3

rails s puma
user2110836
  • 164
  • 1
  • 4
  • This bit me because ARGV[0] is not empty. reload_libs loads lib/tasks/* and I had the assumption that if ARGV[0] was set, that I wanted to execute it as a command. – pedz Apr 22 '17 at 14:52
2

Puma documentation suggests that you prepend #\ -s puma to your config.ru.

RocketR
  • 3,626
  • 2
  • 25
  • 38
  • Thanks. Tried it. No luck. Still get "Booting WEBrick" or "Booting Thin". I wonder if this is a Rails bug? – Matt Scilipoti Jan 07 '13 at 23:01
  • @MattScilipoti It must be something with Rack. But I don't think it's a bug, rather you are just missing some settings. – RocketR Jan 08 '13 at 22:59