Elastic Beanstalk部署后自动重启SolR

Jul*_*vez 6 solr ruby-on-rails amazon-web-services amazon-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
Run Code Online (Sandbox Code Playgroud)

现在我正在尝试将其设置为eb扩展以自动部署.这是我在.ebextensions/deploy.config中尝试的内容:

container_commands:
  1_change_permissions:
    command: chmod 700 .ebextensions/setup.sh 
  2_restart_solr:
    command: bash .ebextensions/setup.sh 
Run Code Online (Sandbox Code Playgroud)

这是setup.sh脚本:

#!/bin/bash
chmod 777 -R solr/ log/ tmp/
RAILS_ENV=production rake sunspot:solr:restart
Run Code Online (Sandbox Code Playgroud)

结果是部署没有失败但是,只有权限被正确更改,并且solr服务正在运行,但是当我尝试索引某些东西时,它失败了(查询工作正常).

我还尝试在部署应用程序之前通过在.ebextensions/deploy.config中添加命令块来停止服务器(我更改了我的sh脚本以启动服务而不是重新启动):

commands:
  1_stop_solr:
    command: cd /var/app/current & RAILS_ENV=production rake sunspot:solr:stop
Run Code Online (Sandbox Code Playgroud)

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

[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
Run Code Online (Sandbox Code Playgroud)

**编辑2:**

詹姆斯的回答并没有解决问题,但我意识到在我的EC2实例上手动操作,我可以运行以下两行:

chmod 777 -R solr/ tmp/ log/
RAILS_ENV=production rake sunspot:reindex"
Run Code Online (Sandbox Code Playgroud)

我尝试使用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)>'
Run Code Online (Sandbox Code Playgroud)

此外,如果我尝试手动运行该命令(在部署后脚本chmod之后),它将失败并在每个项目上重新索引500个错误.所以我需要杀死solr服务器,启动然后重新索引.

这真的很痛苦:)

Jam*_*son 1

我对 Beanstalk 一无所知,但看起来执行命令的 shell 没有您期望的环境变量。假设这篇关于部署后脚本的博客文章是正确的,您应该能够将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
Run Code Online (Sandbox Code Playgroud)