如何删除缓存文件?我在AWS Elastic Beanstalk中运行Opencart。
当它扩展到很少的实例时,我不知道如何删除所有缓存,除非我必须ssh进入内部。
答案 0 :(得分:1)
您可以使用.ebextensions
设置cron和干净脚本。
我们为我们的crons使用Sidekiq(我们是一家红宝石店)。这是我们的.ebextensions/sidekiq.conf
"/opt/elasticbeanstalk/hooks/appdeploy/pre/04_stop_sidekiq":
mode: "000777"
owner: root
group: root
content: |
#!/bin/sh
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
source $EB_SUPPORT_DIR/envvars
source $EB_SCRIPT_DIR/use-app-ruby.sh
if [ -f /var/app/support/pids/sidekiq.pid ]; then
pid=$(cat /var/app/support/pids/sidekiq.pid)
echo "sending 'USR1' to pid $pid"
kill -USR1 $pid || :
rm -rf /var/app/support/pids/sidekiq.pid
sleep 30
kill -9 $pid || :
fi
"/opt/elasticbeanstalk/hooks/appdeploy/post/50_restart_sidekiq":
mode: "000777"
owner: root
group: root
content: |
#!/bin/sh
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
source $EB_SUPPORT_DIR/envvars
source $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.
cd $EB_APP_CURRENT_DIR
if [ -f /var/app/support/pids/sidekiq.pid ]; then
pid=$(cat /var/app/support/pids/sidekiq.pid)
echo "Force Killing pid $pid"
kill -USR1 $pid || :
rm -rf /var/app/support/pids/sidekiq.pid
sleep 30
kill -9 $pid || :
fi
sleep 10
su -s /bin/bash -c "bundle exec sidekiq -C /var/app/current/config/sidekiq.yml" $EB_APP_USER
echo "done running sidekiq as daemon"