Sunspot Solr error on rake sunspot:index - ruby-on-rails

I am trying to use Sunspot gem for Solr on a Rails 3 app. I have followed RailsCast #278, since I am using Windows I have to do rake sunspot:solr:run and that seems to start with no error. However when I try to run rake sunspot:reindex I get the error:
No connection could be made because the target machine actively refused it. - connect(2)
I am using mysql2 gem for mysql. Please advise.

I have to do rake sunspot:solr:run and that seems to start with no error
It sounds like the connection is not being accepted at all to Solr, so this part is my first suspicion — you should get a lot of fairly verbose output from Solr when starting it. Can you share some output of that?
Also, what version of java are you running? (java -version)

I had the same problem running "bundle exec rake sunspot:solr:reindex" on Windows. The solution is to add the correct RAILS_ENV option, for me it was test, e.g.
bundle exec rake sunspot:solr:reindex RAILS_ENV=test
Yes, you'll have to have solr server running beforehand:
bundle exec rake sunspot:solr:run RAILS_ENV=test

Related

Delayed Job in Rails 4 with Capistrano

I cant figure how to start Delayed Jobs on a dedicated Ubuntu server.
It works fine on my localhost but when I run on my server
sudo RAILS_ENV=production bin/delayed_job restart
I get
sudo: bin/delayed_job: command not found
On top of that, if I run the "rake jobs:work RAILS_ENV=production" command Im getting the following error:
PG::FeatureNotSupported: ERROR: SELECT FOR UPDATE/SHARE is not allowed in subqueries
Apparently theres an issue with my psql version.
Is there any way I can get the script to work? Any effective Capistrano recipes available? All ive found on the web are old recipes for Rails 3 and older versions of capistrano.
Thanks in advance.
EDIT:
I have already bundled install the daemons gem and generated "delayed_job:active_record" on my local machine, then proceded to cap deploy which bundle installed and migrated in the production server.
The bin/delayed_job file exists in the server yet it fails with command not found.
And add this to config/environment.rb:
ENV['RAILS_ENV'] ||= 'production'
Then at your production server:
RAILS_ENV=production rake db:migrate
RAILS_ENV=test production generate delayed_job:active_record && RAILS_ENV=production rake db:migrate
Now after you do that:
RAILS_ENV=production script/delayed_job start
As for Capistrano error you are facing, please try to add the command like:
run "cd #{current_path}; #{sudo} RACK_ENV=production bundle exec #{current_path}/bin/delayed_job start"
You must run this on target server:
bundle exec rails generate delayed_job

Solr Sunspot Production environment setup issue

I am trying to setup solr sunspot search in production mode.
I have followed the below tutorial and got success in setting up tomcat-solr server running.
http://www.arborisoft.com/how-to-install-apache-solr-4-4-on-ubuntu-12-04/
I ran
rails generate sunspot_rails:install
and configured the config/sunspot.yml file.
For development mode I used 'sunspot_solr' gem(which is not advisable for production mode) and got this command working.
bundle exec rake sunspot:solr:start
When I removed this gem
it's giving me following error
Note: This task has been moved to the sunspot_solr gem. To install, start and
stop a local Solr instance, please add sunspot_solr to your Gemfile:
group :development do
gem 'sunspot_solr'
end
I have tried adding this to Rakefile:
require 'sunspot/solr/tasks'
when I run the following command
bundle exec rake app:sunspot:solr:start
I am getting the following error
rake aborted!
cannot load such file -- sunspot/solr/tasks
I am using rails 4.
I don't know what I've missed. I have searched for the solution in and out of stackoverflow. But I couldn't get any reference. Even if I find any since I am a rails noob, I couldn't understand what they are talking about. any solution will be really helpful.
You can also change the path to solr/default in config/sunspot.yml file for production mode or any other defined modes.
These are some terminal commands which could follow to solve your problems:
ps aux | grep solr to get solr process ID
through this you can check which server id is running and which one is in your sunspot pid file.
sudo kill <ID>, <ID> is the ID you found from 1
rm -r <path/to/solr>, remove the solr directory inside your project to remove all of previous indexes
RAILS_ENV=production bundle exec rake sunspot:solr:start
Change the path to /solr/default inside config/sunspot.yml
RAILS_ENV=production bundle exec rake sunspot:solr:reindex
this link can also help in understanding problem and issues:https://github.com/sunspot/sunspot/issues/492

Can't reindex Sunspot SOLR - Error - RSolr::Error::Http - 500 Internal Server Error

