-
-
Save vladvinnikov/e6969a536414859157b0 to your computer and use it in GitHub Desktop.
AWS Elastic Beanstalk Ruby 2.2 Puma Sidekiq
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
packages: | |
yum: | |
git: [] | |
htop: [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Modified system bundle script to run 'bundle package' | |
files: | |
"/opt/elasticbeanstalk/hooks/appdeploy/pre/10_bundle_install.sh": | |
content: | | |
#!/usr/bin/env bash | |
. /opt/elasticbeanstalk/hooks/common.sh | |
set -xe | |
EB_SCRIPT_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k script_dir) | |
EB_APP_STAGING_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k app_staging_dir) | |
EB_APP_USER=$(/opt/elasticbeanstalk/bin/get-config container -k app_user) | |
EB_SUPPORT_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k support_dir) | |
. $EB_SUPPORT_DIR/envvars | |
. $EB_SCRIPT_DIR/use-app-ruby.sh | |
cd $EB_APP_STAGING_DIR | |
if [ -f Gemfile ]; then | |
echo "running 'bundle install' with Gemfile:" | |
cat Gemfile | |
if [ -d $EB_CONFIG_APP_ONDECK/vendor/cache ]; then | |
bundle install --local | |
# Incase there is a gem that is missing from the cache | |
bundle pack --all | |
bundle install | |
else | |
bundle pack --all | |
bundle install | |
fi | |
else | |
echo "no Gemfile found! Skipping bundle install stage!" | |
fi | |
if [ -f Gemfile.lock ]; then | |
echo "encountered a Gemfile.lock, setting proper permissions" | |
chown $EB_APP_USER:$EB_APP_USER Gemfile.lock | |
else | |
echo "no Gemfile.lock file found, so no permissions to set on it" | |
fi | |
if [ "$BUNDLE_DISABLE_SHARED_GEMS" = "1" ]; then | |
cd $EB_APP_STAGING_DIR; | |
chown -R $EB_APP_USER:$EB_APP_USER ./$BUNDLE_PATH; | |
echo "Modified the owner of '$BUNDLE_PATH' files"; | |
fi | |
mode: "000755" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 are decreased, just make sure it is updated in the both areas | |
for i in `seq 1 2` | |
do | |
PIDFILE=$EB_CONFIG_APP_PIDS/sidekiq-$i.pid | |
# stop 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 -TERM `cat $PIDFILE` | |
fi | |
fi | |
# start a new instance | |
$BUNDLE exec $SIDEKIQ \ | |
-e production \ | |
-P $PIDFILE.pid \ | |
-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 are decreased, just make sure it is updated in the both areas | |
for i in `seq 1 2` | |
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