Apologies if this is a duplicate - there are a few results with similar questions but most of the answers are quite dated and I am having trouble getting it to work.
I am using the whenever gem to run a single task every hour in my rails app but I can't seem to get AWS to configure the Cron settings right.
My first thought was to SSH into the instance and run the whenever update /write command which went through fine but my task didn't run.
After reviewing the old questions on here I created a an ebextensions folder with a config file to run the update command but still no joy. I used this config script but don't really understand it so I assume I have not set it up right - can someone please assist?
files:
"/opt/elasticbeanstalk/hooks/appdeploy/post/99_update_cron.sh"
mode: "000755"
owner: root
group: root
content: |
#! /usr/bin/env bash
. /opt/elasticbeanstalk/containerfiles/envvars
su -c "cd $EB_CONFIG_APP_CURRENT; bundle exec whenever --update-cron"
- $EB_CONFIG_APP_USER
EDIT Added Logs
2018-01-09T23:24:45.282Z] INFO [1641] - [Application update app-5c64-
180109_162309@15/AppDeployStage1/AppDeployPostHook] : Starting activity...
[2018-01-09T23:24:45.282Z] INFO [1641] - [Application update app-5c64-
180109_162309@15/AppDeployStage1/AppDeployPostHook/01_cron.sh] : Starting
activity...
[2018-01-09T23:24:46.618Z] INFO [1641] - [Application update app-5c64-
180109_162309@15/AppDeployStage1/AppDeployPostHook/01_cron.sh] : Completed
activity. Result:
[write] crontab file updated
[2018-01-09T23:24:46.618Z] INFO [1641] - [Application update app-5c64-
180109_162309@15/AppDeployStage1/AppDeployPostHook] : Completed activity.
Result:
Successfully execute hooks in directory
/opt/elasticbeanstalk/hooks/appdeploy/post.
[2018-01-09T23:24:46.618Z] INFO [1641] - [Application update app-5c64-
180109_162309@15/AppDeployStage1] : Completed activity. Result:
Application version switch - Command CMD-AppDeploy stage 1 completed
[2018-01-09T23:24:46.618Z] INFO [1641] - [Application update app-5c64-
180109_162309@15/AddonsAfter] : Starting activity...
[2018-01-09T23:24:46.618Z] INFO [1641] - [Application update app-5c64-
180109_162309@15/AddonsAfter/ConfigLogRotation] : Starting activity...
[2018-01-09T23:24:46.618Z] INFO [1641] - [Application update app-5c64-
180109_162309@15/AddonsAfter/ConfigLogRotation/10-config.sh] : Starting
activity...
[2018-01-09T23:24:46.778Z] INFO [1641] - [Application update app-5c64-
180109_162309@15/AddonsAfter/ConfigLogRotation/10-config.sh] : Completed
activity. Result:
Disabled forced hourly log rotation.
[2018-01-09T23:24:46.779Z] INFO [1641] - [Application update app-5c64-
180109_162309@15/AddonsAfter/ConfigLogRotation] : Completed activity.
Result:
Successfully execute hooks in directory
/opt/elasticbeanstalk/addons/logpublish/hooks/config.
[2018-01-09T23:24:46.779Z] INFO [1641] - [Application update app-5c64-
180109_162309@15/AddonsAfter] : Completed activity.
[2018-01-09T23:24:46.779Z] INFO [1641] - [Application update app-5c64-
EDIT 2 my new config code that now forms the following errors:
commands:
70.1-create-post-dir:
# "mkdir -p" ignores error if directory already exists
command: "mkdir -p /opt/elasticbeanstalk/hooks/appdeploy/post"
files:
"/opt/elasticbeanstalk/hooks/appdeploy/post/01_cron.sh":
mode: "000755"
owner: root
group: root
content: |
#!/usr/bin/env bash
# Load 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_DEPLOY_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k app_deploy_dir)
# Export EB_APP_LOG_DIR so we can access it when running "whenever" below,
# which accesses config/schedule.rb, which uses EB_APP_LOG_DIR.
export EB_APP_LOG_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k app_log_dir)
# Make sure the cron-whenever.log exists and is owned by $EB_APP_USER
touch $EB_APP_LOG_DIR/cron-whenever.log
chown $EB_APP_USER:$EB_APP_USER $EB_APP_LOG_DIR/cron-whenever.log
# cron requires a home directory. Make sure it exists and is owned by $EB_APP_USER.
mkdir -p /home/$EB_APP_USER
chown $EB_APP_USER:$EB_APP_USER /home/$EB_APP_USER
# Set up correct environment and ruby version so that bundle can load all gems
. $EB_SUPPORT_DIR/envvars
. $EB_SCRIPT_DIR/use-app-ruby.sh
# Run the whenever --update command to update the cron job for $EB_APP_USER.
cd $EB_APP_DEPLOY_DIR
whenever --update -u $EB_APP_USER
# After setup, you can run "crontab -l -u webapp" to check the configuration.