Rails WEBrick not writing log to terminal (stdout) - ruby-on-rails

WEBrick usually writes its output to both development.log and stdout. However it suddenly stopped doing so and it is not writing to stdout. All we're getting is
Booting WEBrick
=> Rails 3.2.8 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
and then nothing. development.log seems to be written to properly.
This is a project-specific problem because it's happening to all members of our team in different computers. On the other hand if I create another Rails project (and copy the Gemfile and Gemfile.lock to ensure I have the same gems) I get the normal output on the terminal.
This is a big problem because among other things it prevents us from using pry or ruby-debug since I have no access to the process on a breakpoint.
We're using Ruby ruby-1.9.3-p194, Rails 3.2.8 and WEBrick 1.3.1. In case it matters we're all on Macs (Mountain Lion).
Any ideas what could be causing this and how to solve it? We need stdout back! Thanks

It turned out that someone had added these three lines to config.ru
log = File.new("console.log", "a+")
$stdout.reopen(log)
$stderr.reopen(log)
It was very painful to figure out this one, so needless to say, don't do that.

If you use pry-remote you should be fine.

Related

Rails won't exit on first CTRL-C

No Rails command will exit on the first CTRL-C. So rails s or rails c require me to hit control CTRL-C a second time and commands that previously wouldn't have required a CTRL-C at all such as rake routes / db:migrate now require me to press it.
The issue is not happening for any of my teammates. I'm on OSX using iTerm2. There are no instances of 'rescue Exception' in the app.
I've just reinstalled mysql using brew and the issue is still present. Rails version 4.0.5 and sql server version 5.6.27. Any idea where the issue might be?
[2016-01-13 16:18:33] INFO WEBrick 1.3.1
[2016-01-13 16:18:33] INFO ruby 2.1.2 (2014-05-08) [x86_64-darwin13.0]
[2016-01-13 16:18:33] INFO WEBrick::HTTPServer#start: pid=2329 port=3000
^C[2016-01-13 16:18:54] INFO going to shutdown ...
[2016-01-13 16:18:54] INFO WEBrick::HTTPServer#start done.
Exiting
^C
Honestly Webrick 1.3.1 was released in December 28, 2011 I would suggest moving away from this see webrick answer for the reasons.
As you have said that it happens in rails consoles and other tasks (You should really put this in the question as it helps with debugging) I would suggest it is a gem that is causing this (You should update your rails version anyway) but I would suggest using:
Ctrl-D
This should exit you straight away
I suspect this isn't as much an answer as a suggestion, but I started using Puma by default in my projects a while back, and given that Rails 5 is moving to Puma by default it may not be a bad suggestion.
I use a similar environment, OS X 10.11.2, iTerm 2, tmux, etc. I can't recall when or what prompted it, but at some point my WEBrick projects started behaving this same way, and I started moving them to Puma where possible which didn't seem to show the same behavior.
I know that doesn't really give a clear answer as to what's causing the issue, but also, I too know it's not system performance related.

Rails - ctrl-c ignored after starting server

I have Ruby v1.9.3 and Rails v3.2.3 on Win7. I have no problem generating a Rails directory and starting the Ruby server, but what happens is that once the server is started I have no prompt and no code I type seems to execute.
to be specific - here is the terminal code from a session:
=> 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-04-30 06:25:06] INFO WEBrick 1.3.1
[2012-04-30 06:25:06] INFO ruby 1.9.3 (2012-02-16) [i386-mingw32]
[2012-04-30 06:25:06] INFO WEBrick::HTTPServer#start: pid=2112 port=3000
after this point there is no prompt and no command I type seems to produce a result (including ctrl-c).
what am I doing wrong?
This worked: Im doing a rails tutorial and this was the got me back on track. Ctrl-Pause/Break stopped the server.
I assume you're running rails server to get to this point.
Everything is working as it should. Rails is a web framework and when you run it in server mode it doesn't accept commands from the terminal. Instead Rails listens for web requests on port 3000 and responds appropriately. While the server is running the terminal window is displaying the internal server logs. Visit http://localhost:3000 while the server is running and you'll see what I mean.
If you want some command line interactivity, run rails console instead. This will load up your Rails environment but instead of listening for web requests on a port it'll give you an irb prompt where you can type ruby.
Ctrl-Pause/Break works. "Pause/Break" confused me for a little bit, so if you are new like me it is the key usually next to F12 that says "pause break". :)

Rails - no command prompt after starting server?

total n00b question here but I can't seem to find the answer searching around here or the web.
I have Ruby v1.8.7 (2009-06-12 patchlevel 174) and Rails v.2.3.5 installed on my Mac (10.6.8). I have no problem generating a Rails directory and starting the Ruby server, but what happens is that once the server is started I have no prompt and no code I type seems to execute.
to be specific - here is the terminal code from a session:
bvb:new bennettvonbennett$ ruby script/server
=> Booting Mongrel
=> Rails 2.3.5 application starting on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
after this point there is no prompt and no command I type seems to produce a result.
what am I doing wrong?
This is the correct behavior. You're not doing anything wrong.
The server runs in the foreground so that you can see the log output on every page load without having to open a specific log file. It's very helpful for debugging and staying aware of what the code you write does to the application and the database.
To return to a normal command prompt, you can send an end-of-text character (usually ctrl-c) to stop the server. Most of us Rails-folk work with multiple terminal windows open - server running in one, and others for other functions, such as the rails console, started with
ruby script/console
which will let you experiment with other Rails controller functions, much like irb for standard Ruby.
With ruby script/server you launch the webserver. Run ruby script/console if you want to execute commands against your current Rails application.
You're loooking for:
script/console
If you want to play with your project in a console.

Telling which ruby on rails project is running

My client wants me to download a working ruby on rails project to my local system. But when I connected to a server, I got nine identical project folders (which seem like different versions). Is there a way to know which project is running using process id (I have only the process id)?
If you have the process ID, then check /proc/[pid]/cwd symbolic link. This is the process' current directory.
I assume that you are on a Linux-like system.
If you are not, then you may issue a HTTP request (to wake up the rails app) and then look which logfile has been modified recently.
if you are able to run rails console on your server then type this: Rails.root in your console or irb it will tell that project you are on belongs to which directory!
no we cant know using process id. but when you start server you will find rails version like
:> ruby script/server
=> Booting Mongrel
=> Rails 2.3.10 application starting on http://0.0.0.0:3000
above line using rails 2.3.10 version and if you want to know ruby version simply call
ruby -v in your command prompt

Rails not working with Safari

I'm trying to learn some basics of Ruby on Rails and encountered a problem : my Rails project seems to work fine with Firefox but nothing is shown with Safari?
I also tried this with a new project :
rails emptytest
cd emptytest
script/server
Producing output:
=> Booting Mongrel
=> Rails 2.3.5 application starting on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
With Firefox, the Rails default page was shown, with Safari nothing was shown (no error, "Page source" was also empty).
Hmm... While still writing this, I found the thread Rails 2.3 just serving Firefox which adviced to upgrade mongrel (the web server); for some reasons Rails 2.3 and old versions of Mongrel would not work well together.
sudo gem update mongrel
After that, rails pages were shown as supposed with Safari also.
I'll write this down here if somebody ends up in the same situation. (I didn't found anything relevant with tags ruby-on-rails + safari)
As mentioned in the question, upgrading mongrel solved the problem.

Resources