skippy-ec2onrails 0.9.10 → 0.9.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/CHANGELOG +21 -0
  2. data/Manifest +7 -1
  3. data/README.textile +10 -13
  4. data/Rakefile +4 -3
  5. data/TODO +10 -8
  6. data/ec2onrails.gemspec +17 -15
  7. data/examples/deploy.rb +7 -1
  8. data/lib/ec2onrails/recipes.rb +11 -714
  9. data/lib/ec2onrails/recipes/db.rb +377 -0
  10. data/lib/ec2onrails/recipes/deploy.rb +30 -0
  11. data/lib/ec2onrails/recipes/server.rb +489 -0
  12. data/lib/ec2onrails/version.rb +1 -1
  13. data/server/files/etc/apache2/sites-available/app.common +6 -1
  14. data/server/files/etc/cron.d/{backup_app_db_to_s3 → ec2onrails} +8 -0
  15. data/server/files/etc/cron.daily/app +17 -2
  16. data/server/files/etc/cron.hourly/app +16 -2
  17. data/server/files/etc/cron.monthly/app +16 -2
  18. data/server/files/etc/cron.weekly/app +16 -2
  19. data/server/files/etc/ec2onrails/README +1 -1
  20. data/server/files/etc/god/app.god +7 -2
  21. data/server/files/etc/god/dkim_filter.god +20 -0
  22. data/server/files/etc/god/system.god +1 -1
  23. data/server/files/etc/god/web.god +6 -4
  24. data/server/files/etc/mysql/my.cnf +3 -0
  25. data/server/files/etc/nginx/nginx.conf +11 -2
  26. data/server/files/etc/rcS.d/S91ec2-first-startup +36 -1
  27. data/server/files/etc/rcS.d/S92ec2-every-startup +29 -1
  28. data/server/files/etc/rcS.d/S99set_roles +3 -1
  29. data/server/files/etc/sudoers +26 -1
  30. data/server/files/usr/bin/god +0 -0
  31. data/server/files/usr/local/ec2onrails/bin/backup_app_db.rb +3 -2
  32. data/server/files/usr/local/ec2onrails/bin/backup_dir.rb +89 -0
  33. data/server/files/usr/local/ec2onrails/bin/exec_runner +9 -6
  34. data/server/files/usr/local/ec2onrails/bin/init_services.rb +7 -0
  35. data/server/files/usr/local/ec2onrails/bin/rails_env +1 -2
  36. data/server/files/usr/local/ec2onrails/bin/setup_web_proxy.rb +32 -28
  37. data/server/files/usr/local/ec2onrails/bin/update_hostname +40 -0
  38. data/server/files/usr/local/ec2onrails/lib/mysql_helper.rb +1 -1
  39. data/server/files/usr/local/ec2onrails/lib/s3_helper.rb +22 -0
  40. data/server/files/usr/local/ec2onrails/startup-scripts/every-startup/get-hostname.sh +1 -3
  41. data/server/rakefile.rb +12 -5
  42. data/test/test_app/config/deploy.rb +1 -1
  43. metadata +16 -12
@@ -46,21 +46,24 @@ module CommandLineArgs extend OptiFlagSet
46
46
 
47
47
  flag "exec" do
48
48
  description "what to run if the role of the server matches the -role passed in"
49
- end
49
+ end
50
+
51
+ optional_switch_flag "v" do
52
+ description "let you know if the script stopped because it was running in either a different role or environment than the one specified"
53
+ end
50
54
 
51
55
  and_process!
52
56
  end
53
57
 
54
58
  #strip out the ':', in case the user enters ':db', or ':app'
55
- role = ARGV.flags.role.sub(/^:/, '').to_sym
56
- if ARGV.flags.role && !in_role?(role)
57
- puts "This script is not being run because the server is not running under the #{role} role"
59
+ if ARGV.flags.role && !in_role?(ARGV.flags.role.sub(/^:/, '').to_sym)
60
+ puts "This script is not being run because the server is not running under the #{role} role" if ARGV.flags.v
58
61
  exit
