Its all about Ruby On Rails
Acts_as_solr: Starting solr server on windows
I was using acts_as_searchable for one of my project, which uses Hyperestraier in background. Yesterday I decided to use acts_as_solr which uses solr(based on Lucene Java search library). I did all written in its Manual/Readme, but when I issued
rake solr:start
to start the solr server, it threw a heart breaking “Bad file descriptor” error, although acts_as_solr was working fine on one of my colleague’s linux machine.
I started digging around this and found that there is an issue in rake task that starts the solr server. Actually the problem was this rake task uses ‘fork’ which is not available on windows, also it only handles ‘ECONNREFUSED’ exception which is actually “Connection Refused” error raised by ruby on linux. But in windown it throws ‘EBADF’ which is “Bad file descriptor” error raised by ruby on windows.
So below is the hack for that:
desc 'Starts Solr. on windows . Options accepted: RAILS_ENV=your_env, PORT=XX. Defaults to development if none.'
task :start_win do
begin
n = Net::HTTP.new('localhost', SOLR_PORT)
n.request_head('/').value
rescue Net::HTTPServerException #responding
puts "Port #{SOLR_PORT} in use" and return
rescue Errno::EBADF #not responding
Dir.chdir(SOLR_PATH) do
exec "java -Dsolr.data.dir=solr/data/#{ENV['RAILS_ENV']} -Djetty.port=#{SOLR_PORT} -jar start.jar"
sleep(5)
puts "#{ENV['RAILS_ENV']} Solr started sucessfuly on #{SOLR_PORT}, pid: #{pid}."
end
end
end
Just add this to vendor/plugins/acts_as_solr/lib/taks/solr.rake, and start solr server on windows by issuing
rake solr:start_win

September 19, 2007 - 3:53 am
Would be great if you filed a ticket for this issue: http://acts_as_solr.railsfreaks.com/newticket
October 23, 2007 - 12:24 pm
coool…bro !!!!
October 31, 2007 - 8:39 pm
Thank you!! This solved our problem in seconds. Really appreciate the work you did.
November 6, 2007 - 6:33 am
Thank you! but how can we stop solr ?
Ctrl^C is one way, but I wish to stop from script..
November 22, 2007 - 2:29 pm
This hack didn’t work for me until I renamed the task from :start_win to :startwin. The ‘_’ seems to be a problem in my rails app.
@takemoto: Stop Solr by calling “rake solr:stop”
January 13, 2008 - 11:07 am
Thanks buddy! it worked but I didn’t need Errno::EBADF (i left that part alone)
cheers
February 11, 2008 - 5:20 pm
I tried to work on windows. but whenever I try to run the rake start_win I got the following error “No connection could be made because the target machine actively refused it. – connect(2)”.
My firewall is turned off, so I wonder what may be the problem?
February 15, 2008 - 3:48 pm
Ahmed,
Make sure MySQL service is running.
February 26, 2008 - 9:10 am
Ahmed,
I had to change Errno::EBADF back to Errno::ECONNREFUSED to make it work on windows. The task tries to send an http request to the server, which isn’t running when you invoke the task, so it catches the excepiton and starts the server. For some reason, the exception being thrown is ECONNREFUSED, not EBADF.
March 17, 2008 - 9:06 pm
Immad
Thanks for your advice. It works for me.
March 17, 2008 - 10:44 pm
Thanks to all of you guys. I am pleased to know that it helped.
–
Akhil
March 17, 2008 - 10:46 pm
You guys can recommend me on working with rails. click here http://www.workingwithrails.com/recommendation/new/person/2892-akhil-bansal
April 1, 2008 - 8:23 pm
@Immad
Yes, it worked perfectly after I changed the errorno.
Thx very much guys for your help
September 25, 2008 - 12:21 pm
Good Work.
Are you having any idea how to start with webrick while deployment.
Thanks!
September 25, 2008 - 12:23 pm
@sandip: Could you be more specific what do you want to do?
September 25, 2008 - 1:09 pm
@akil
When i start webrick server,
that time i want to start solr server also in background.
September 25, 2008 - 1:12 pm
@sandp: No, you can’t hook that with webrick. you need to write a script that start webrick and solr.
September 25, 2008 - 1:16 pm
@akil
k, Have you any idea how to write that script ?
September 25, 2008 - 1:18 pm
@sandip: Its up to you, you can write a ruby script or a bash script.
in ruby script:
system(“ruby script/server”)
system(“rake solr:start_win”)
some thing like that
September 25, 2008 - 1:22 pm
@akil
Can you clarify bit more ?
Because, i have not written any script yet.
& also i will prefer ruby script
so,How will be that exactly ?
September 29, 2008 - 6:14 pm
finally, I found how to start solr in deamon.
November 6, 2008 - 4:32 am
I’m using Aptana Rad Rails IDE(in Windows) for my rails development and I have not
been able to get acts_as_solr installed.
I tried doing
1. script/plugin install svn://svn.railsfreaks.com/projects/acts_as_solr and
2. script/plugin install git://github.com/railsfreaks/acts_as_solr.git
with (1) nothing happens and with (2) I get “Plugin not found: ["git://github.com/railsfreaks/acts_as_solr.git"]” msg.
can u plz help me on how to install acts_as_solr.. thanks a lott in advance
February 7, 2010 - 10:09 pm
Looks like you dont have either SVN or GIT clientinstalled. I suggest getting the GIT Client.
http://code.google.com/p/msysgit/downloads/list
It should work now.
September 28, 2009 - 9:15 am
I had the problem like Ahmed, until I change the solr.rake file becomes like this : http://pastie.org/632975
February 7, 2010 - 10:13 pm
Also.. For ppl finding it difficult to install the plugin in windows even after following the tutorial add this line right after the ‘task’ block.
require “#{File.dirname(__FILE__)}/../../config/solr_environment.rb”
also add the entire block of code in the end just before: “def env_array_to_constants(env)”
Cheers!