Reputation: 2210
I am trying to integrate whenever gem into my elasticbeanstalk amazon linux 1 but in my schedule.rb, it throws out a permission denied error when trying to create my output error file.
This is my schedule.rb
require 'dotenv/load'
set :job_template, "TZ=\"Asia/Kuala_Lumpur\" bash -c ':job'"
env :PATH, ENV['PATH']
every 1.minute do
if (ENV['RAILS_APP_TYPE'] == "single") && (ENV['RACK_ENV'] == 'develop')
rake 'sidekiq:send_alert', :output => {:error => "log/sidekiq_check_error.log", :standard => "log/sidekiq_check.log"}
end
end
and this is my .ebextensions/whenever.config
commands:
create_post_dir:
command: "mkdir /opt/elasticbeanstalk/hooks/appdeploy/post"
ignoreErrors: true
files:
"/opt/elasticbeanstalk/hooks/appdeploy/post/update_cron_tab.sh":
mode: "000755"
content: |
#!/bin/sh
RAILS_APP_TYPE=$(/opt/elasticbeanstalk/bin/get-config environment -k RAILS_APP_TYPE)
RACK_ENV=$(/opt/elasticbeanstalk/bin/get-config environment -k RACK_ENV)
echo "WHENEVER GEM CRON"
echo "$RACK_ENV"
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_CURRENT_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k app_deploy_dir)
EB_CONFIG_APP_LOGS=$(/opt/elasticbeanstalk/bin/get-config container -k app_log_dir)
echo "$EB_CONFIG_APP_LOGS"
touch "$EB_APP_CURRENT_DIR/log/sidekiq_check.log"
touch "$EB_APP_CURRENT_DIR/log/sidekiq_check_error.log"
sudo chown webapp:webapp "$EB_APP_CURRENT_DIR/log/sidekiq_check.log"
sudo chown webapp:webapp "$EB_APP_CURRENT_DIR/log/sidekiq_check_error.log"
. $EB_SUPPORT_DIR/envvars
. $EB_SCRIPT_DIR/use-app-ruby.sh
echo '* * * * * TZ="Asia/Kuala_Lumpur" bash -c 'cd $EB_APP_CURRENT_DIR && RAILS_ENV=$RACK_ENV' bundle exec rake sidekiq:send_alert --silent >> $EB_APP_CURRENT_DIR/log/sidekiq_check.log 2>> $EB_APP_CURRENT_DIR/log/sidekiq_check_error.log'
sudo su - webapp -c "cd $EB_APP_CURRENT_DIR; whenever --update-crontab --set environment='$RACK_ENV'"
sudo su - webapp -c "crontab -l"
Whenever this gets deployed, I end up getting an error in my /var/spool/mail/ec2-user
file that says permission denied log/sidekiq_check.log
Is there a reason why I get this error? And how can I fix it?
Upvotes: 0
Views: 634