59
62
  end
60
63
 
61
64
  curr_env = Ec2onrails::Utils.rails_env
62
- if ARGV.flags.only_env && ARGV.flags.only_env.strip != curr_env
63
- puts "This script is not being run because the server is not running under the #{curr_env} environment"
65
+ if ARGV.flags.only_env && ARGV.flags.only_env.strip.downcase != curr_env.strip.downcase
66
+ puts "This script is not being run because the server is not running under the #{curr_env} environment" if ARGV.flags.v
64
67
  exit
65
68
  end
66
69
 
@@ -28,6 +28,13 @@ include Ec2onrails::RolesHelper
28
28
  # not already in a web role. Leave as is, as all it does is throw an error
29
29
  # until GOD is in the picture, at which case it should be easy to enable
30
30
  # and let it handle it instead of the init.d script....
31
+ APP_ROOT = "/mnt/app/current"
32
+ RAILS_ENV = `/usr/local/ec2onrails/bin/rails_env`.strip
33
+
34
+ #reload configs to pick up any new changes
35
+ Dir.glob("/etc/god/*.god") + Dir.glob("/mnt/app/current/config/god/#{RAILS_ENV}/*.god").each do |f|
36
+ sudo "god load '#{f}'"
37
+ end
31
38
 
32
39
  # memcache role:
33
40
  if in_role?(:memcache)
@@ -28,8 +28,7 @@ require "yaml"
28
28
  @rails_env = YAML::load_file("/etc/mongrel_cluster/app.yml")["environment"]
29
29
 
30
30
  if ARGV.any?
31
- result = system "env RAILS_ENV=#{@rails_env} #{ARGV.join(' ')}"
32
- raise("error: #{$?}") unless result
31
+ exec "env RAILS_ENV=#{@rails_env} #{ARGV.join(' ')}"
33
32
  else
34
33
  puts @rails_env
35
34
  end
@@ -53,6 +53,7 @@ when 'apache'
53
53
  # sudo "sh -c 'export DEBIAN_FRONTEND=noninteractive; aptitude -q -y install apache2'"
54
54
 
55
55
  sudo "a2enmod deflate"
56
+ sudo "a2enmod headers"
56
57
  sudo "a2enmod proxy_balancer"
57
58
  sudo "a2enmod proxy_http"
58
59
  sudo "a2enmod rewrite"
@@ -64,36 +65,39 @@ when 'apache'
64
65
  sudo "ln -sf /mnt/log/apache2 /mnt/log/web_proxy"
65
66
 
66
67
  when 'nginx'
67
- #nginx does not have a precompiled package, so....
68
-
69
- src_dir = "#{Dir.pwd}/src"
68
+ #stop if already have nginx installed
69
+ unless system('which nginx')
70
+ #nginx does not have a precompiled package, so....
71
+ nginx_version = "nginx-0.6.35"
72
+ nginx_tar = "#{nginx_version}.tar.gz"
70
73
 
