我在AWS上有一个RoR应用程序。我的应用程序使用SolR作为搜索引擎,但是每次部署后,应用程序都无法再次进行索引。因此,我必须手动重置权限并重新启动Solr:
chmod 777 -R /solr /tmp /log
RAILS_ENV=production rake sunspot:solr:stop # or I kill the processus if it doesn't work :D
RAILS_ENV=production rake sunspot:solr:start
RAILS_ENV=production rake sunspot:reindex
我现在正在尝试将它设置为EB扩展以自动化部署。以下是我在.ebextensions/deploy.config中尝试的内容:
container_commands:
1_change_permissions:
command: chmod 700 .ebextensions/setup.sh
2_restart_solr:
command: bash .ebextensions/setup.sh
以下是setup.sh脚本:
#!/bin/bash
chmod 777 -R solr/ log/ tmp/
RAILS_ENV=production rake sunspot:solr:restart
结果是部署不会失败,但只有权限被正确更改,Solr服务正在运行,但当我尝试索引某些内容时,它会失败(查询工作正常)。
我还尝试在我的.ebextensions/deploy.config中添加一个commands块(并将我的sh脚本更改为启动服务而不是重新启动)来在应用程序部署之前停止服务器:
commands:
1_stop_solr:
command: cd /var/app/current & RAILS_ENV=production rake sunspot:solr:stop
我遇到了这个错误(我不知道它是从哪里执行的):
[2015-06-25T09:51:35.510Z] 信息 [13207] - [CMD-AppDeploy/AppDeployStage0/EbExtensionPreBuild/Infra-EmbeddedPreBuild/prebuild_0_My_First_Elastic_Beanstalk_Application/Command 1_stop_solr]:活动执行失败,原因是:rake中止! 找不到HOME环境--扩展`~'
编辑1(根据jay的评论): 当我保存对象时,索引过程会完成。
以下是一个实体的示例(以及出现错误的位置):
class Document < ActiveRecord::Base
# .....
# SolR entity
searchable do
text :title, :description, :tags
integer :user_id
end
# .....
end
**编辑 2:**
詹姆斯的答案没有解决问题,但是我意识到在我的EC2实例上手动运行以下两行代码即可:
chmod 777 -R solr/ tmp/ log/
RAILS_ENV=production rake sunspot:reindex"
我尝试使用James的链接来创建一个部署后脚本,chmod命令可以正常运行,但是当我将reindex命令添加到文件中时,部署失败并出现以下错误:
[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)>'
此外,如果我尝试手动运行命令(在执行后部署脚本的chmod之后),每个重新索引的项目都会出现500错误。因此,我需要终止solr服务器,然后重新启动并重新索引。
这真的很痛苦 :)