Skip to content

Instantly share code, notes, and snippets.

@hiattp
Last active March 6, 2020 09:14
Show Gist options
  • Save hiattp/f2b8eca4a160c5f266e3 to your computer and use it in GitHub Desktop.
Save hiattp/f2b8eca4a160c5f266e3 to your computer and use it in GitHub Desktop.
Sidekiq Config for Elastic Beanstalk
# Sidekiq interaction and startup script
files:
"/opt/elasticbeanstalk/hooks/appdeploy/post/50_restart_sidekiq.sh":
mode: "000755"
content: |
#!/bin/bash
. /opt/elasticbeanstalk/hooks/common.sh
. /opt/elasticbeanstalk/support/envvars
set -xe
EB_SCRIPT_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k script_dir)
EB_CONFIG_APP_CURRENT=$(/opt/elasticbeanstalk/bin/get-config container -k app_deploy_dir)
EB_CONFIG_APP_LOGS=$(/opt/elasticbeanstalk/bin/get-config container -k app_log_dir)
EB_CONFIG_APP_PIDS=$(/opt/elasticbeanstalk/bin/get-config container -k app_pid_dir)
. $EB_SCRIPT_DIR/use-app-ruby.sh
BUNDLE=`which bundle`
SIDEKIQ=`which sidekiq`
cd $EB_CONFIG_APP_CURRENT
# For 2 instances of Sidekiq this can be increased or decreased,
# just make sure it is updated here and below. Also, if decreasing
# these values, be sure to terminate processes at previously available
# indices (e.g. kill sidekiq-3.pid if going from 3 to 2 processes).
# for i in `seq 1 2`
for i in `seq 1`
do
PIDFILE=$EB_CONFIG_APP_PIDS/sidekiq-$i.pid
# Stop current Sidekiq processes
if [ -f $PIDFILE ]
then
SIDEKIQ_LIVES=$(/bin/ps -o pid= -p `cat $PIDFILE`)
if [ -z $SIDEKIQ_LIVES ]
then
rm -rf $PIDFILE
else
kill -TERM `cat $PIDFILE`
fi
fi
# Boot Sidekiq process
$BUNDLE exec $SIDEKIQ \
-e production \
-P $PIDFILE \
-C $EB_CONFIG_APP_CURRENT/config/sidekiq.yml \
-L $EB_CONFIG_APP_LOGS/sidekiq.log \
-d
done
"/opt/elasticbeanstalk/hooks/appdeploy/pre/03_quiet_sidekiq.sh":
mode: "000755"
content: |
#!/bin/bash
. /opt/elasticbeanstalk/support/envvars
EB_CONFIG_APP_PIDS=$(/opt/elasticbeanstalk/bin/get-config container -k app_pid_dir)
# For 2 instances of Sidekiq this can be increased or decreased,
# just make sure it is updated here and below.
# for i in `seq 1 2`
for i in `seq 1`
do
PIDFILE=$EB_CONFIG_APP_PIDS/sidekiq-$i.pid
# quiet any running instance
if [ -f $PIDFILE ]
then
SIDEKIQ_LIVES=$(/bin/ps -o pid= -p `cat $PIDFILE`)
if [ -z $SIDEKIQ_LIVES ]
then
rm -rf $PIDFILE
else
kill -USR1 `cat $PIDFILE`
fi
fi
done
@degendra
Copy link

degendra commented Mar 6, 2020

Sidekiq 5.0+
Note: The quiet signal used to be USR1 but was changed to TSTP in Sidekiq 5.0.
TSTP should be used instead of "USR1" on L79

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