71
- nginx_img = "http://sysoev.ru/nginx/nginx-0.6.32.tar.gz"
72
- fair_bal_img = "http://github.com/gnosek/nginx-upstream-fair/tarball/master"
73
- nginx_dir = "#{src_dir}/nginx"
74
- puts "installing nginx 6.32 (src dir: #{nginx_dir})"
75
- run "mkdir -p -m 755 #{nginx_dir} && rm -rf #{nginx_dir}/*"
76
- run "mkdir -p -m 755 #{nginx_dir}/modules/nginx-upstream-fair"
77
- run "cd #{nginx_dir} && wget -q #{nginx_img} && tar -xzf nginx-0.6.32.tar.gz"
78
-
79
- run "cd #{nginx_dir}/modules && \
80
- wget -q #{fair_bal_img} && \
81
- tar -xzf *nginx-upstream-fair*.tar.gz -o -C ./nginx-upstream-fair && \
82
- mv nginx-upstream-fair/*/* nginx-upstream-fair/."
83
-
84
- sudo "sh -c 'export DEBIAN_FRONTEND=noninteractive; aptitude -q -y install libpcre3-dev'"
85
-
86
- run "cd #{nginx_dir}/nginx-0.6.32 && \
87
- ./configure \
88
- --sbin-path=/usr/sbin \
89
- --conf-path=/etc/nginx/nginx.conf \
90
- --pid-path=/var/run/nginx.pid \
91
- --with-http_ssl_module \
92
- --with-http_stub_status_module \
93
- --add-module=#{nginx_dir}/modules/nginx-upstream-fair && \
94
- make && \
95
- sudo make install"
74
+ nginx_img = "http://sysoev.ru/nginx/#{nginx_tar}"
75
+ fair_bal_img = "http://github.com/gnosek/nginx-upstream-fair/tarball/master"
76
+ src_dir = "/tmp/src/nginx"
77
+ puts "installing nginx #{nginx_version} (src dir: #{src_dir})"
78
+ #make sure the dir is created but empty...lets start afresh
79
+ run "mkdir -p -m 755 #{src_dir}/ && rm -rf #{src_dir}/*"
80
+ run "mkdir -p -m 755 #{src_dir}/modules/nginx-upstream-fair"
81
+ run "cd #{src_dir} && wget -q #{nginx_img} && tar -xzf #{nginx_tar}"
82
+
83
+ run "cd #{src_dir}/modules && \
84
+ wget -q #{fair_bal_img} && \
85
+ tar -xzf *nginx-upstream-fair*.tar.gz -o -C ./nginx-upstream-fair && \
86
+ mv nginx-upstream-fair/*/* nginx-upstream-fair/."
96
87
 
88
+ sudo "sh -c 'export DEBIAN_FRONTEND=noninteractive; aptitude -q -y install libpcre3-dev'"
89
+
90
+ run "cd #{src_dir}/#{nginx_version} && \
91
+ ./configure \
92
+ --sbin-path=/usr/sbin \
93
+ --conf-path=/etc/nginx/nginx.conf \
94
+ --pid-path=/var/run/nginx.pid \
95
+ --with-http_ssl_module \
96
+ --with-http_stub_status_module \
97
+ --add-module=#{src_dir}/modules/nginx-upstream-fair && \
98
+ make && \
99
+ sudo make install"
100
+ end
97
101
  run "sudo rm -rf /usr/local/nginx/logs; sudo ln -sf /mnt/log/nginx /usr/local/nginx/logs"
98
102
  #an init.d script is in the default server config... lets link it up
99
103
  sudo "ln -sf /etc/init.d/nginx /etc/init.d/web_proxy"
@@ -0,0 +1,40 @@
1
+ #!/bin/sh
2
+
3
+ # This file is part of EC2 on Rails.
4
+ # http://rubyforge.org/projects/ec2onrails/
5
+ #
6
+ # Copyright 2007 Paul Dowman, http://pauldowman.com/
7
+ #
8
+ # EC2 on Rails is free software; you can redistribute it and/or modify
9
+ # it under the terms of the GNU General Public License as published by
10
+ # the Free Software Foundation; either version 2 of the License, or
11
+ # (at your option) any later version.
12
+ #
13
+ # EC2 on Rails is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU General Public License
19
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
20
+
21
+
22
+ # Check if the hostname has been updated.
23
+ # This can happen if the user associated or disassociated an Elastic IP
24
+
25
+ OLD_HOSTNAME=`hostname`
26
+ /usr/local/ec2onrails/startup-scripts/every-startup/get-hostname.sh
27
+ NEW_HOSTNAME=`hostname`
28
+ if [ $OLD_HOSTNAME != $NEW_HOSTNAME ] ; then
29
+ echo "Hostname has changed (from $OLD_HOSTNAME to $NEW_HOSTNAME)"
30
+
31
+ echo "Restarting god..."
32
+ /etc/init.d/god restart > /dev/null
33
+
34
+ echo "Running full database backup into new bucket..."
35
+ # We run the full backup because the bucket name is expected to be based on
36
+ # the hostname.
37
+ # Kill any current backup job first.
38
+ killall -q -u root backup_app_db.rb
39
+ /usr/local/ec2onrails/bin/backup_app_db.rb --reset
40
+ fi
@@ -40,7 +40,7 @@ module Ec2onrails
40
40
  def load_db_config(config_file)
41
41
  db_config = YAML::load(ERB.new(File.read(config_file)).result)
42
42
  if db_config && db_config[@rails_env].nil?
43
- puts "the rails environment '#{@rails_env}' was not found in this db onfig file: #{config_file}"
43
+ puts "the rails environment '#{@rails_env}' was not found in this db config file: #{config_file}"
44
44
  end
45
45
  db_config = db_config[@rails_env]
46
46
  @database = db_config['database']
@@ -26,6 +26,7 @@ require "#{File.dirname(__FILE__)}/aws_helper"
26
26
 
27
27
  module Ec2onrails
28
28
  class S3Helper
29
+ SCRATCH_SPACE = '/mnt/tmp'
29
30
 
30
31
  # make attributes available for specs
31
32
  attr_accessor :bucket
@@ -63,6 +64,27 @@ module Ec2onrails
63
64
  create_bucket
64
65
  AWS::S3::S3Object.store(s3_key(file), open(file), @bucket)
65
66
  end
67
+
68
+ def store_dir(dir, options={})
69
+ FileUtils.mkdir_p SCRATCH_SPACE
70
+ create_bucket
71
+ compress = options[:compress]
72
+ exclude = options[:exclude]
73
+
74
+ #should be of the format:
75
+ # mnt-app-shared_ec2-75-101-250-19__20090217-183411.tgz
76
+ archive_nm = "#{Ec2onrails::Utils.hostname}__#{Time.new.strftime('%Y%m%d-%H%M%S')}"
77
+ archive_nm += compress ? ".tgz" : 'tar'
78
+ cmd = "cd #{SCRATCH_SPACE} && tar -cph"
79
+ cmd += 'z' if compress
80
+ cmd += "f #{archive_nm} -C / #{dir[1..-1]} "
81
+ cmd += " --exclude=#{exclude} "
82
+ system(cmd)
83
+ file = "#{SCRATCH_SPACE}/#{archive_nm}"
84
+ AWS::S3::S3Object.store(s3_key(archive_nm), open(file), @bucket)
85
+ ensure
86
+ system "nice -n 15 rm -f #{file}"
87
+ end
66
88
 
67
89
  def retrieve_file(file)
68
90
  key = s3_key(file)
@@ -20,6 +20,4 @@
20
20
 
21
21
  # Set the hostname to this instance's public hostname
22
22
 
23
- hostname `curl http://169.254.169.254/latest/meta-data/public-hostname`
24
- sudo god reload
25
-
23
+ hostname `curl -s http://169.254.169.254/latest/meta-data/public-hostname`
data/server/rakefile.rb CHANGED
@@ -80,6 +80,7 @@ end
80
80
  ruby
81
81
  ruby1.8-dev
82
82
  subversion
83
+ sysstat
83
84
  unzip
84
85
  vim
85
86
  wget
@@ -100,11 +101,14 @@ end
100
101
  "grempe-amazon-ec2",
101
102
  "aws-s3",
102
103
  "god",
104
+ "RubyInline",
103
105
  "memcache-client",
104
106
  "mongrel",
105
107
  "mongrel_cluster",
106
108
  "optiflag",
107
109
  "rails",
110
+ "rails -v '~> 2.2.2'",
111
+ "rails -v '~> 2.1.2'",
108
112
  "rails -v '~> 2.0.5'",
109
113
  "rails -v '~> 1.2.6'",
110
114
  "rake"
@@ -113,7 +117,7 @@ end
113
117
  @build_root = "/mnt/build"
114
118
  @fs_dir = "#{@build_root}/ubuntu"
115
119
 
116
- @version = [Ec2onrails::VERSION::MAJOR, Ec2onrails::VERSION::MINOR, Ec2onrails::VERSION::TINY].join('.')
120
+ @version = [Ec2onrails::VERSION::STRING]
117
121
 
