Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get 'puma' to start, automatically, when I run `rails server` (like Thin does)

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.

like image 447
Matt Scilipoti Avatar asked Nov 13 '12 17:11

Matt Scilipoti


People also ask

How does PUMA work in Rails?

Puma allows you to configure your thread pool with a min and max setting, controlling the number of threads each Puma instance uses. The min threads setting allows your application to spin down resources when not under load.

How do I check my Puma server status?

Control/Status Server Check out https://github.com/puma/puma/blob/master/lib/puma/app/status.rb to see what the app has available.

Which is the command to start the server in Rails?

Go to your browser and open http://localhost:3000, you will see a basic Rails app running. You can also use the alias "s" to start the server: bin/rails s . The server can be run on a different port using the -p option.

How does PUMA work?

Puma is a threaded Ruby HTTP application server processing requests across a TCP and/or UNIX socket. Puma processes (there can be one or many) accept connections from the socket via a thread (in the Reactor class).


1 Answers

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)

like image 94
Simon Woker Avatar answered Sep 29 '22 08:09

Simon Woker