Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Chef configuration for EC2
Ruby JavaScript Perl
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.


1. Setup Amazon EC2


1.1 Sign up
1.2 Download EC2 tools and extract to ~/tools, rename or make a symbolic link ~/tools/ec2-api-tools
1.3 Change bash profile to add
export EC2_HOME=~/tools/ec2-api-tools
export PATH=$PATH:$EC2_HOME/bin
export EC2_PRIVATE_KEY=~/.ec2/pk.pem
export EC2_CERT=~/.ec2/cert.pem
ssh-add ~/.ssh/ec2-keypair

1.4 Create and download pk-????.pem and cert-????.pem, move to ~/.ec2, rename to pk.pem and cert.pem
1.5 open new console and run
ec2-add-keypair ec2-keypair > ~/.ssh/ec2-keypair
chmod 600 ~/.ssh/ec2-keypair
ec2-authorize default -p 22
ec2-authorize default -p 80
ssh-add ~/.ssh/ec2-keypair

2. Start EC2 instance


2.1 Allocate elastic IP (through AWS Management Console)
2.2 Associate IP to running instance
2.3 Change A record on
2.4 Run below command to update ami_host 


3. Connect to EC2 instance

ssh root@`ami_host` echo DONE

# Phew, Now you don't have to use the -i option again (until you restart you computer)

4. Chef bootstrap

scp ~/proj/chef/chef-bootstrap root@`ami_host`:/tmp
ssh root@`ami_host` "ruby /tmp/chef-bootstrap"

5. Run chef

cd ~/proj/chef && rake cook server=root@`ami_host`

6. Deploy rails application

Update RAILS_APP/config/deploy.rb to match what is specified in dna.rb
cap deploy:setup
cap deploy:start
cap deploy:migrations

7. Terminate EC2 instance


8. Elastic IP

Release IP after instance is terminated (otherwise it costs $0.01/hour)


* default site is enabled (/etc/apache2/sites-enabled/000-default)
* /data/apps/gocool/releases is not created

* database is not created? Mysql::Error: Table '' doesn't exist: SHOW FIELDS FROM `games`
This is caused by active_scaffold, need to investigate

* Rails Error: Unable to access log file. Please ensure that /data/apps/gocool/releases/20091020122330/log/production.log exists and is chmod 0666. The log level has been raised to WARN and the output directed to STDERR until the problem is fixed.
Use different log file location in application


If you see error below
  /usr/lib/ruby/1.8/pathname.rb:709:in `relative_path_from': different prefix: "/" and "." (ArgumentError)
  from /usr/lib/ruby/gems/1.8/gems/chef-0.7.12/lib/chef/provider/template.rb:57:in `action_create'
Follow instructions in to modify template.rb (on EC2 host)

If you see error below (related to sshd)
  /usr/lib/ruby/gems/1.8/gems/chef-0.7.12/lib/chef/provider/service/simple.rb:60:in `close': closed stream (IOError)
  from /usr/lib/ruby/gems/1.8/gems/chef-0.7.12/lib/chef/provider/service/simple.rb:60:in `load_current_resource' 
Comment out 'stdin.close' in .../provider/service/simple.rb

If you see error below
  DEBUG: STDERR: mv: cannot move `/var/lib/mysql' to `/db/mysql': No such file or directory
  DEBUG: ---- End output of mv /var/lib/mysql /db/mysql ----
  DEBUG: Ran mv /var/lib/mysql /db/mysql returned 1
  ERROR: execute[install-mysql] (/etc/chef/cookbooks/mysql/recipes/default.rb line 64) had an error:
  mv /var/lib/mysql /db/mysql returned 1, expected 0
Create dir /db

If you see error below
  DEBUG: Cron empty for 'mr_app'
  ERROR: cron[a_dumb_task] (/etc/chef/cookbooks/cron/recipes/default.rb line 7) had an error:
  Broken pipe
  from /usr/lib/ruby/gems/1.8/gems/chef-0.7.12/lib/chef/provider/cron.rb:146:in `puts'
Comment out 'cron' in recipes in chef/config/dna.rb (in this project)
Something went wrong with that request. Please try again.