【发布时间】:2015-07-27 23:26:58
【问题描述】:
我有一个使用 Ruby 2.2 的 Rails 4.2.1 应用程序。我正在尝试使用 Whenever Gem 从我的代码库更新我的 Elastic Beanstalk 上的 cron 任务。我关注了来自 AWS 的一些资源,您可以在其中将文件添加到 .ebextensions 文件夹并通过 shell 文件使用 EB 的部署后挂钩。以下是一些资源:
- https://forums.aws.amazon.com/thread.jspa?threadID=137136
- http://www.dannemanne.com/posts/post-deployment_script_on_elastic_beanstalk_restart_delayed_job
- http://blog.endpoint.com/2015/01/elastic-beanstalk-whenever.html
在博客文章之后,我在下面添加了文件,取消了关于 .ebextensions 文件夹中文件的 gitignore 行的注释,并部署了我的应用程序。不幸的是,我已经能够看到任何变化。我检查了日志文件(log/eb-tools.log、log/cron 等),并为我创建的 shell 文件的所有日志文件、无论何时等等。不过运气不好。
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
如何确保调用此 shell 文件?我可以在每次不进行新部署的情况下对其进行测试吗?此外,如果Whenever gem 不是最佳选择,我愿意接受其他选择。我主要希望能够在代码中和版本控制下管理我的 cron 任务。
提前致谢!
更新:
- 我在
.ebextensions文件夹中有一个类型,导致它没有被添加。修复此问题后,我能够阅读错误消息,并创建一个使用 When gem 更新 crontab 的 cron 脚本。
【问题讨论】:
-
我遇到了这个设置的问题。在部署时我不断收到错误,因为
whenever: command not found。 gem 安装在机器上,当我通过 ssh 登录时,我可以运行whenever。有什么想法吗?
标签: ruby-on-rails ruby-on-rails-4 amazon-web-services amazon-elastic-beanstalk whenever