Eva*_*son 4 ruby-on-rails amazon-web-services whenever ruby-on-rails-4 amazon-elastic-beanstalk
我有一个使用Ruby 2.2的Rails 4.2.1应用程序.我正在尝试使用Whenever Gem从我的代码库更新我的Elastic Beanstalk上的cron任务.我已经从AWS中获取了一些资源,您可以在其中添加文件到.ebextensions文件夹,并通过shell文件使用EB的后部署钩子.这里有几个资源:
在博客文章之后,我添加了下面的文件,取消注释了gitignore关于文件.ebextensions夹中文件的行,并部署了我的应用程序.不幸的是,我已经看到了任何变化.我检查了日志文件(log/eb-tools.log,log/cron等),并为我创建的shell文件的grepped所有日志文件,等等.虽然没有运气.
commands:
create-post-dir:
command: "mkdir /opt/elasticbeanstalk/hooks/appdeploy/post"
ignoreErrors: true
files:
"/opt/elasticbeanstalk/hooks/appdeploy/post/99_update_cron.sh"
mode: "000755"
owner: root
group: root
content: |
#!/usr/bin/env bash
# Using similar syntax as the appdeploy pre hooks that is managed by AWS
# Loading environment data
EB_SCRIPT_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k script_dir)
EB_SUPPORT_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k support_dir)
EB_APP_USER=$(/opt/elasticbeanstalk/bin/get-config container -k app_user)
EB_APP_CURRENT_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k app_deploy_dir)
EB_APP_PIDS_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k app_pid_dir)
# Setting up correct environment and ruby version so that bundle can load all gems
. $EB_SUPPORT_DIR/envvars
. $EB_SCRIPT_DIR/use-app-ruby.sh
# Now we can do the actual restart of the worker. Make sure to have double quotes when using env vars in the command.
su -c "cd $EB_APP_CURRENT_DIR; bundle exec whenever --update-cron --set='environment=$RACK_ENV'" - $EB_APP_USER
Run Code Online (Sandbox Code Playgroud)
如何确保调用此shell文件?我可以在没有新部署的情况下进行测试吗?此外,如果Whenever宝石不是最好的选择,我会对其他选项持开放态度.我主要希望能够在代码和版本控制下管理我的cron任务.
提前致谢!
更新:
.ebextensions文件夹上有一个类型,导致它不被添加.在修复之后,我能够读取错误消息,并创建一个使用Whenever gem更新crontab的cron脚本.在修复了我的.ebextensions文件夹名称中的拼写错误后,我能够解决这个问题.然后,编译脚本,并开始显示日志消息.阅读完日志消息后,我想出了以下配置脚本(.ebextensions/01_cron.config):
files:
"/opt/elasticbeanstalk/hooks/appdeploy/post/01_cron.sh":
mode: "000755"
owner: root
group: root
content: |
#!/usr/bin/env bash
# Using similar syntax as the appdeploy pre hooks that is managed by AWS
set -xe
EB_SCRIPT_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k script_dir)
EB_SUPPORT_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k support_dir)
EB_DEPLOY_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k app_deploy_dir)
. $EB_SUPPORT_DIR/envvars
. $EB_SCRIPT_DIR/use-app-ruby.sh
cd $EB_DEPLOY_DIR
su -c "bundle exec whenever --update-cron"
su -c "crontab -l"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1040 次 |
| 最近记录: |