Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.