Kin*_*ina 5 deployment ruby-on-rails amazon-web-services delayed-job amazon-elastic-beanstalk
我无法在Elastic Beanstalk上运行delayed_jobs.我正在使用运行Ruby 2.1(Passenger Standalone)容器的64位Amazon Linux 2014.03 v1.0.0.
这是我的配置脚本(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
Run Code Online (Sandbox Code Playgroud)
该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
Run Code Online (Sandbox Code Playgroud)
我已经通过SO上的其他帖子倾注了我,告诉我如何设置.我的问题是我不知道是什么阻止脚本无错误地运行.
如果我通过SSH连接到EC2实例,我可以毫无错误地运行它...
RAILS_ENV=production bin/delayed_job --pid-dir=$EB_CONFIG_APP_SUPPORT/pids restart
Run Code Online (Sandbox Code Playgroud)
虽然这要求我输入密码......
su -c "RAILS_ENV=production bin/delayed_job --pid-dir=$EB_CONFIG_APP_SUPPORT/pids restart" $EB_CONFIG_APP_USER
Run Code Online (Sandbox Code Playgroud)
这样做我可以避免...
sudo su -c "RAILS_ENV=production bin/delayed_job --pid-dir=$EB_CONFIG_APP_SUPPORT/pids restart" $EB_CONFIG_APP_USER
Run Code Online (Sandbox Code Playgroud)
请参阅:'如何在Amazon Elastic Beanstalk上部署rails项目时自动重启delayed_job?'
更新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
Run Code Online (Sandbox Code Playgroud)
更新2:2014-10-15
原来上面的错误是由root创建的现有pid引起的(在调试时我手动启动了delayed_job)所以c2用户无法重启/杀死它因此错误.
据我所知,问题在于切换到 linux 用户时没有建立环境/路径变量$EB_CONFIG_APP_USER。我做了三个改变:
-l在命令中添加选项su以模拟$EB_CONFIG_APP_USER.-l,必须将更改目录命令带入该-c选项。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
Run Code Online (Sandbox Code Playgroud)