Ben
Ben

Reputation: 5361

Prevent puma from running in locally (ruby on rails)

I'm recently started to use Puma for my production server with nginx, however, when I now try to run my app locally, it tries to run Puma with all my production settings and fails. How can I prevent Puma from running locally?

AFAIK all I've done was added the puma gem to my gemfile, so I don't know how it's accessing my server config (I'm just not too knowledgeable in this area). I have it in my production group:

group :production do
  gem 'pg'
  gem 'rails_12factor'
  gem 'puma'
end

Error:

→ rails s
=> Booting Puma
=> Rails 4.2.6 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[8917] Puma starting in cluster mode...
[8917] * Version 3.4.0 (ruby 2.0.0-p645), codename: Owl Bowl Brawl
[8917] * Min threads: 1, max threads: 6
[8917] * Environment: development
[8917] * Process workers: 1
[8917] * Phased restart available
[8917] * Listening on tcp://localhost:3000
[8917] Use Ctrl-C to stop
/rbenv/versions/2.0.0-p645/lib/ruby/gems/2.0.0/gems/puma-3.4.0/lib/puma/runner.rb:103:in `reopen': No such file or directory - /Users/me/mll/shared/log/puma.stdout.log (Errno::ENOENT)

Additionally, though less important to me right now, is it in my benefit to run Puma locally? If so, any tips/resources on how I can do that?

Upvotes: 4

Views: 2756

Answers (3)

elc
elc

Reputation: 1952

Rails 3 project (it keeps hanging around longer than expected...) I changed from unicorn to puma in the production group of my gemfile.

group :production do
  gem 'puma'
end

Then then when trying to run tests, or a dev server (which should have been thin) I got:

C:\Rails Projects\Rep>rails s
Could not find gem 'puma x86-mingw32' in any of the gem sources listed in your Gemfile or available on this machine.
Run `bundle install` to install missing gems.

After poking around a bit (including finding this question) I gave up and decided to go ahead and use puma in dev. I ran bundle install and tried running server and voila, thin was working again.

Then I realized I still only had it in the production group--I looked back at the bundle install and nothing was installed, puma still isn't installed. But now that bundle install has been run since the edit to the gemfile, everything works again.

C:\Rails Projects\Rep>rails s
=> Booting Thin
=> Rails 3.2.22.2 application starting in development on http://0.0.0.0:3000

So I guess the 'missing gem' error I wasn't because it was trying to actually run puma but rather some kind of bundler generated error due to unattempted gemfile? Just putting this out in case it speed things up for anyone in similar circumstances who ends up here.

Upvotes: 1

B Liu
B Liu

Reputation: 123

Having the exact same issue with Ben. I try to use web brick on local while developing and testing, and puma in production.

Gem file is perfectly define as puma only sits in production group. 'bin/rails' and 'config/application' are checked, same as @Răzvan Ciocănel suggested. Still boot with 'puma' on local.

At last, have a look into the 'bundle install' gem list, 'puma' is installed along with other 'production' gem. Run 'bundle install --without production' and now local will boot with web brick as ROR default.

I guess as long as puma is bundle installed, it will be loaded on local unless you config something to force it off. So the solution might be to remove the gem in the bundle list in development and test.

Upvotes: 2

Răzvan Ciocănel
Răzvan Ciocănel

Reputation: 446

You need to put puma in your production group. Like this:

group :production do
   gem 'puma'
end

That way puma will only be used on production and not development.

Update

Make sure that your bin/rails file looks like this:

#!/usr/bin/env ruby
APP_PATH = File.expand_path('../../config/application', __FILE__)
require_relative '../config/boot'
require 'rails/commands'

Upvotes: 3

Related Questions