From da1a143304380f82f7acb95da24687e93d74f29a Mon Sep 17 00:00:00 2001 From: David Wilkie Date: Sat, 27 Jun 2015 11:35:44 +0700 Subject: [PATCH] Setup deployment of sidekiq for worker process on Elastic Beanstalk. #183 --- .../{packages.config => 00_packages.config} | 0 .ebextensions/15_sidekiq_initialize.config | 53 +++++++++++++++++++ .ebextensions/16_sidekiq_setup.config | 9 ++++ 3 files changed, 62 insertions(+) rename .ebextensions/{packages.config => 00_packages.config} (100%) create mode 100644 .ebextensions/15_sidekiq_initialize.config create mode 100644 .ebextensions/16_sidekiq_setup.config diff --git a/.ebextensions/packages.config b/.ebextensions/00_packages.config similarity index 100% rename from .ebextensions/packages.config rename to .ebextensions/00_packages.config diff --git a/.ebextensions/15_sidekiq_initialize.config b/.ebextensions/15_sidekiq_initialize.config new file mode 100644 index 0000000..b7b5c63 --- /dev/null +++ b/.ebextensions/15_sidekiq_initialize.config @@ -0,0 +1,53 @@ +--- +files: + "/opt/elasticbeanstalk/hooks/appdeploy/post/50_restart_sidekiq": + mode: "000755" + content: | + #!/bin/bash + initctl restart sidekiq || initctl start sidekiq + + ln -sf /var/app/current/log/sidekiq.log /var/app/containerfiles/logs/sidekiq.log + + "/opt/elasticbeanstalk/hooks/appdeploy/pre/03_mute_sidekiq": + mode: "000755" + content: | + #!/bin/bash + + . /opt/elasticbeanstalk/support/envvars + + PIDFILE=/var/app/containerfiles/pids/sidekiq.pid + if [ -f ${PIDFILE} ]; then + if [ -d /proc/`cat ${PIDFILE}` ]; then + kill -USR1 `cat ${PIDFILE}` + fi + fi + + "/opt/elasticbeanstalk/support/conf/sidekiq.conf": + mode: "000644" + content: | + description "Elastic Beanstalk Sidekiq Upstart Manager" + + start on runlevel [2345] + stop on runlevel [!2345] + + # explained above + respawn + respawn limit 3 30 + + script + # scripts run in /bin/sh by default + # respawn as bash so we can source in rbenv + exec /bin/bash <<"EOT" + 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_SUPPORT_DIR/envvars + . $EB_SCRIPT_DIR/use-app-ruby.sh + + EB_APP_DEPLOY_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k app_deploy_dir) + EB_APP_PID_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k app_pid_dir) + cd $EB_APP_DEPLOY_DIR + + exec su -s /bin/bash -c "sidekiq -e ${RACK_ENV} -c ${SIDEKIQ_WORKERS:-2} -L ${EB_APP_DEPLOY_DIR}/log/sidekiq.log -C ${EB_APP_DEPLOY_DIR}/config/sidekiq.yml -P ${EB_APP_PID_DIR}/sidekiq.pid" webapp + EOT + end script diff --git a/.ebextensions/16_sidekiq_setup.config b/.ebextensions/16_sidekiq_setup.config new file mode 100644 index 0000000..56b6276 --- /dev/null +++ b/.ebextensions/16_sidekiq_setup.config @@ -0,0 +1,9 @@ +--- +files: + "/etc/init/sidekiq.conf" : + mode: "120400" + content: "/opt/elasticbeanstalk/support/conf/sidekiq.conf" + +commands: + reload_initctl_for_sidekiq: + command: "initctl reload-configuration"