Elastic Beanstalk部署后自动重启SolR

时间:2015-06-25 10:19:35

标签: ruby-on-rails amazon-web-services solr elastic-beanstalk

我在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 中添加命令块来停止服务器(并且我将我的sh脚本更改为启动服务而不是重启):

commands:
  1_stop_solr:
    command: cd /var/app/current & RAILS_ENV=production rake sunspot:solr:stop

我收到了这个错误(我不知道从哪里执行):

[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]:活动执行失败,原因是:rake aborted!   找不到HOME环境 - 扩展`〜'

编辑1(遵循杰伊的评论): 索引过程在保存对象时完成。

以下是实体(以及失败的地方)的示例:

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服务器,启动然后重新索引。

这真的很痛苦:)

2 个答案:

答案 0 :(得分:1)

我对Beanstalk一无所知,但看起来执行命令的shell没有你期望的环境变量。假设post-deployment scripts上的这篇博客文章是正确的,您应该可以将setup.sh脚本更改为以下内容:

 #!/usr/bin/env bash
 . /opt/elasticbeanstalk/support/envvars
 cd $EB_CONFIG_APP_CURRENT
 su -c "RAILS_ENV=production /usr/local/bin/rvm 2.2 do rake sunspot:solr:restart" $EB_CONFIG_APP_USER

答案 1 :(得分:0)

我知道这是一个老问题,但我写了一个ebextensions脚本,似乎适用于这种情况。希望如果人们仍然遇到这个问题,这将有所帮助。

[2]