Everytime i try to reindex using...
rake sunspot:solr:reindex
These error messages always show:
Error - RSolr::Error::Http - 500 Internal Server Error - retrying...
Error - RSolr::Error::Http - 500 Internal Server Error - ignoring...
Error - RSolr::Error::Http - 500 Internal Server Error - retrying...
Error - RSolr::Error::Http - 500 Internal Server Error - ignoring...
I tried to stop then start using...
rake sunspot:solr:stop
rake sunspot:solr:start
But nothing happened.
And now everytime I try to run my app in localhost...
This is the error:
RSolr::Error::Http - 500 Internal Server Error
Error: Severe errors in solr configuration.
Check your log files for more detailed information on what may be wrong.
If you want solr to continue after configuration errors, change:
<abortOnConfigurationError>false</abortOnConfigurationError>
in null
-------------------------------------------------------------
Request Data: "<?xml version=\"1.0\" encoding=\"UTF-8\"?><delete><query>type:Trip</query></delete>"
A more detailed error message than the one I had in terminal.
I tried plenty of solutions from the net like setting Abort Configuration to false, but nothing happened.
The error still persists.
Any work around will be appreciated.
The solution:
rake sunspot:solr:stop
rm -rvf solr (Delete your /solr directory)
rake sunspot:solr:start
rake sunspot:solr:reindex
Enjoy
Based on the answer provided by #professormeowingtons, what worked for me in production is the following:
$ rake sunspot:solr:stop RAILS_ENV=production
$ rm -rvf solr # delete your /solr directory
$ sudo reboot # reboot the machine RAILS_ENV=production
$ rake sunspot:solr:start RAILS_ENV=production
$ rake sunspot:solr:reindex RAILS_ENV=production
With reference to #professormeowingtons, you don't have to delete entire solr directory as you might not want to delete your solr configurations like schema.xml and solrconfig.xml. The reason you are getting error might be because of corrupted indexes, what you can do is delete 'solr/env' i.e. solr/development or/and solr/data/development and restart solr server.
1. rake sunspot:solr:stop
2. rm -rf solr/development (Delete your solr/development directory)
3. rm -rf solr/data/development
4. rake sunspot:solr:start
5. rake sunspot:solr:reindex
If problem still persists, rollback your recent changes because you might have added some wrong configurations.
I've got this working by restarting my PC. I guess there was a solr instance incorrectly stopped :-?
This means there is a problem in your config file and solr couldn't start. Check the sunspot logs.
Check your sunspot server by localhost:8982 (depelopment). if you get same error like console. try again by localhost:8983 (production). for my case, port 8983 is work fine and I change sunspot config at rails/config/sunspot.yml to port :8983. and solved.
Upgrade Rsolr gem to latest version, 1.0.10.pre1, that worked for me.
Now I was able to reindex my models, and everything seems fine, in production that is.
For those of you that are using Websolr in Heroku production and getting this error when reindexing:
Remember that you have to upload your schema.xml manually in the Websolr admin GUI, under the "Advanced Configuration" tab when viewing your index.
Here's the direct link: https://websolr.com/slices/<index_uri>/schema
You can get the <index_uri> from running heroku config and getting it from the last part of your
WEBSOLR_URL that looks like this: http://index.websolr.com/solr/<index_uri>
I ran into this error because I mistakenly assumed that Websolr would just use the schema.xml that I committed to git and pushed to heroku together with all the other <appname>/solr/conf files.
The essence is to reset every sunspot solr part, that may occur problems.
Delete the complete solr directory. This deletes the complete solr directory for sure - double check!
rm -rf solr
Delete the sunspot solr configuration file config/sunspot.yml.
rm config/sunspot.yml
Stop sunspot solr.
bundle exec rake sunspot:solr:stop
Check if sunspot solr is no longer running. If there are solr processes running note there PID
ps aux | grep solr
Manually kill the solr processes by PID. This command is only needed if bundle exec rake sunspot:solr:stop wasn't successful.
kill -9 PID # (fully turns off solr - double check `ps aux|grep solr`)
Delete your database, double check if you really sure! Then recreate the database and restore the schema from the migration files.
bundle exec rake db:drop
bundle exec rake db:create
bundle exec rake db:migrate
creates a new sunspot configuration config/sunspot.yml.
rails generate sunspot_rails:install
recreates the solr directory
bundle exec rake sunspot:solr:start
create a new solr index
bundle exec rake sunspot:reindex
Finally refill the empty database with your seed data.
bundle exec rake db:seed

Rake db:create error - cannot load such file -- resque/tasks

setting up existing apps on my new machine.
The first app (a simple one) went ok.
For the second app most things are ok but now getting
Rake aborted!
cannot load such file -- resque/tasks
when trying to run rake db:create
I've installed redis and I believe it is running.
How can I resolve this error?
Ruby 1.9.3 Rails 3.2.8
Installed the resque gem to fix this.

running rake task on 'production' and specifying environment?

I have a host at Linode and am trying to run a Rake task on it, but I get a mySQL error saying it can't connect. It looks like it thinks it is on dev. I did some Googling and saw that I can do something like this:
bundle exec rails c
It loads the dev environment and I can't run User.all giving me an access denied error.
If I run bundle exec rails c RAILS_ENV=production I get the error:
Rails.env=production database is not configured (ActiveRecord::AdapterNotSpecified)
However, if I access it via the web, everything is OK. I was able to run rake db:seed before so I know that there's some way around this.
Accessing mySQL with the production credentials works fine.
Any ideas?
Try this:
rails c production
or, at the beginning:
RAILS_ENV=production rails c
It thinks you're passing RAILS_ENV=production as an argument when you put it at the end.
If you want to run your console in the context of the current bundle in your Gemfile and ensure you're using your Gemset use:
bundle exec rails c production
This works for me. It depends on how your server and all its dependencies are set up:
RAILS_ENV=production bundle exec rails console

Resources