Wednesday, 12 March 2008

mongrel_rails service and $stdout problem on Windows server

« Experimenting with MySQL spatial extensions | Main | Английски »

Charlie:

First, if you have the choice, ditch windows, not worth it. However, if you are like me and are forced to use windows for a project then your solution is a simple derivative of what you will find here.

I'm forced to work with a Windows server too and I was experimenting the same issue. Charlie put me on the right track and I solved it adding what follows at the beginning of #{RAILS_ROOT}/config/boot.rb:

begin
  $stdout.write("checking $stdout -> ")
  $stdout.flush # really try to write!
  $stdout.write("OK\n")
rescue
  $stdout.reopen('log/mongrel.log')
  $stderr.reopen('log/mongrel_err.log')
end

As $stdout and $stderr are redirected only when IO#write raises an exception, it is effective only when Mongrel is running as a service and you still can launch it from a terminal or use a console without any problem.

Posted by Nicola Piccinini at 12:57 AM CET in devel/