Last active
June 24, 2020 09:00
-
-
Save deekshithh/00b1e44e73d3eefea1e39eed85ab6c18 to your computer and use it in GitHub Desktop.
Using whenever ruby gem in aws elastic beanstalk. It runs only on production env leader node.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commands: | |
01_remove_old_cron_jobs: | |
command: "crontab -r || exit 0" | |
01_remove_old_cron_job_creator: | |
command: "rm -f /opt/elasticbeanstalk/hooks/appdeploy/post/99_cron_job.sh" | |
files: | |
"/var/tmp/99_cron_job.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_ENV_NAME=$(/opt/elasticbeanstalk/bin/get-config container -k environment_name) | |
if [[ $EB_ENV_NAME == 'Your-production' ]] | |
then | |
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-crontab --set 'environment=$RAILS_ENV'" | |
fi | |
container_commands: | |
enable_cron: | |
command: "cp /var/tmp/99_cron_job.sh /opt/elasticbeanstalk/hooks/appdeploy/post/99_cron_job.sh" | |
leader_only: true | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment