ruby-on-rails – AWS Elastic Beanstalk和Whenever Gem
我有一个使用
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 在博客文章之后,我添加了下面的文件,取消注释了关于.ebextensions文件夹中文件的gitignore行,并部署了我的应用程序.不幸的是,我已经看到了任何变化.我检查了日志文件(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 如何确保调用此shell文件?我可以在没有新部署的情况下进行测试吗?此外,如果Whenever gem不是最佳选择,我会对其他选项持开放态度.我主要希望能够在代码和版本控制下管理我的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" (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |