Skip to content

Instantly share code, notes, and snippets.

@eccyan
Last active August 19, 2019 20:26
Show Gist options
  • Save eccyan/4849bf9037a081d9b55313892737e03e to your computer and use it in GitHub Desktop.
Save eccyan/4849bf9037a081d9b55313892737e03e to your computer and use it in GitHub Desktop.
Sidekiq on AWS Elastic Beanstalk (upstart v0.6.5)
# See: https://medium.com/@hugooodias/deploying-a-rails-app-to-amazon-elasticbeanstalk-in-2016-c4e833c687c0
files:
"/opt/elasticbeanstalk/hooks/appdeploy/post/50_restart_sidekiq":
mode: "000755"
content: |
#!/bin/bash
EB_CONFIG_DEPLOY=$(/opt/elasticbeanstalk/bin/get-config container -k app_deploy_dir)
EB_CONFIG_APP_LOG=$(/opt/elasticbeanstalk/bin/get-config container -k app_log_dir)
initctl stop sidekiq
initctl start sidekiq
ln -sf $EB_CONFIG_DEPLOY/log/sidekiq.log $EB_CONFIG_APP_LOG/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: |
# NOTE: for upstart v0.6.5, reload signal is not implemented yet
description "Elastic Beanstalk Sidekiq Upstart Manager"
start on runlevel [2345]
stop on runlevel [06]
respawn
respawn limit 3 60
normal exit 0 TERM
kill timeout 40
# send USR1 signal before stop
pre-stop script
EB_APP_PID_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k app_pid_dir)
kill -USR1 `cat ${EB_APP_PID_DIR}/sidekiq.pid`
sleep 20
end script
script
# scripts run in /bin/sh by default
# respawn as bash so we can source in rbenv
exec /bin/bash -e <<"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
bundle exec sidekiq -e ${RACK_ENV} \
-L ${EB_APP_DEPLOY_DIR}/log/sidekiq.log \
-C ${EB_APP_DEPLOY_DIR}/config/sidekiq.yml \
-P ${EB_APP_PID_DIR}/sidekiq.pid
EOT
end script
files:
"/etc/init/sidekiq.conf":
mode: "120400"
content: "/opt/elasticbeanstalk/support/conf/sidekiq.conf"
commands:
reload_initctl_for_sidekiq:
command: "initctl reload-configuration"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment