Skip to content

Instantly share code, notes, and snippets.

@JaisonBrooks
Forked from gcarrion-gfrmedia/0000_packages.config
Created December 2, 2016 17:10
Show Gist options
  • Save JaisonBrooks/17d8ad2f27c3cf45ecbd460d7a5de7ca to your computer and use it in GitHub Desktop.
Save JaisonBrooks/17d8ad2f27c3cf45ecbd460d7a5de7ca to your computer and use it in GitHub Desktop.
AWS Elastic Beanstalk Ruby 2.0/Puma Environment - .ebextensions tweaks and Sidekiq configuration. This is known to work fine with AWS Elastic Beanstalk 's 64bit Amazon Linux 2014.03 v1.0.1 running Ruby 2.0 (Puma) stack. Later stack versions might not work, but for that specific version works fine.
# Install Git needed for Git based gems
packages:
yum:
git: []
# Fixing permissions of packaged gems
files:
"/opt/elasticbeanstalk/hooks/appdeploy/pre/10_fixing_permission.sh":
content: |
#!/usr/bin/env bash
. /opt/elasticbeanstalk/containerfiles/envvars
CACHE_GEM_DIR=$EB_CONFIG_APP_ONDECK/vendor/cache
if [ -d $CACHE_GEM_DIR ]
then
chown -R webapp:webapp $CACHE_GEM_DIR
echo "Modified the owner of $CACHE_GEM_DIR files"
else
echo "Nothing in $CACHE_GEM_DIR"
fi
true
mode: "000755"
# 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/containerfiles/envvars
cd $EB_CONFIG_APP_ONDECK
if [ -f Gemfile ]
then
echo "running 'bundle install' with Gemfile:"
cat Gemfile
if [ -d $EB_CONFIG_APP_ONDECK/vendor/cache ]
then
/usr/local/bin/bundle install --local
# Incase there is a gem that is missing from the cache
/usr/local/bin/bundle pack --all
/usr/local/bin/bundle install
else
/usr/local/bin/bundle pack --all
/usr/local/bin/bundle install
fi
if [ $? != 0 ]
then
echo "ERROR: bundle install failed!"
exit 1
else
echo "bundle install succeeded"
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_CONFIG_APP_USER:$EB_CONFIG_APP_USER Gemfile.lock
else
echo "no Gemfile.lock file found, so no permissions to set on it";
fi
true
mode: "000755"
# Sidekiq interaction and startup script
files:
"/opt/elasticbeanstalk/hooks/appdeploy/post/50_restart_sidekiq":
mode: "000755"
content: |
#!/bin/bash
. /opt/elasticbeanstalk/containerfiles/envvars
PIDFILE=$EB_CONFIG_APP_PIDS/sidekiq.pid
cd $EB_CONFIG_APP_CURRENT
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`
sleep 10
rm -rf $PIDFILE
fi
fi
BUNDLE=/usr/local/bin/bundle
SIDEKIQ=/usr/local/bin/sidekiq
$BUNDLE exec $SIDEKIQ \
-e production \
-P /var/app/containerfiles/pids/sidekiq.pid \
-C /var/app/current/config/sidekiq.yml \
-L /var/app/containerfiles/logs/sidekiq.log \
-d
"/opt/elasticbeanstalk/hooks/appdeploy/pre/03_mute_sidekiq":
mode: "000755"
content: |
#!/bin/bash
. /opt/elasticbeanstalk/containerfiles/envvars
PIDFILE=$EB_CONFIG_APP_PIDS/sidekiq.pid
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`
sleep 10
fi
fi
# Globally include the vendor/cache gem location and the location of puma_http11 gem
files:
"/opt/elasticbeanstalk/containerfiles/envvars.d/appenv":
content: |
export RUBYLIB=$RUBYLIB:/var/app/current/vendor/cache:/usr/local/lib64/ruby/gems/2.0/gems/puma-2.8.1/lib/
mode: "000644"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment