[英]AWS Elastic Beanstalk and Whenever Gem
我有一個使用Ruby 2.2的Rails 4.2.1應用程序。 我正在嘗試使用Whenever Gem從我的代碼庫更新我的Elastic Beanstalk上的cron任務。 我已經從AWS中獲取了一些資源,您可以在其中將文件添加到.ebextensions
文件夾,並通過shell文件使用EB的部署后部署鈎子。 這里有幾個資源:
在博客文章之后,我添加了下面的文件,取消注釋了關於.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"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.