Rails console vs server differences on production server
Asked Answered
S

2

7

Having deployed a very basic Rails 3.2.3 trial site to a "production" server (not really in production, thankfully!) with RVM Ruby 1.9.3-p194, I find the following to be true, of the commands listed here:

╔══════════════════════════════════════╤═══╗
║ command issued                       │OK?║
╟──────────────────────────────────────┼───╢
║ bundle exec rails console            │ N ║
║ bundle exec rails console production │ Y ║
║ bundle exec rails server             │ Y ║
║ bundle exec rails server production  │ N ║
╚══════════════════════════════════════╧═══╝

My first question: is this expected? (I would have thought the pattern in the right column should be N-Y-N-Y.)

More info: bundle exec rails console fails for the understandable reason that the sqlite3 gem is not installed on the server. However, bundle exec rails server production fails with a much less understandable trace:

$ bundle exec rails server production
Exiting
/home/spkspike/www/spike.sampablokuper.com/releases/20120530134819/vendor/ruby/1.9.1/gems/rack-1.4.1/lib/rack/handler.rb:63:in `require': cannot load such file -- rack/handler/production (LoadError)
from /home/spkspike/www/spike.sampablokuper.com/releases/20120530134819/vendor/ruby/1.9.1/gems/rack-1.4.1/lib/rack/handler.rb:63:in `try_require'
from /home/spkspike/www/spike.sampablokuper.com/releases/20120530134819/vendor/ruby/1.9.1/gems/rack-1.4.1/lib/rack/handler.rb:16:in `get'
from /home/spkspike/www/spike.sampablokuper.com/releases/20120530134819/vendor/ruby/1.9.1/gems/rack-1.4.1/lib/rack/server.rb:269:in `server'
from /home/spkspike/www/spike.sampablokuper.com/releases/20120530134819/vendor/ruby/1.9.1/gems/railties-3.2.3/lib/rails/commands/server.rb:59:in `start'
from /home/spkspike/www/spike.sampablokuper.com/releases/20120530134819/vendor/ruby/1.9.1/gems/railties-3.2.3/lib/rails/commands.rb:55:in `block in <top (required)>'
from /home/spkspike/www/spike.sampablokuper.com/releases/20120530134819/vendor/ruby/1.9.1/gems/railties-3.2.3/lib/rails/commands.rb:50:in `tap'
from /home/spkspike/www/spike.sampablokuper.com/releases/20120530134819/vendor/ruby/1.9.1/gems/railties-3.2.3/lib/rails/commands.rb:50:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'

My second question: how best to troubleshoot this error?

Sharkey answered 30/5, 2012 at 13:56 Comment(0)
F
18

Don't you want to be starting the server in production mode using the production environment?

rails server -e production

The syntax difference between rails console environment and rails server -e environment is a bit of a PITA

Fecula answered 30/5, 2012 at 14:22 Comment(1)
For thin server this is correct....Also for Webrick you will need to run RAILS_ENV=production rails sTurman
J
3

In case of console production specifies the environment and in case of server it specifies something else (probably which server to use webrick/...).

So if you want to specify the enviroment do:

ENV=production rails server
Jacinda answered 30/5, 2012 at 14:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.