Skip to content

Instantly share code, notes, and snippets.

@kitwalker12
Last active November 27, 2017 21:24
Show Gist options
  • Select an option

  • Save kitwalker12/0313e0edd66e5bfa7aed78f6890fab9d to your computer and use it in GitHub Desktop.

Select an option

Save kitwalker12/0313e0edd66e5bfa7aed78f6890fab9d to your computer and use it in GitHub Desktop.
Sneakers and Sidekiq Configuration on AWS Beanstalk
packages:
yum:
git: []
option_settings:
aws:elasticbeanstalk:application:environment:
BUNDLE_WITHOUT: test:development
files:
"/opt/elasticbeanstalk/support/conf/sidekiq.conf":
mode: "000755"
content: |
description "Elastic Beanstalk Sidekiq Upstart Manager"
start on runlevel [2345]
stop on runlevel [06]
# 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
su -s /bin/bash -c "bundle exec sidekiq -L ${EB_APP_DEPLOY_DIR}/log/sidekiq.log -P ${EB_APP_PID_DIR}/sidekiq.pid"
EOT
end script
files:
"/opt/elasticbeanstalk/support/conf/sneakers.conf":
mode: "000755"
content: |
description "Elastic Beanstalk Sneakers Upstart Manager"
start on runlevel [2345]
stop on runlevel [06]
respawn
respawn limit 3 30
# TERM is sent by sneakers when stopping sidekiq. Without declaring these as normal exit codes, it just respawns.
normal exit 0 TERM
script
# scripts run in /bin/sh by default
# respawn as bash so we can source in rbenv
exec /bin/bash <<"EOT"
EB_APP_USER=$(/opt/elasticbeanstalk/bin/get-config container -k app_user)
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)
cd $EB_APP_DEPLOY_DIR
exec su -s /bin/bash -c "bundle exec rake sneakers:run >> $EB_APP_DEPLOY_DIR/log/sneakers.log 2>&1" $EB_APP_USER
EOT
end script
files:
"/opt/elasticbeanstalk/hooks/appdeploy/pre/03_mute_sidekiq.sh":
mode: "000755"
content: |
#!/bin/bash
. /opt/elasticbeanstalk/support/envvars
PIDFILE=/var/app/support/pids/sidekiq.pid
if [ -f ${PIDFILE} ]
then
kill -USR1 `cat ${PIDFILE}`
rm -rf /var/app/support/pids/sidekiq.pid
fi
"/opt/elasticbeanstalk/hooks/appdeploy/post/50_restart_sidekiq.sh":
mode: "000755"
content: |
#!/bin/bash
initctl restart sidekiq || initctl start sidekiq
"/opt/elasticbeanstalk/hooks/configdeploy/pre/03_mute_sidekiq.sh":
mode: "000755"
content: |
#!/bin/bash
. /opt/elasticbeanstalk/support/envvars
PIDFILE=/var/app/support/pids/sidekiq.pid
if [ -f ${PIDFILE} ]
then
kill -USR1 `cat ${PIDFILE}`
rm -rf /var/app/support/pids/sidekiq.pid
fi
"/opt/elasticbeanstalk/hooks/configdeploy/post/50_restart_sidekiq.sh":
mode: "000755"
content: |
#!/bin/bash
initctl restart sidekiq || initctl start sidekiq
"/opt/elasticbeanstalk/hooks/restartappserver/pre/03_mute_sidekiq.sh":
mode: "000755"
content: |
#!/bin/bash
. /opt/elasticbeanstalk/support/envvars
PIDFILE=/var/app/support/pids/sidekiq.pid
if [ -f ${PIDFILE} ]
then
kill -USR1 `cat ${PIDFILE}`
rm -rf /var/app/support/pids/sidekiq.pid
fi
"/opt/elasticbeanstalk/hooks/restartappserver/post/50_restart_sidekiq.sh":
mode: "000755"
content: |
#!/bin/bash
initctl restart sidekiq || initctl start sidekiq
files:
"/opt/elasticbeanstalk/hooks/appdeploy/pre/04_mute_sneakers.sh":
mode: "000755"
content: |
#!/bin/bash
initctl stop sneakers
kill $(ps aux | grep '[/]opt/rubies/ruby-2.0.0-p648/bin/rake' | awk '{print $2}')
"/opt/elasticbeanstalk/hooks/appdeploy/post/51_restart_sneakers.sh":
mode: "000755"
content: |
#!/bin/bash
initctl restart sneakers || initctl start sneakers
"/opt/elasticbeanstalk/hooks/configdeploy/pre/04_mute_sneakers.sh":
mode: "000755"
content: |
#!/bin/bash
initctl stop sneakers
kill $(ps aux | grep '[/]opt/rubies/ruby-2.0.0-p648/bin/rake' | awk '{print $2}')
"/opt/elasticbeanstalk/hooks/configdeploy/post/51_restart_sneakers.sh":
mode: "000755"
content: |
#!/bin/bash
initctl restart sneakers || initctl start sneakers
"/opt/elasticbeanstalk/hooks/restartappserver/pre/04_mute_sneakers.sh":
mode: "000755"
content: |
#!/bin/bash
initctl stop sneakers
kill $(ps aux | grep '[/]opt/rubies/ruby-2.0.0-p648/bin/rake' | awk '{print $2}')
"/opt/elasticbeanstalk/hooks/restartappserver/post/51_restart_sneakers.sh":
mode: "000755"
content: |
#!/bin/bash
initctl restart sneakers || initctl start sneakers
files:
"/etc/init/sidekiq.conf":
mode: "120400"
content: "/opt/elasticbeanstalk/support/conf/sidekiq.conf"
"/etc/init/sneakers.conf":
mode: "120400"
content: "/opt/elasticbeanstalk/support/conf/sneakers.conf"
commands:
reload_initctl_for_sidekiq_and_sneakers:
command: "initctl reload-configuration"
@kitwalker12

Copy link
Copy Markdown
Author

Updated sneakers hooks to kill orphaned processes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment