5

我在Elastic Beanstalk上运行delayed_jobs时遇到问题。我正在使用运行Ruby 2.1(Passenger Standalone)容器的64位Amazon Linux 2014.03 v1.0.0的容器。如何在Elastic Beanstalk上设置delayed_job时修复'require'错误

这是我的配置脚本(delayed_job.config)...

files: 
    "/opt/elasticbeanstalk/hooks/appdeploy/post/99_restart_delayed_job.sh": 
    mode: "000755" 
    owner: root 
    group: root 
    encoding: plain 
    content: | 
     #!/usr/bin/env bash 
     . /opt/elasticbeanstalk/support/envvars 
     cd $EB_CONFIG_APP_CURRENT 
     su -c "RAILS_ENV=production bin/delayed_job --pid-dir=$EB_CONFIG_APP_SUPPORT/pids restart" $EB_CONFIG_APP_USER 

99_restart_delayed_job.sh脚本存在和运行......但后来我跌入这个错误。

2014-10-02 15:28:32,332 [INFO] (17387 MainThread) [directoryHooksExecutor.py-29] [root directoryHooksExecutor info] Script succeeded. 
2014-10-02 15:28:32,402 [INFO] (17448 MainThread) [directoryHooksExecutor.py-29] [root directoryHooksExecutor info] Executing directory: /opt/elasticbeanstalk/hooks/appdeploy/post/ 
2014-10-02 15:28:32,402 [INFO] (17448 MainThread) [directoryHooksExecutor.py-29] [root directoryHooksExecutor info] Executing script: /opt/elasticbeanstalk/hooks/appdeploy/post/99_restart_delayed_job.sh 
/usr/share/ruby/vendor_ruby/2.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- bundler/setup (LoadError) 
    from /usr/share/ruby/vendor_ruby/2.0/rubygems/core_ext/kernel_require.rb:55:in `require' 
    from /var/app/current/config/boot.rb:4:in `<top (required)>' 
    from /usr/share/ruby/vendor_ruby/2.0/rubygems/core_ext/kernel_require.rb:55:in `require' 
    from /usr/share/ruby/vendor_ruby/2.0/rubygems/core_ext/kernel_require.rb:55:in `require' 
    from /var/app/current/config/application.rb:1:in `<top (required)>' 
    from /usr/share/ruby/vendor_ruby/2.0/rubygems/core_ext/kernel_require.rb:55:in `require' 
    from /usr/share/ruby/vendor_ruby/2.0/rubygems/core_ext/kernel_require.rb:55:in `require' 
    from /var/app/current/config/environment.rb:2:in `<top (required)>' 
    from /usr/share/ruby/vendor_ruby/2.0/rubygems/core_ext/kernel_require.rb:55:in `require' 
    from /usr/share/ruby/vendor_ruby/2.0/rubygems/core_ext/kernel_require.rb:55:in `require' 
    from bin/delayed_job:3:in `<main>' 

2014-10-02 15:28:32,440 [ERROR] (17448 MainThread) [directoryHooksExecutor.py-33] [root directoryHooksExecutor error] Script /opt/elasticbeanstalk/hooks/appdeploy/post/99_restart_delayed_job.sh failed with returncode 1 

我已经倾注了this other thread on SO,告诉我如何设置。我的问题是,我不知道什么阻止脚本无误地运行。

如果我SSH到EC2实例,我能够运行没有错误此...

RAILS_ENV=production bin/delayed_job --pid-dir=$EB_CONFIG_APP_SUPPORT/pids restart 

虽然这要求我输入密码...

su -c "RAILS_ENV=production bin/delayed_job --pid-dir=$EB_CONFIG_APP_SUPPORT/pids restart" $EB_CONFIG_APP_USER 

我哪通过这样做避免...

sudo su -c "RAILS_ENV=production bin/delayed_job --pid-dir=$EB_CONFIG_APP_SUPPORT/pids restart" $EB_CONFIG_APP_USER 

参见:'How to automatically restart delayed_job when deploying a rails project on Amazon Elastic Beanstalk?'

更新1:2014年10月15日

与传递,我得到这个错误目录的变化赋予了-l选项后...

2014-10-15 06:17:28,673 [INFO] (4417 MainThread) [directoryHooksExecutor.py-29] [root directoryHooksExecutor info] Executing script: /opt/elasticbeanstalk/hooks/appdeploy/post/99_restart_delayed_job.sh 
2014-10-15 06:17:30,374 [INFO] (4417 MainThread) [directoryHooksExecutor.py-29] [root directoryHooksExecutor info] Output from script: /opt/rubies/ruby-2.1.2/lib/ruby/gems/2.1.0/gems/daemons-1.1.9/lib/daemons/application.rb:393:in `kill': Operation not permitted (Errno::EPERM) 
    from /opt/rubies/ruby-2.1.2/lib/ruby/gems/2.1.0/gems/daemons-1.1.9/lib/daemons/application.rb:393:in `stop' 
    from /opt/rubies/ruby-2.1.2/lib/ruby/gems/2.1.0/gems/daemons-1.1.9/lib/daemons/application_group.rb:171:in `block (2 levels) in stop_all' 

2014-10-15 06:17:30,374 [ERROR] (4417 MainThread) [directoryHooksExecutor.py-33] [root directoryHooksExecutor error] Script /opt/elasticbeanstalk/hooks/appdeploy/post/99_restart_delayed_job.sh failed with returncode 1 

更新2:2014- 10-15

发现上面的错误是由root创建的现有pid导致的(在调试时我手动启动了delayed_job),所以c2用户无法重新启动/终止它,从而导致错误。

回答

1

从我所知道的问题来看,当切换到linux用户时,环境/路径变量未建立。我做了三个转变:

  1. -l选项添加到su命令模拟的$EB_CONFIG_APP_USER一个完整的登录。
  2. 作为-l选项的副作用,change directory命令必须带入-c选项。
  3. 作为一个很好的措施,但可能没有必要,包括bundle exec以确保使用正确的宝石。

这里是我的功能content:面积:

#!/usr/bin/env bash 
. /opt/elasticbeanstalk/support/envvars 
su -l -c "cd $EB_CONFIG_APP_CURRENT && RAILS_ENV=production bundle exec bin/delayed_job --pid-dir=$EB_CONFIG_APP_SUPPORT/pids restart" $EB_CONFIG_APP_USER 
+0

我申请更改建议,并得到了新的错误(见更新的问题),但是,是的,你的建议是有道理的。这当然指向了正确的方向,所以我必须通过SSH进入我的实例,然后手动完成,直到出现问题。将更新进度。 – 2014-10-15 06:27:28

+1

您的错误似乎表明'$ EB_CONFIG_APP_USER'没有权限停止正在运行的进程。确保'bin/delayed_job'没有以前面的故障排除步骤的root身份在后台运行。同时验证'bin/delayed_job'的文件权限。 – 2014-10-15 15:59:30

+1

显然环境变量随着下一个Beanstalk(2014.09)而消失。 [此AWS论坛主题]的解决方法(https://forums.aws.amazon.com/thread.jspa?messageID=602937)。有关[本答案](http://stackoverflow.com/a/28506920/550712)和[本博客文章](http://www.dannemanne.com/posts/post-deployment_script_on_elastic_beanstalk_restart_delayed_job)中新方法的delayed_job详细信息, 。 – 2015-02-19 02:03:45

相关问题