'rails server' starts thin twice, shuts both down. Cucumber still works - ruby-on-rails

My rails application fails to start up in development mode. It appears to work in both production and test mode. Here is what I get when I run 'rails server':
Thin web server (v1.5.1 codename Straight Razor)
Maximum connections set to 1024
Listening on 0.0.0.0:51960, CTRL+C to stop
Booting Thin
Rails 3.2.11 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
Exiting
One clue I've found is that thin seems to start before every call to rails. For example, here is what happens when I call rails console:
Thin web server (v1.5.1 codename Straight Razor)
Maximum connections set to 1024
Listening on 0.0.0.0:52262, CTRL+C to stop
Loading development environment (Rails 3.2.11)
This error has shown up on two different computers. The first (macbook) I simply cloned the github repository into a new folder and started it up from there, fixing things (how? Not sure). The second computer (iMac) did not respond to this.
I'm using ruby 1.9.3, rails 3.2, and thin 1.5.1.
More mysteriously, removing thin from my gemfile does nothing to fix the error. Rails still uses thin to start. I cannot find a direct reference to thin in the rest of my project.
Please excuse my relative ignorance of the internals of both rails and web servers. Any ideas on what might be causing this?
PS I am aware of this SO question and the solution there did not work for me.

I found out why. I was running the gem 'fake_braintree' in both development and test. It is meant to be run only in test. When it is run, it starts up a thin server which conflicts with the thin server I am wanting to run.

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.

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

how to use thin-specific cli options in rails server

I'm using thin and launch it through rails server thin. (If I launch thin separately I have 2 logs (rails and thin log) and no stacktraces in some cases.) If I try to launch it with the option -S /var/tmp/thin/thin.sock rails server complains that it's not a valid option.
try switching to thin command:
thin -S=/var/tmp/thin/thin.sock

What are the differences between using `rails server` and `rackup`?

The only difference I've noted is that rails server starts the server on port 3000, while rackup starts the server on port 9292.
Are there any other differences?
Are there use cases for one instead of the other?
rails server is the command for starting your server (usually WEBrick) and is in rails.
rackup is a command that comes with the rack middle and uses the settings in your config.ru and starts a server based off of those. This is a standard (it will work for other frameworks and rack-based applications) and is usually used in production servers.
One difference of note is that if you start a server with rails s then you will see the output in the terminal.
In my experience, in production, rackup is used by phusion passenger so you wouldn't want rails s in that situation.
As an aside, the port can be changed with both rails server and rackup using the -p flag.

Webrick Fails to Run as Daemon, no Error Message

Running Ubuntu Server 10.04 with Rails 2.3.4 and Webrick 1.3.1; our rails app runs fine when called via script/server -e production, but trying to test it as a daemon by calling it with the -d flag produces the following output:
=> Booting WEBrick
=> Rails 2.3.4 application starting on http://0.0.0.0:3000
Nothing is produced in the logs, and other Rails applications will run detached without issue.
I assume You are running the Webrick in port 3000
>>$ sudo netstat -anp | grep 3000
tcp 0 0 0.0.0.0:3000 0.0.0.0:* LISTEN 8822/ruby
>>$ sudo kill -9 8822
I don't mean to contradict your choosing Webrick as a production server and maybe there is something I'm missing about why you are choosing Webrick, but have you considered other alternatives? I'd wager you already know all of this, but Webrick is the provided ruby server, and it is also the slowest ruby server choice.
Some of the most popular production server choices are:
Passenger
Thin
Mongrel
Unicorn
Glassfish
Passenger is likely the most popular choice for production now due to its easy configuration, speed, and features.
If there is a specific use case for Webrick that makes it better than any of the other server choices, I'd love to know.
You can add patch to enable error log here: https://github.com/rails/rails/blob/3-2-stable/activesupport/lib/active_support/core_ext/process/daemon.rb#L16
To
unless noclose
STDIN.reopen "/dev/null" # Free file descriptors and
STDOUT.reopen "/dev/null", "a" # point them somewhere sensible.
STDERR.reopen '/tmp/rails_daemon_err.log', 'a'
end
Now when you start rails server with -d, the error log will append to /tmp/rails_daemon.log.

Resources