I am using following command for start the production server.
nohup ruby script/server webrick -e production &
My Rails applications start with port number in URL, like this one:
http://myapp.com:3000/
How to remove port no from the app URL? I think I need to install something like Passenger, If so anyone suggest me a good tutorial.
PS: My rails App hosted in http://dreamhost.com and I am using Rails 2.3r
In a production environment you probably want to use passenger instead of doing things by yourself.
"No port" for HTTP means port 80, so specify that with the -p 80 or --port=80:
nohup ruby script/server webrick -e production -p 80 &
You don't need Passenger, but using it can make things easier to manage for smaller apps and requires less babysitting.
Related
I setup Nginx for listening to lockalhost:3000 than I launch rails command bundle exec rails server webrick -e production. I found that I can launch rails server as daemon simply adds the -d flag to the command, so the command becomes a bundle exec rails server -d webrick -e production. My problem is that after server reloads or app is crushed - that a dead-end, I can't found info about how should I create "rails as a daemon with auto relaunch".
webrick in production?
Please please please refrain from doing anything like that. Use puma or unicorn or any similar app server for your purpose.
And for the process monitoring part, you can use systemd, or monit for better control.
Personally, I prefer monit as it gives me crash logs and downtime alerts.
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
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.
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.
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