118
122
  task :default => :configure
119
123
 
@@ -147,8 +151,9 @@ task :install_gems => [:install_packages] do |t|
147
151
  run_chroot "gem update --system --no-rdoc --no-ri"
148
152
  run_chroot "gem update --no-rdoc --no-ri"
149
153
  run_chroot "gem sources -a http://gems.github.com"
150
- @rubygems.each do |gem|
151
- run_chroot "gem install #{gem} --no-rdoc --no-ri"
154
+ # run_chroot "cp /root/.gemrc /home/app" # so the app user also has access to gems.github.com
155
+ @rubygems.each do |g|
156
+ run_chroot "gem install #{g} --no-rdoc --no-ri"
152
157
  end
153
158
  end
154
159
  end
@@ -157,7 +162,6 @@ desc "Configure the image"
157
162
  task :configure => [:install_gems] do |t|
158
163
  unless_completed(t) do
159
164
  sh("cp -r files/* #{@fs_dir}")
160
- sh("find #{@fs_dir} -type d -name .svn -o -name .git | xargs rm -rf")
161
165
  replace("#{@fs_dir}/etc/motd.tail", /!!VERSION!!/, "Version #{@version}")
162
166
 
163
167
  run_chroot "/usr/sbin/adduser --gecos ',,,' --disabled-password app"
@@ -175,6 +179,9 @@ task :configure => [:install_gems] do |t|
175
179
  # TODO find out the most correct solution here, there seems to be a bug in
176
180
  # both feisty and gutsy where the dhcp daemon runs as dhcp but the dir
177
181
  # that it tries to write to is owned by root and not writable by others.
182
+ # *** Do we still need this? The problem was constant messages in the syslog
183
+ # after the first DHCP lease expired (after 12 hours or so).
184
+ # We can probably assume Eric's base image does the right thing.
178
185
  run_chroot "chown -R dhcp /var/lib/dhcp3"
179
186
 
180
187
  #make sure that god is setup to reboot at startup
@@ -185,7 +192,7 @@ end
185
192
  desc "This task is for deploying the contents of /files to a running server image to test config file changes without rebuilding."
186
193
  task :deploy_files do |t|
187
194
  raise "need 'key' and 'host' env vars defined" unless ENV['key'] && ENV['host']
188
- run "rsync -rlvzcC --rsh='ssh -l root -i #{ENV['key']}' files/ #{ENV['host']}:/"
195
+ run "rsync -rlvzcCp --rsh='ssh -l root -i #{ENV['key']}' files/ #{ENV['host']}:/"
189
196
  end
190
197
 
191
198
  ##################
