Rails running in development thinks it's in production mode - ruby-on-rails

BIt of a weird one this.
rails s
=> Booting Thin
=> Rails 3.2.13 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Thin web server (v1.6.2 codename Doc Brown)
Maximum connections set to 1024
Listening on 0.0.0.0:3000, CTRL+C to stop
But when I call
puts Rails.env
in a controller, it says
production
In rails console it correctly says development
Rails.env
=> "development"
Any ideas.
I want to run in dev locally and production on my server. Particularly important as I'm testing functionality where it costs me money to run certain api calls and I have them faked if Rails.env.prodcution? is false.
Running rails 3.2.13

Related

WEBRick stays booting for an indefinite amount of time, no error message

I'm trying to execute rails s -e production on an installation of OpenCongress inside a Vagrant box (Ubuntu precise64) that already works in development mode. When I try to run the server in production I get this:
=> Booting WEBrick
=> Rails 3.0.20 application starting in production on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
** [Raven] Raven 0.7.1 ready to catch errors
Where it stays for an indefinite amount of time. I can't access the app at localhost:3000, and given the fact that there's no error message, I can't diagnose what is going on.
The app runs on a Postgres DB, the production table specified in database.yml exists in the DB. I sincerely don't know what's going on.
EDIT: Commenting out the gems particular to production in the Gemfile doesn't have any effect whatsoever. Also, trying to run the app with Thin by executing bundle exec thin -e production stays on the Raven message too, and after this the process is not killable (sending the Ctrl-Csignal shows an "Stopping..." message that does not go away).
You are using this gem. I would read up on the different configurations to get the behavior you want.

Specify which server a rails project will use

Just wondering if this can be done. You can specify you want a new rails project to use the postgresql server ike this:
rails new my-new-rails-project -d postgresql
and that takes care of the database yaml file.
Can an option be passed in here to specify puma as the development and production server so the relevant puma.rb configuration file is created?
Something like this:
rails new my-new-rails-project -d postgresql -s puma
By default Rails are using Webrick, but you can include different gem using Gemfile.
For example, you can use Thin (or puma, unicorn, whatever...) gem to your Gemfile and install it with bundler.
gem 'thin', group :development
When you start local server, rails will boot with custom webserver
rails server
=> Booting Thin
=> Rails 4.0.1 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Thin web server (v1.6.1 codename Death Proof)
Maximum connections set to 1024
Listening on 0.0.0.0:3000, CTRL+C to stop
There is no option for server configuration in Rails. You can check using below command.
rails new --help

Thin webserver shuts down immediately after start (rails)

I am deploying a Rails application into production using Thin. Right after starting rails, Thin shuts down, the only ouput is 'Exiting':
$ bundle exec rails s -e production
=> Booting Thin
=> Rails 4.0.0 application starting in production on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
>> Thin web server (v1.5.1 codename Straight Razor)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:3000, CTRL+C to stop
Exiting
The same configuration / setup works in development. The same configuration works for production using WEBrick:
$ bundle exec rails s -e production
=> Booting WEBrick
=> Rails 4.0.0 application starting in production on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2013-07-19 17:59:07] INFO WEBrick 1.3.1
[2013-07-19 17:59:07] INFO ruby 2.0.0 (2013-06-27) [x86_64-linux]
[2013-07-19 17:59:07] INFO WEBrick::HTTPServer#start: pid=5231 port=3000
Surely it should be possible to receive some output on why it is shutting down from a web server rated for production use. However, I have not found out how.
Any ideas?
Turns out starting Thin in production mode made Rails eager load a module also using EventMachine, thus keeping the Thin code from being blocked after starting and immediately shutting down instead.

What is the best way to start thin in a rails application?

You can start the thin server by one of the following ways:
thin start
rails s (if you have thin in the Gemfile)
Is there any difference on performance/compatibility between these two ways, or the rails s actually only calls thin start?
It seems that they are both functionally equivalent. However, adding thin to your Gemfile will only start thin automatically if you are using rails >= 3.2. Otherwise, you will have to start thin by passing rails server thin at the command line.
$ thin start
>> Using rack adapter
>> Thin web server (v1.5.1 codename Straight Razor)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:3000, CTRL+C to stop
Notice the difference between thin start and rails server if rails >= 3.2 or rails server thin
$ rails server thin
=> Booting Thin
=> Rails 3.2.13 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
>> Thin web server (v1.5.1 codename Straight Razor)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:3000, CTRL+C to stop
It prints out more info about the rails environment. It seems that sticking to the rails server convention would be the wise thing to do. Although I haven't seen anything different between the two ways of starting thin, I would stick with the conventional rails server

Unable to run ruby on rails app?

I am unable to run ruby on rails application. I setup the database and loaded database schema. When I run:
ruby script/server -e production
It says:
=> Booting Mongrel
=> Rails 2.3.2 application starting on http://0.0.0.0:3000
=> Call with -d to detach
=> Crtl-C to shutdown server
and it just stays there. If I go to the directory where the app is installed, it just lists the directory of files and doesn't run the app. Any suggestions?
Thanks
Have you opened http://localhost:3000/ in a browser?
The '=> Booting Mongrel ...' stuff means the server is running, you just need to navigate a browser to it.
You are starting your server in production mode.
Use the development mode fpr debugging, it will give you a better log output.
Run ruby script/server -e development

Resources