How define his own server with Rails 3 - ruby-on-rails

I want use always thin when I start my rails server in development mode.
By default it webrick to use. So I add thin in my Gemfile
gem 'thin', :group => 'development'
Now If I want use it to launch my server in development mode I mandatory define it.
bundle exec rails s thin
If I don't define it, it's always use webrick. So How define using thin by default ?

Instead of rails s just type :
>> thin start -p 3000
Where 3000 is the number of your port.
You can also specify an enviornment :
>> thin start -e production

Assuming you are using bundler 1.0.x and your gems is vendorized:
bundle exec vendor/ruby/1.9.1/bin/thin start

Related

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?
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'
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.
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.

`rails server puma` vs. `puma`

Some guides (example) recommend this to start one's webserver
bundle exec rails server puma
But I've always just started the server with puma directly
bundle exec puma
Does something special happening when firing up puma (or any other server) via rails server?
When you use rails s <server>, the server is launched from the Rails command and is aware of the Rails environment.
This makes possible, for example, to use any of the features and flags offered by the rails server command.
rails s --help
Usage: rails server [mongrel, thin, etc] [options]
-p, --port=port Runs Rails on the specified port.
Default: 3000
-b, --binding=ip Binds Rails to the specified ip.
Default: 0.0.0.0
-c, --config=file Use custom rackup configuration file
-d, --daemon Make server run as a Daemon.
-u, --debugger Enable ruby-debugging for the server.
-e, --environment=name Specifies the environment to run this server under (test/development/production).
Default: development
-P, --pid=pid Specifies the PID file.
Default: tmp/pids/server.pid
-h, --help Show this help message.
For instance, you can attach a debugger to the session passing --debugger or daemonize the server.
The second advantage is that you can version the Puma instance, since you will have to list the gem in the Gemfile. This is already true if you start it with bundle exec like you are doing.
Conversely, when you simply run $ puma (or $ bundle exec puma) you're not passing through the Rails system. Puma will try to find a rack bootstrap file and will use it (it works because Rails provides a config.ru script in the application root.
Generally speaking, there is no real difference if you don't need to pass specific options to the server. I like puma and I tend to use it in some projects even when on production we use Unicorn, thus running $ puma as a standalone command is handy because I don't need to add it to the Gemfile.
However, I would probably go with $ rails s puma if my entire stack uses Puma. This is also the command suggested in the documentation.

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

How to enable thin server for faye in production in rails3 for private_pub gem with apache2

I am using private_pub gem for live chat in my rails 3.2 application and it is working perfectly on development mode but I am stuck at how to do it on production.
I am using apache2 in production. When I ran this command on server
RAILS_ENV=production bundle exec rackup private_pub.ru -s thin -E production
It starts the thin server but my app keeps on waiting for response from
http://www.example.com:9292/faye.js
It doesn't do anything. I am unable to connect with faye in prodution
Thanks for help in advance
Thin and Apache need to be set up running on different ports.
The default settings for both should work, but you should double
check. Ensure apache is running under port 80 and thin is using port
9292. These numbers should be visible when the servers start up.
In the end you should be able to access faye.js at
http://yoursite.com:9292/faye.js and your site at http://yoursite.com/
Source: https://stackoverflow.com/a/6667347/539075

How to Change the environment of a rails application?

Once I start coding a rails app, I am by default in development mode.
What should I do to change my rails environment to test or production mode ?
can I work in multiple environments simultaneously ?
to run application on production mode type in console
ruby script/server -e production
TO RUN SAME APPLICATION ON DIFFERENT ENVIORMENT you have to use different ports
like
ruby script/server -e production -p 3001
AND
ruby script/server -p 3002
It depends how you are running the application. When you run your tests then they automatically use the test environment. If you are using script/server (e,g, using WEBrick, Mongrel etc.) then you can pass the name of the environment to use on the command line e.g. script/server -e production.
If you are using Phusion Passenger then the environment can be specified using the RailsEnv configuration directive
If you are using the Rails console then specify the environment name directly: script/console production
You can create your own environments too. This Railscast has the details
script/server -e production for production mode
more in script/server --help

Resources