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
| Print article | This entry was posted by Akhil Bansal on September 13, 2007 at 2:24 pm, and is filed under ROR, Rails, Rubyonrails, acts_as_solr, full text search, rails_plugin, ruby, solr. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |
about 2 years ago
Would be great if you filed a ticket for this issue: http://acts_as_solr.railsfreaks.com/newticket
about 2 years ago
coool…bro !!!!
about 2 years ago
Thank you!! This solved our problem in seconds. Really appreciate the work you did.
about 2 years ago
Thank you! but how can we stop solr ?
Ctrl^C is one way, but I wish to stop from script..
about 2 years ago
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”
about 2 years ago
Thanks buddy! it worked but I didn’t need Errno::EBADF (i left that part alone)
cheers
about 2 years ago
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?
about 2 years ago
Ahmed,
Make sure MySQL service is running.
about 2 years ago
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.
about 2 years ago
Immad
Thanks for your advice. It works for me.
about 2 years ago
Thanks to all of you guys. I am pleased to know that it helped.
–
Akhil
about 2 years ago
You guys can recommend me on working with rails. click here http://www.workingwithrails.com/recommendation/new/person/2892-akhil-bansal
about 2 years ago
@Immad
Yes, it worked perfectly after I changed the errorno.
Thx very much guys for your help
about 1 year ago
Good Work.
Are you having any idea how to start with webrick while deployment.
Thanks!
about 1 year ago
@sandip: Could you be more specific what do you want to do?
about 1 year ago
@akil
When i start webrick server,
that time i want to start solr server also in background.
about 1 year ago
@sandp: No, you can’t hook that with webrick. you need to write a script that start webrick and solr.
about 1 year ago
@akil
k, Have you any idea how to write that script ?
about 1 year ago
@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
about 1 year ago
@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 ?
about 1 year ago
finally, I found how to start solr in deamon.
about 1 year ago
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
about 6 months ago
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.
about 11 months ago
I had the problem like Ahmed, until I change the solr.rake file becomes like this : http://pastie.org/632975
about 6 months ago
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!