@@ -16,6 +16,6 @@ set :ec2onrails_config, {
16
16
  :packages => [],
17
17
  :rubygems => [],
18
18
  :timezone => "Canada/Eastern",
19
- :server_config_files_root => "../server_config",
19
+ :server_config_files_root => "../server_configs",
20
20
  :services_to_restart => %w(sysklogd)
21
21
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skippy-ec2onrails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.10
4
+ version: 0.9.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Dowman, Adam Greene
@@ -9,47 +9,42 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-12-19 00:00:00 -08:00
12
+ date: 2009-05-24 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: capistrano
17
+ type: :runtime
17
18
  version_requirement:
18
19
  version_requirements: !ruby/object:Gem::Requirement
19
20
  requirements:
20
21
  - - ">="
21
- - !ruby/object:Gem::Version
22
- version: "0"
23
- - - "="
24
22
  - !ruby/object:Gem::Version
25
23
  version: 2.4.3
26
24
  version:
27
25
  - !ruby/object:Gem::Dependency
28
26
  name: archive-tar-minitar
27
+ type: :runtime
29
28
  version_requirement:
30
29
  version_requirements: !ruby/object:Gem::Requirement
31
30
  requirements:
32
31
  - - ">="
33
- - !ruby/object:Gem::Version
34
- version: "0"
35
- - - "="
36
32
  - !ruby/object:Gem::Version
37
33
  version: 0.5.2
38
34
  version:
39
35
  - !ruby/object:Gem::Dependency
40
36
  name: optiflag
37
+ type: :runtime
41
38
  version_requirement:
42
39
  version_requirements: !ruby/object:Gem::Requirement
43
40
  requirements:
44
41
  - - ">="
45
- - !ruby/object:Gem::Version
46
- version: "0"
47
- - - "="
48
42
  - !ruby/object:Gem::Version
49
43
  version: 0.6.5
50
44
  version:
51
45
  - !ruby/object:Gem::Dependency
52
46
  name: rake
47
+ type: :development
53
48
  version_requirement:
54
49
  version_requirements: !ruby/object:Gem::Requirement
55
50
  requirements:
@@ -66,6 +61,9 @@ extensions: []
66
61
  extra_rdoc_files:
67
62
  - CHANGELOG
68
63
  - lib/ec2onrails/capistrano_utils.rb
64
+ - lib/ec2onrails/recipes/db.rb
65
+ - lib/ec2onrails/recipes/deploy.rb
66
+ - lib/ec2onrails/recipes/server.rb
69
67
  - lib/ec2onrails/recipes.rb
70
68
  - lib/ec2onrails/version.rb
71
69
  - lib/ec2onrails.rb
@@ -78,6 +76,9 @@ files:
78
76
  - examples/deploy.rb
79
77
  - examples/s3.yml
80
78
  - lib/ec2onrails/capistrano_utils.rb
79
+ - lib/ec2onrails/recipes/db.rb
80
+ - lib/ec2onrails/recipes/deploy.rb
81
+ - lib/ec2onrails/recipes/server.rb
81
82
  - lib/ec2onrails/recipes.rb
82
83
  - lib/ec2onrails/version.rb
83
84
  - lib/ec2onrails.rb
@@ -95,7 +96,7 @@ files:
95
96
  - server/files/etc/apache2/sites-available/app.custom
96
97
  - server/files/etc/apache2/sites-available/default
97
98
  - server/files/etc/apache2/sites-available/default-ssl
98
- - server/files/etc/cron.d/backup_app_db_to_s3
99
+ - server/files/etc/cron.d/ec2onrails
99
100
  - server/files/etc/cron.daily/app
100
101
  - server/files/etc/cron.daily/logrotate_post
101
102
  - server/files/etc/cron.hourly/app
@@ -109,6 +110,7 @@ files:
109
110
  - server/files/etc/environment
110
111
  - server/files/etc/god/app.god
111
112
  - server/files/etc/god/db.god
113
+ - server/files/etc/god/dkim_filter.god
112
114
  - server/files/etc/god/examples/have_god_daemonize.god
113
115
  - server/files/etc/god/master.conf
114
116
  - server/files/etc/god/memcache.god
@@ -140,6 +142,7 @@ files:
140
142
  - server/files/usr/bin/god
141
143
  - server/files/usr/local/ec2onrails/bin/archive_file.rb
142
144
  - server/files/usr/local/ec2onrails/bin/backup_app_db.rb
145
+ - server/files/usr/local/ec2onrails/bin/backup_dir.rb
143
146
  - server/files/usr/local/ec2onrails/bin/ec2_meta_data.rb
144
147
  - server/files/usr/local/ec2onrails/bin/exec_runner
145
148
  - server/files/usr/local/ec2onrails/bin/init_services.rb
@@ -150,6 +153,7 @@ files:
150
153
  - server/files/usr/local/ec2onrails/bin/set_rails_env
151
154
  - server/files/usr/local/ec2onrails/bin/set_roles.rb
152
155
  - server/files/usr/local/ec2onrails/bin/setup_web_proxy.rb
156
+ - server/files/usr/local/ec2onrails/bin/update_hostname
153
157
  - server/files/usr/local/ec2onrails/config
154
158
  - server/files/usr/local/ec2onrails/COPYING
155
159
  - server/files/usr/local/ec2onrails/lib/aws_helper.rb