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
Would be great if you filed a ticket for this issue: http://acts_as_solr.railsfreaks.com/newticket
coool…bro !!!!
Thank you!! This solved our problem in seconds. Really appreciate the work you did.
Thank you! but how can we stop solr ?
Ctrl^C is one way, but I wish to stop from script..
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”
Thanks buddy! it worked but I didn’t need Errno::EBADF (i left that part alone)
cheers
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?
Ahmed,
Make sure MySQL service is running.
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.
Immad
Thanks for your advice. It works for me.
Thanks to all of you guys. I am pleased to know that it helped.
–
Akhil
You guys can recommend me on working with rails. click here http://www.workingwithrails.com/recommendation/new/person/2892-akhil-bansal
@Immad
Yes, it worked perfectly after I changed the errorno.
Thx very much guys for your help
Good Work.
Are you having any idea how to start with webrick while deployment.
Thanks!
@sandip: Could you be more specific what do you want to do?
@akil
When i start webrick server,
that time i want to start solr server also in background.
@sandp: No, you can’t hook that with webrick. you need to write a script that start webrick and solr.
@akil
k, Have you any idea how to write that script ?
@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
@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 ?
finally, I found how to start solr in deamon.
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
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.
I had the problem like Ahmed, until I change the solr.rake file becomes like this : http://pastie.org/632975
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!