AWS elastic bean stock and whenever a gem

I have a Rails 4.2.1 application using Ruby 2.2. I try to use Whenever Gem updates cron tasks on my Elastic Beanstalk from my code base. I followed several resources from AWS where you can add files to a folder .ebextensionsand use the DB2 deployment hook through shell files. Here are some resources:

After the blog articles, I added the file below, uncommented the gitignore line about the files in the folder, .ebextensionsand deployed my application. Unfortunatley, I was able to see any changes. I checked the log files ( log/eb-tools.log, log/cronetc.) and grepped all the log files for the shell file that I create, each time, etc. No luck though.

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

How can I make sure this shell file is called? Can I test it without a new deployment every time? In addition, I am open to other options if every time a gem is not the best option. Basically, I want my cron tasks to be managed in code and under version control.

Thanks in advance!

UPDATE:

  • .ebextensions, - . cron script, crontab, Whenever.
+4
1

.ebextensions. , . script (.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"
+6

All Articles