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.
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.
When generating toy_app using scaffolding I can go to the root site using the local server, but when I try to go to the page /users I get the following error message: "Errno::ENOENT in UsersController#index"
The page should allow me to enter a new user.
When I try to restart the server and run rails server -b $IP -p $PORTI get the following:
sunny_dee#rails-tutorial:~/workspace/toy_app (master) $ rails server -b $IP -p $PORT
=> Booting WEBrick
=> Rails 4.2.0 application starting in development on http://0.0.0.0:8080
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2015-04-27 18:06:55] INFO WEBrick 1.3.1
[2015-04-27 18:06:55] INFO ruby 2.1.5 (2014-11-13) [x86_64-linux]
Exiting
/usr/local/rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/socket.rb:206:in `bind': Address already in use - bind(2) for 0.0.0.0:8080 (Errno::EADDRINUSE)
I finally got it to work by restarting the workspace. I'm guessing that is what restarted the local server. I was trying Ctrl-C but it was not working.
The tutorial uses Cloud9 and since it's a cloud IDE closing/logging out did nothing but when I clicked on the button to the left of "Share" on the top right corner and the clicked on "Restart" the page ran correctly.
Hopefully my stupid question can help someone else as well. Thanks everyone that took the time to contribute :)
If you running this application in your local Linux system just use -
rails server
Then you can access your site using http://localhost:3000/
You can also specify which port to run on using this command -
rails s -p 3001 -P tmp/pids/server2.pid
Then you can access using 3001 port.
You are getting that error because your 8080 port is already in use by some other process.
Rails noob here. I'm trying to work through Michael Hartl's Ruby on Rails Tutorial, but every time I run rails server, it keeps Exiting and shows me a SocketError. I was able to run the server just fine this past weekend using wifi from a startup, so I'm guessing it has something to do with my internet connection/firewall? I also ran into the same problem with the server at the library this afternoon.
Any help is appreciated! Thanks in advance.
=> Booting WEBrick
=> Rails 4.2.0 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2015-02-23 22:33:11] INFO WEBrick 1.3.1
[2015-02-23 22:33:11] INFO ruby 2.2.0 (2014-12-25) [x86_64-darwin14]
Exiting
/Users/awo/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/socket.rb:232:in `getaddrinfo': getaddrinfo: nodename nor servname provided, or not known (SocketError)
I had messed with my hosts file in the past, and removing and creating a new default one (with localhost included) seemed to do the trick . Got mine from here:
##
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
I'm thinking the path was screwed up or there were some ninja whitespaces lurking in my /private/etc/hosts file.
I had the same problem recently, which I resolved by adding 127.0.0.1 localhost record to the private/etc/hosts file
First you need to identify the port id of rails server so run below command that give list of PID which run on 3000 port
lsof -wni tcp:3000
the number in the PID column to kill the process:
kill -9 PID
I made the basic blog demo from a rails tutorial in a book from 2007. I realized it's dated so I deleted the blog I made and began to redo it from a tutorial here: http://guides.rubyonrails.org/getting_started.html#creating-the-blog-application
I started from scratch and now I'm stuck on 4.3 on that link's instructions because when I type in http://localhost:3000/ I keep getting the default screen for Rails instead of "Hello, Rails!" like the tut says I should.
The instructions on 4.3 are to type in
rm public/index.html
And then access the routes.rb file to uncomment the root to: section so that it says
root :to => "welcome#index"
I continued on with the migration and all that but I still keep getting the default screen.
Then I typed
rails server -d
to see if that does the trick but nope. It just says this only ending with the 2nd =>:
blog ❯ rails server -d
=> Booting WEBrick
=> Rails 3.2.3 application starting in development on http://0.0.0.0:3000
If I just type
rails server
I get an error in terminal that says the following:
blog ❯ rails server
=> Booting WEBrick
=> Rails 3.2.3 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2012-05-28 17:42:34] INFO WEBrick 1.3.1
[2012-05-28 17:42:34] INFO ruby 1.9.3 (2012-02-16) [x86_64-darwin11.3.0]
[2012-05-28 17:42:34] WARN TCPServer Error: Address already in use - bind(2)
Exiting
/Users/Nick/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/webrick/utils.rb:85:in `initialize': Address already in use - bind(2) (Errno::EADDRINUSE)
from /Users/Nick/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/webrick/utils.rb:85:in `new'
If anyone wants me to paste the rest of the error I'll go ahead and do that.
I'm not sure what to do from here to fix this.
Thanks for your help
TCPServer Error: Address already in use - bind(2)
One of two things is happening:
You already have a WEBrick server running elsewhere on port 3000. Kill it before starting a new one.
Some other process is listening on port 3000
The first time you did rails server -d, you started a backgrounded WEBrick service that is eating port 3000. Find the running process and kill it via:
ps aux | grep ruby
kill [PID from above]
Then restart your WEBrick with just rails server. At this point, having already removed the public/index.html, your route should be active and working.
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.