Elastic Beanstalk will execute any script in /opt/elasticbeanstalk/hooks/appdeploy/post after the web server is restarted. This means if you drop shell scripts in this directory they will be run. Please also refer the AWS Documentation for container_commands.

I have created a file name delayed_job.config in the .ebextensions folder in order to deploy a shell script that runs after the deployment gets over.

For RAILS 3.x


Below is my delayed_job.sh file for Rails 3.x

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
commands:
  create_post_dir:
    command: "mkdir /opt/elasticbeanstalk/hooks/appdeploy/post"
    ignoreErrors: true
    
files:
  "/opt/elasticbeanstalk/hooks/appdeploy/post/delayed_job.sh":
    mode: "000755"
    owner: root
    group: root
    content: |
      #!/usr/bin/env bash
      . /opt/elasticbeanstalk/support/envvars
      cd $EB_CONFIG_APP_CURRENT
      su -c "RAILS_ENV=production script/delayed_job --pid-dir=$EB_CONFIG_APP_SUPPORT/pids restart" $EB_CONFIG_APP_USER

For RAILS 4.x


Below is my delayed_job.sh file for Rails 4.x

1
2
3
4
5
6
7
8
9
10
11
12
13
14
commands:
  create_post_dir:
    command: "mkdir /opt/elasticbeanstalk/hooks/appdeploy/post"
    ignoreErrors: true
files:
  "/opt/elasticbeanstalk/hooks/appdeploy/post/delayed_job.sh":
    mode: "000755"
    owner: root
    group: root
    content: |
      #!/usr/bin/env bash
      . /opt/elasticbeanstalk/support/envvars
      cd $EB_CONFIG_APP_CURRENT
      su -c "RAILS_ENV=production bin/delayed_job  --pid-dir=$EB_CONFIG_APP_SUPPORT/pids restart" $EB_CONFIG_APP_USER

What this config do is:

  • Create the “post” directory if it doesn’t already exist, it ignores errors (If the directory already exists).
  • Deploy the shell script with the appropriate permission into the right directory.

What this shell script do is:

  • Setup the environment variables in ((/opt/elasticbeanstalk).
  • Restart delayed_job as per the app user (usually webapp), using a shared pids directory to make sure it will kill the old version first.

Install a ruby 2.0.0 on an Amazon AMI. This is just a quick update to get version 2.0.0 up. We used the current 64 bits Amazon AMI. Note that the complete procedure might take a few hours on a Amazon Micro instance. Deleting the old version of Ruby also removes the package aws-amitools-ec2. As long as you don’t need to create your own AMIs with this instance, you will be fine. Here is the procedure, as usual log in as ec2-user and perform the following from the shell:

Login as root

1
2
sudo su -
cd

Remove the old version of Ruby

1
yum remove ruby

Install the dependency packages

1
2
3
4
5
yum groupinstall 'Development Tools'
yum groupinstall development-libs
yum install libffi-devel
yum install libyaml-devel
yum update

After intalling the dependency packages download and install Ruby 2.0.0

1
2
3
4
5
6
7
8
9
10
wget ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p195.tar.gz
tar xzvf ruby-2.0.0-p195.tar.gz
cd ruby-2.0.0-p195
./configure
make
make install
make clean
gem update --system
exit
ruby --version (this should give you the newly installed version)

That’s it! Have fun with Ruby!