I have a RoR app on AWS. My application uses SolR for the search engine, but after each deployment, the application cannot index again. Therefore, I have to allow reset and restart Solr manually with
chmod 777 -R /solr /tmp /log RAILS_ENV=production rake sunspot:solr:stop
Now I'm trying to configure it as an eb extension to automate deployment. Here is what I tried in my .ebextensions / deploy.config:
container_commands: 1_change_permissions: command: chmod 700 .ebextensions/setup.sh 2_restart_solr: command: bash .ebextensions/setup.sh
And here is the setup.sh script:
#!/bin/bash chmod 777 -R solr/ log/ tmp/ RAILS_ENV=production rake sunspot:solr:restart
As a result, the deployment will not work, but only the permissions will be correctly changed, and the solr service is started, but when I try to index something, it fails (the request works fine).
I also tried stopping the server before the application was deployed by adding a command block to my .ebextensions / deploy.config (and I changed the sh script to start the service instead of restarting):
commands: 1_stop_solr: command: cd /var/app/current & RAILS_ENV=production rake sunspot:solr:stop
I got this error (I don't know where it comes from):
[2015-06-25T09: 51: 35.510Z] INFO [13207] - [CMD-AppDeploy / AppDeployStage0 / EbExtensionPreBuild / Infra-EmbeddedPreBuild / prebuild_0_My_First_Elastic_Beanstalk_Application / Command 1_stop_solr, aber:] aber:] could not find home environment HOME - extension `~ '
EDIT 1 (next jay comment): The indexing process is executed when I save the objects.
Here is an example for an entity (and where it does not work):
class Document < ActiveRecord::Base # ..... # SolR entity searchable do text :title, :description, :tags integer :user_id end # ..... end
** EDIT 2: **
James's answer does not fix the problem, but, I understand that manually on my EC2 instance, I can simply run the following two lines:
chmod 777 -R solr/ tmp/ log/ RAILS_ENV=production rake sunspot:reindex"
I tried using the James link to create a post-deployment script, and chmod works fine, but when I add the reindex command to the file, the deployment fails with this error:
[2015-07-07T16:26:25.509Z] INFO [20402] - [CMD-AppDeploy/AppDeployStage1/AppDeployPostHook/99_restart_delayed_job.sh] : Activity execution failed, because: rake aborted! Could not find rake-10.4.2 in any of the sources /var/app/current/config/boot.rb:3:in `<top (required)>' /var/app/current/config/application.rb:1:in `<top (required)>' /var/app/current/Rakefile:4:in `<top (required)>'
Also, if I try to execute the command manually (after the script chmod post-deployment), it will not be able to execute 500 errors for each element to override. So I need to kill the solr server, start, and then re-index.
This is very painful:)