gigpark-ec2onrails 0.9.10.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +190 -0
- data/COPYING +339 -0
- data/Manifest +160 -0
- data/README.textile +233 -0
- data/Rakefile +31 -0
- data/TODO +104 -0
- data/ec2onrails.gemspec +46 -0
- data/echoe_config.rb +27 -0
- data/examples/Capfile +3 -0
- data/examples/deploy.rb +103 -0
- data/examples/s3.yml +9 -0
- data/lib/ec2onrails.rb +20 -0
- data/lib/ec2onrails/capistrano_utils.rb +47 -0
- data/lib/ec2onrails/recipes.rb +146 -0
- data/lib/ec2onrails/recipes/db.rb +366 -0
- data/lib/ec2onrails/recipes/deploy.rb +26 -0
- data/lib/ec2onrails/recipes/server.rb +517 -0
- data/lib/ec2onrails/version.rb +29 -0
- data/server/build +74 -0
- data/server/files/etc/README +7 -0
- data/server/files/etc/aliases +5 -0
- data/server/files/etc/cron.d/ec2onrails +16 -0
- data/server/files/etc/cron.daily/app +31 -0
- data/server/files/etc/cron.daily/logrotate_post +25 -0
- data/server/files/etc/cron.hourly/app +31 -0
- data/server/files/etc/cron.monthly/app +31 -0
- data/server/files/etc/cron.weekly/app +31 -0
- data/server/files/etc/default/varnish +33 -0
- data/server/files/etc/default/varnishncsa +11 -0
- data/server/files/etc/denyhosts.conf +628 -0
- data/server/files/etc/dpkg/dpkg.cfg +13 -0
- data/server/files/etc/ec2onrails/rails_env +1 -0
- data/server/files/etc/ec2onrails/roles.yml +5 -0
- data/server/files/etc/environment +2 -0
- data/server/files/etc/event.d/god +8 -0
- data/server/files/etc/god/db_primary.god +16 -0
- data/server/files/etc/god/dkim_filter.god +17 -0
- data/server/files/etc/god/master.conf +40 -0
- data/server/files/etc/god/memcache.god +15 -0
- data/server/files/etc/god/notifications.god +11 -0
- data/server/files/etc/god/proxy.god +40 -0
- data/server/files/etc/god/system.god +37 -0
- data/server/files/etc/god/web.god +23 -0
- data/server/files/etc/init.d/ec2-every-startup +29 -0
- data/server/files/etc/init.d/ec2-first-startup +37 -0
- data/server/files/etc/init.d/nginx +78 -0
- data/server/files/etc/logrotate.d/nginx +10 -0
- data/server/files/etc/logrotate.d/rails +8 -0
- data/server/files/etc/logrotate.d/varnish +14 -0
- data/server/files/etc/memcached.conf +47 -0
- data/server/files/etc/motd.tail +13 -0
- data/server/files/etc/mysql/my.cnf +152 -0
- data/server/files/etc/nginx/conf.d/custom.conf +1 -0
- data/server/files/etc/nginx/nginx.conf.erb +152 -0
- data/server/files/etc/postfix/main.cf +4 -0
- data/server/files/etc/ssh/sshd_config +96 -0
- data/server/files/etc/sudoers +31 -0
- data/server/files/etc/syslog.conf +63 -0
- data/server/files/etc/varnish/default.vcl.erb +140 -0
- data/server/files/usr/local/ec2onrails/COPYING +339 -0
- data/server/files/usr/local/ec2onrails/bin/archive_file +44 -0
- data/server/files/usr/local/ec2onrails/bin/backup_app_db +160 -0
- data/server/files/usr/local/ec2onrails/bin/backup_dir +89 -0
- data/server/files/usr/local/ec2onrails/bin/ec2_meta_data +80 -0
- data/server/files/usr/local/ec2onrails/bin/exec_runner +76 -0
- data/server/files/usr/local/ec2onrails/bin/in_role +33 -0
- data/server/files/usr/local/ec2onrails/bin/init_services +43 -0
- data/server/files/usr/local/ec2onrails/bin/install_system_files +56 -0
- data/server/files/usr/local/ec2onrails/bin/optimize_mysql +346 -0
- data/server/files/usr/local/ec2onrails/bin/public-hostname +24 -0
- data/server/files/usr/local/ec2onrails/bin/rails_env +33 -0
- data/server/files/usr/local/ec2onrails/bin/rebundle +62 -0
- data/server/files/usr/local/ec2onrails/bin/restore_app_db +58 -0
- data/server/files/usr/local/ec2onrails/bin/set_rails_env +36 -0
- data/server/files/usr/local/ec2onrails/bin/set_roles +36 -0
- data/server/files/usr/local/ec2onrails/bin/uninstall_system_files +34 -0
- data/server/files/usr/local/ec2onrails/config +30 -0
- data/server/files/usr/local/ec2onrails/lib/aws_helper.rb +75 -0
- data/server/files/usr/local/ec2onrails/lib/god_helper.rb +84 -0
- data/server/files/usr/local/ec2onrails/lib/mysql_helper.rb +100 -0
- data/server/files/usr/local/ec2onrails/lib/roles_helper.rb +156 -0
- data/server/files/usr/local/ec2onrails/lib/s3_helper.rb +116 -0
- data/server/files/usr/local/ec2onrails/lib/system_files_helper.rb +110 -0
- data/server/files/usr/local/ec2onrails/lib/system_files_manifest.rb +107 -0
- data/server/files/usr/local/ec2onrails/lib/utils.rb +26 -0
- data/server/files/usr/local/ec2onrails/lib/vendor/ini.rb +268 -0
- data/server/files/usr/local/ec2onrails/startup-scripts/every-startup/README +5 -0
- data/server/files/usr/local/ec2onrails/startup-scripts/every-startup/create-mysqld-pid-dir +26 -0
- data/server/files/usr/local/ec2onrails/startup-scripts/first-startup/README +5 -0
- data/server/files/usr/local/ec2onrails/startup-scripts/first-startup/create-dirs +45 -0
- data/server/files/usr/local/ec2onrails/startup-scripts/first-startup/generate-default-web-cert-and-key +49 -0
- data/server/files/usr/local/ec2onrails/startup-scripts/first-startup/get-hostname +27 -0
- data/server/files/usr/local/ec2onrails/startup-scripts/first-startup/misc +27 -0
- data/server/files/usr/local/ec2onrails/startup-scripts/first-startup/prepare-mysql-data-dir +24 -0
- data/server/files/usr/local/ec2onrails/startup-scripts/first-startup/setup-credentials +32 -0
- data/server/files/usr/local/ec2onrails/startup-scripts/first-startup/setup-file-permissions +30 -0
- data/server/rakefile-wrapper +26 -0
- data/server/rakefile.rb +267 -0
- data/test/autobench.conf +60 -0
- data/test/spec/lib/s3_helper_spec.rb +154 -0
- data/test/spec/lib/s3_old.yml +3 -0
- data/test/spec/lib/system_files_manifest_spec.rb +122 -0
- data/test/spec/test_files/system_files1/_manifest +13 -0
- data/test/spec/test_files/system_files1/test1 +0 -0
- data/test/spec/test_files/system_files1/test2 +0 -0
- data/test/spec/test_files/system_files1/testfolder/test3 +0 -0
- data/test/spec/test_files/system_files2/_manifest +2 -0
- data/test/spec/test_files/system_files2/test1 +0 -0
- data/test/spec/test_files/system_files2/test2 +0 -0
- data/test/spec/test_files/system_files2/testfolder/test3 +0 -0
- data/test/spec/test_files/test2 +0 -0
- data/test/test_app/Capfile +3 -0
- data/test/test_app/README +243 -0
- data/test/test_app/Rakefile +10 -0
- data/test/test_app/app/controllers/application_controller.rb +10 -0
- data/test/test_app/app/controllers/db_fast_controller.rb +6 -0
- data/test/test_app/app/controllers/fast_controller.rb +5 -0
- data/test/test_app/app/controllers/slow_controller.rb +6 -0
- data/test/test_app/app/controllers/very_slow_controller.rb +6 -0
- data/test/test_app/app/helpers/application_helper.rb +3 -0
- data/test/test_app/config/boot.rb +110 -0
- data/test/test_app/config/database.yml +24 -0
- data/test/test_app/config/deploy.rb +22 -0
- data/test/test_app/config/ec2onrails/config.rb +5 -0
- data/test/test_app/config/environment.rb +41 -0
- data/test/test_app/config/environments/development.rb +17 -0
- data/test/test_app/config/environments/production.rb +28 -0
- data/test/test_app/config/environments/test.rb +28 -0
- data/test/test_app/config/initializers/backtrace_silencers.rb +7 -0
- data/test/test_app/config/initializers/inflections.rb +10 -0
- data/test/test_app/config/initializers/mime_types.rb +5 -0
- data/test/test_app/config/initializers/new_rails_defaults.rb +19 -0
- data/test/test_app/config/initializers/session_store.rb +15 -0
- data/test/test_app/config/locales/en.yml +5 -0
- data/test/test_app/config/routes.rb +43 -0
- data/test/test_app/doc/README_FOR_APP +2 -0
- data/test/test_app/public/404.html +30 -0
- data/test/test_app/public/422.html +30 -0
- data/test/test_app/public/500.html +30 -0
- data/test/test_app/public/favicon.ico +0 -0
- data/test/test_app/public/images/rails.png +0 -0
- data/test/test_app/public/index.html +275 -0
- data/test/test_app/public/javascripts/application.js +2 -0
- data/test/test_app/public/javascripts/controls.js +963 -0
- data/test/test_app/public/javascripts/dragdrop.js +973 -0
- data/test/test_app/public/javascripts/effects.js +1128 -0
- data/test/test_app/public/javascripts/prototype.js +4320 -0
- data/test/test_app/public/robots.txt +5 -0
- data/test/test_app/script/about +4 -0
- data/test/test_app/script/console +3 -0
- data/test/test_app/script/dbconsole +3 -0
- data/test/test_app/script/destroy +3 -0
- data/test/test_app/script/generate +3 -0
- data/test/test_app/script/performance/benchmarker +3 -0
- data/test/test_app/script/performance/profiler +3 -0
- data/test/test_app/script/plugin +3 -0
- data/test/test_app/script/runner +3 -0
- data/test/test_app/script/server +3 -0
- data/test/test_app/test/performance/browsing_test.rb +9 -0
- data/test/test_app/test/test_helper.rb +38 -0
- metadata +266 -0
data/ec2onrails.gemspec
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# This file is auto-generated, do not edit.
|
2
|
+
# Edit echoe_config.rb and then run 'rake ec2onrails_gem'
|
3
|
+
#
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{ec2onrails}
|
8
|
+
s.version = "0.9.10.3"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Paul Dowman, Adam Greene"]
|
12
|
+
s.date = %q{2009-08-16}
|
13
|
+
s.description = %q{Client-side libraries (Capistrano tasks) for managing and deploying to EC2 on Rails servers.}
|
14
|
+
s.email = %q{paul@pauldowman.com}
|
15
|
+
s.extra_rdoc_files = ["CHANGELOG", "lib/ec2onrails/capistrano_utils.rb", "lib/ec2onrails/recipes/db.rb", "lib/ec2onrails/recipes/deploy.rb", "lib/ec2onrails/recipes/server.rb", "lib/ec2onrails/recipes.rb", "lib/ec2onrails/version.rb", "lib/ec2onrails.rb", "README.textile"]
|
16
|
+
s.files = ["CHANGELOG", "COPYING", "ec2onrails.gemspec", "echoe_config.rb", "examples/Capfile", "examples/deploy.rb", "examples/s3.yml", "lib/ec2onrails/capistrano_utils.rb", "lib/ec2onrails/recipes/db.rb", "lib/ec2onrails/recipes/deploy.rb", "lib/ec2onrails/recipes/server.rb", "lib/ec2onrails/recipes.rb", "lib/ec2onrails/version.rb", "lib/ec2onrails.rb", "Manifest", "Rakefile", "README.textile", "server/build", "server/files/etc/aliases", "server/files/etc/cron.d/ec2onrails", "server/files/etc/cron.daily/app", "server/files/etc/cron.daily/logrotate_post", "server/files/etc/cron.hourly/app", "server/files/etc/cron.monthly/app", "server/files/etc/cron.weekly/app", "server/files/etc/default/varnish", "server/files/etc/default/varnishncsa", "server/files/etc/denyhosts.conf", "server/files/etc/dpkg/dpkg.cfg", "server/files/etc/ec2onrails/rails_env", "server/files/etc/ec2onrails/roles.yml", "server/files/etc/environment", "server/files/etc/event.d/god", "server/files/etc/god/db_primary.god", "server/files/etc/god/dkim_filter.god", "server/files/etc/god/master.conf", "server/files/etc/god/memcache.god", "server/files/etc/god/notifications.god", "server/files/etc/god/proxy.god", "server/files/etc/god/system.god", "server/files/etc/god/web.god", "server/files/etc/init.d/ec2-every-startup", "server/files/etc/init.d/ec2-first-startup", "server/files/etc/init.d/nginx", "server/files/etc/logrotate.d/nginx", "server/files/etc/logrotate.d/rails", "server/files/etc/logrotate.d/varnish", "server/files/etc/memcached.conf", "server/files/etc/motd.tail", "server/files/etc/mysql/my.cnf", "server/files/etc/nginx/conf.d/custom.conf", "server/files/etc/nginx/nginx.conf.erb", "server/files/etc/postfix/main.cf", "server/files/etc/README", "server/files/etc/ssh/sshd_config", "server/files/etc/sudoers", "server/files/etc/syslog.conf", "server/files/etc/varnish/default.vcl.erb", "server/files/usr/local/ec2onrails/bin/archive_file", "server/files/usr/local/ec2onrails/bin/backup_app_db", "server/files/usr/local/ec2onrails/bin/backup_dir", "server/files/usr/local/ec2onrails/bin/ec2_meta_data", "server/files/usr/local/ec2onrails/bin/exec_runner", "server/files/usr/local/ec2onrails/bin/in_role", "server/files/usr/local/ec2onrails/bin/init_services", "server/files/usr/local/ec2onrails/bin/install_system_files", "server/files/usr/local/ec2onrails/bin/optimize_mysql", "server/files/usr/local/ec2onrails/bin/public-hostname", "server/files/usr/local/ec2onrails/bin/rails_env", "server/files/usr/local/ec2onrails/bin/rebundle", "server/files/usr/local/ec2onrails/bin/restore_app_db", "server/files/usr/local/ec2onrails/bin/set_rails_env", "server/files/usr/local/ec2onrails/bin/set_roles", "server/files/usr/local/ec2onrails/bin/uninstall_system_files", "server/files/usr/local/ec2onrails/config", "server/files/usr/local/ec2onrails/COPYING", "server/files/usr/local/ec2onrails/lib/aws_helper.rb", "server/files/usr/local/ec2onrails/lib/god_helper.rb", "server/files/usr/local/ec2onrails/lib/mysql_helper.rb", "server/files/usr/local/ec2onrails/lib/roles_helper.rb", "server/files/usr/local/ec2onrails/lib/s3_helper.rb", "server/files/usr/local/ec2onrails/lib/system_files_helper.rb", "server/files/usr/local/ec2onrails/lib/system_files_manifest.rb", "server/files/usr/local/ec2onrails/lib/utils.rb", "server/files/usr/local/ec2onrails/lib/vendor/ini.rb", "server/files/usr/local/ec2onrails/startup-scripts/every-startup/create-mysqld-pid-dir", "server/files/usr/local/ec2onrails/startup-scripts/every-startup/README", "server/files/usr/local/ec2onrails/startup-scripts/first-startup/create-dirs", "server/files/usr/local/ec2onrails/startup-scripts/first-startup/generate-default-web-cert-and-key", "server/files/usr/local/ec2onrails/startup-scripts/first-startup/get-hostname", "server/files/usr/local/ec2onrails/startup-scripts/first-startup/misc", "server/files/usr/local/ec2onrails/startup-scripts/first-startup/prepare-mysql-data-dir", "server/files/usr/local/ec2onrails/startup-scripts/first-startup/README", "server/files/usr/local/ec2onrails/startup-scripts/first-startup/setup-credentials", "server/files/usr/local/ec2onrails/startup-scripts/first-startup/setup-file-permissions", "server/rakefile-wrapper", "server/rakefile.rb", "test/autobench.conf", "test/spec/lib/s3_helper_spec.rb", "test/spec/lib/s3_old.yml", "test/spec/lib/system_files_manifest_spec.rb", "test/spec/test_files/system_files1/_manifest", "test/spec/test_files/system_files1/test1", "test/spec/test_files/system_files1/test2", "test/spec/test_files/system_files1/testfolder/test3", "test/spec/test_files/system_files2/_manifest", "test/spec/test_files/system_files2/test1", "test/spec/test_files/system_files2/test2", "test/spec/test_files/system_files2/testfolder/test3", "test/spec/test_files/test2", "test/test_app/app/controllers/application_controller.rb", "test/test_app/app/controllers/db_fast_controller.rb", "test/test_app/app/controllers/fast_controller.rb", "test/test_app/app/controllers/slow_controller.rb", "test/test_app/app/controllers/very_slow_controller.rb", "test/test_app/app/helpers/application_helper.rb", "test/test_app/Capfile", "test/test_app/config/boot.rb", "test/test_app/config/database.yml", "test/test_app/config/deploy.rb", "test/test_app/config/ec2onrails/config.rb", "test/test_app/config/environment.rb", "test/test_app/config/environments/development.rb", "test/test_app/config/environments/production.rb", "test/test_app/config/environments/test.rb", "test/test_app/config/initializers/backtrace_silencers.rb", "test/test_app/config/initializers/inflections.rb", "test/test_app/config/initializers/mime_types.rb", "test/test_app/config/initializers/new_rails_defaults.rb", "test/test_app/config/initializers/session_store.rb", "test/test_app/config/locales/en.yml", "test/test_app/config/routes.rb", "test/test_app/doc/README_FOR_APP", "test/test_app/public/404.html", "test/test_app/public/422.html", "test/test_app/public/500.html", "test/test_app/public/favicon.ico", "test/test_app/public/images/rails.png", "test/test_app/public/index.html", "test/test_app/public/javascripts/application.js", "test/test_app/public/javascripts/controls.js", "test/test_app/public/javascripts/dragdrop.js", "test/test_app/public/javascripts/effects.js", "test/test_app/public/javascripts/prototype.js", "test/test_app/public/robots.txt", "test/test_app/Rakefile", "test/test_app/README", "test/test_app/script/about", "test/test_app/script/console", "test/test_app/script/dbconsole", "test/test_app/script/destroy", "test/test_app/script/generate", "test/test_app/script/performance/benchmarker", "test/test_app/script/performance/profiler", "test/test_app/script/plugin", "test/test_app/script/runner", "test/test_app/script/server", "test/test_app/test/performance/browsing_test.rb", "test/test_app/test/test_helper.rb", "TODO"]
|
17
|
+
s.homepage = %q{http://ec2onrails.rubyforge.org}
|
18
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Ec2onrails", "--main", "README.textile"]
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
s.rubyforge_project = %q{ec2onrails}
|
21
|
+
s.rubygems_version = %q{1.3.4}
|
22
|
+
s.summary = %q{Client-side libraries (Capistrano tasks) for managing and deploying to EC2 on Rails servers.}
|
23
|
+
s.test_files = ["test/test_app/test/performance/browsing_test.rb", "test/test_app/test/test_helper.rb"]
|
24
|
+
|
25
|
+
if s.respond_to? :specification_version then
|
26
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
27
|
+
s.specification_version = 3
|
28
|
+
|
29
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
30
|
+
s.add_runtime_dependency(%q<capistrano>, [">= 2.4.3"])
|
31
|
+
s.add_runtime_dependency(%q<archive-tar-minitar>, [">= 0.5.2"])
|
32
|
+
s.add_runtime_dependency(%q<optiflag>, [">= 0.6.5"])
|
33
|
+
s.add_development_dependency(%q<rake>, [">= 0.7.1"])
|
34
|
+
else
|
35
|
+
s.add_dependency(%q<capistrano>, [">= 2.4.3"])
|
36
|
+
s.add_dependency(%q<archive-tar-minitar>, [">= 0.5.2"])
|
37
|
+
s.add_dependency(%q<optiflag>, [">= 0.6.5"])
|
38
|
+
s.add_dependency(%q<rake>, [">= 0.7.1"])
|
39
|
+
end
|
40
|
+
else
|
41
|
+
s.add_dependency(%q<capistrano>, [">= 2.4.3"])
|
42
|
+
s.add_dependency(%q<archive-tar-minitar>, [">= 0.5.2"])
|
43
|
+
s.add_dependency(%q<optiflag>, [">= 0.6.5"])
|
44
|
+
s.add_dependency(%q<rake>, [">= 0.7.1"])
|
45
|
+
end
|
46
|
+
end
|
data/echoe_config.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require "./lib/ec2onrails/version"
|
2
|
+
|
3
|
+
Echoe.new('ec2onrails', Ec2onrails::VERSION::STRING.dup) do |p|
|
4
|
+
p.changelog = "CHANGELOG"
|
5
|
+
|
6
|
+
p.author = ['Paul Dowman', 'Adam Greene']
|
7
|
+
p.email = "paul@pauldowman.com"
|
8
|
+
|
9
|
+
p.summary = <<-DESC.strip.gsub(/\n\s+/, " ")
|
10
|
+
Client-side libraries (Capistrano tasks) for managing and
|
11
|
+
deploying to EC2 on Rails servers.
|
12
|
+
DESC
|
13
|
+
|
14
|
+
#OTHER helpful options
|
15
|
+
# p.install_message = "perhaps telling them where to find the example docs?"
|
16
|
+
# p.rdoc_pattern
|
17
|
+
p.url = "http://ec2onrails.rubyforge.org"
|
18
|
+
p.need_zip = true
|
19
|
+
p.rdoc_pattern = /^(lib|README.textile|CHANGELOG)/
|
20
|
+
|
21
|
+
p.dependencies = [
|
22
|
+
'capistrano >=2.4.3',
|
23
|
+
'archive-tar-minitar >=0.5.2',
|
24
|
+
'optiflag >=0.6.5']
|
25
|
+
|
26
|
+
p.development_dependencies = ['rake >=0.7.1']
|
27
|
+
end
|
data/examples/Capfile
ADDED
data/examples/deploy.rb
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
# This is a sample Capistrano config file for EC2 on Rails.
|
2
|
+
# It should be edited and customized.
|
3
|
+
|
4
|
+
set :application, "yourapp"
|
5
|
+
|
6
|
+
set :repository, "http://svn.foo.com/svn/#{application}/trunk"
|
7
|
+
|
8
|
+
# NOTE: for some reason Capistrano requires you to have both the public and
|
9
|
+
# the private key in the same folder, the public key should have the
|
10
|
+
# extension ".pub".
|
11
|
+
ssh_options[:keys] = ["#{ENV['HOME']}/.ssh/your-ec2-key"]
|
12
|
+
|
13
|
+
# Your EC2 instances. Use the ec2-xxx....amazonaws.com hostname, not
|
14
|
+
# any other name (in case you have your own DNS alias) or it won't
|
15
|
+
# be able to resolve to the internal IP address.
|
16
|
+
role :web, "ec2-12-xx-xx-xx.z-1.compute-1.amazonaws.com"
|
17
|
+
role :memcache, "ec2-12-xx-xx-xx.z-1.compute-1.amazonaws.com"
|
18
|
+
role :db, "ec2-56-xx-xx-xx.z-1.compute-1.amazonaws.com", :primary => true
|
19
|
+
# role :db, "ec2-56-xx-xx-xx.z-1.compute-1.amazonaws.com", :primary => true, :ebs_vol_id => 'vol-12345abc'
|
20
|
+
# optinally, you can specify Amazon's EBS volume ID if the database is persisted
|
21
|
+
# via Amazon's EBS. See the main README for more information.
|
22
|
+
|
23
|
+
# Whatever you set here will be taken set as the default RAILS_ENV value
|
24
|
+
# on the server. Your app and your hourly/daily/weekly/monthly scripts
|
25
|
+
# will run with RAILS_ENV set to this value.
|
26
|
+
set :rails_env, "production"
|
27
|
+
|
28
|
+
# EC2 on Rails config.
|
29
|
+
# NOTE: Some of these should be omitted if not needed.
|
30
|
+
set :ec2onrails_config, {
|
31
|
+
# S3 bucket and "subdir" used by the ec2onrails:db:restore task
|
32
|
+
# NOTE: this only applies if you are not using EBS
|
33
|
+
:restore_from_bucket => "your-bucket",
|
34
|
+
:restore_from_bucket_subdir => "database",
|
35
|
+
|
36
|
+
# S3 bucket and "subdir" used by the ec2onrails:db:archive task
|
37
|
+
# This does not affect the automatic backup of your MySQL db to S3, it's
|
38
|
+
# just for manually archiving a db snapshot to a different bucket if
|
39
|
+
# desired.
|
40
|
+
# NOTE: this only applies if you are not using EBS
|
41
|
+
:archive_to_bucket => "your-other-bucket",
|
42
|
+
:archive_to_bucket_subdir => "db-archive/#{Time.new.strftime('%Y-%m-%d--%H-%M-%S')}",
|
43
|
+
|
44
|
+
# Set a root password for MySQL. Run "cap ec2onrails:db:set_root_password"
|
45
|
+
# to enable this. This is optional, and after doing this the
|
46
|
+
# ec2onrails:db:drop task won't work, but be aware that MySQL accepts
|
47
|
+
# connections on the public network interface (you should block the MySQL
|
48
|
+
# port with the firewall anyway).
|
49
|
+
# If you don't care about setting the mysql root password then remove this.
|
50
|
+
:mysql_root_password => "your-mysql-root-password",
|
51
|
+
|
52
|
+
# Any extra Ubuntu packages to install if desired
|
53
|
+
# If you don't want to install extra packages then remove this.
|
54
|
+
:packages => ["logwatch", "imagemagick"],
|
55
|
+
|
56
|
+
# Any extra RubyGems to install if desired: can be "gemname" or if a
|
57
|
+
# particular version is desired "gemname -v 1.0.1"
|
58
|
+
# If you don't want to install extra rubygems then remove this
|
59
|
+
# NOTE: if you are using rails 2.1, ec2onrails calls 'sudo rake gem:install',
|
60
|
+
# which will install gems defined in your rails configuration
|
61
|
+
:rubygems => ["rmagick", "rfacebook -v 0.9.7"],
|
62
|
+
|
63
|
+
# extra security measures are taken if this is true, BUT it makes initial
|
64
|
+
# experimentation and setup a bit tricky. For example, if you do not
|
65
|
+
# have your ssh keys setup correctly, you will be locked out of your
|
66
|
+
# server after 3 attempts for upto 3 months.
|
67
|
+
:harden_server => false,
|
68
|
+
|
69
|
+
#if you want to harden the server, or setup email signing, you will need to set the domain
|
70
|
+
#if you use Capistrano's multistage extension (recommended!), you can add a line like this to your
|
71
|
+
#environment specific file:
|
72
|
+
# ec2onrails_config[:service_domain] = 'staging.mydomain.com'
|
73
|
+
:service_domain => nil,
|
74
|
+
|
75
|
+
# Set the server timezone. run "cap -e ec2onrails:server:set_timezone" for
|
76
|
+
# details
|
77
|
+
:timezone => "UTC",
|
78
|
+
|
79
|
+
# Files to deploy to the server (they'll be owned by root). It's intended
|
80
|
+
# mainly for customized config files for new packages installed via the
|
81
|
+
# ec2onrails:server:install_packages task. Subdirectories and files inside
|
82
|
+
# here will be placed in the same structure relative to the root of the
|
83
|
+
# server's filesystem.
|
84
|
+
# If you don't need to deploy customized config files to the server then
|
85
|
+
# remove this.
|
86
|
+
:server_config_files_root => "../server_configs",
|
87
|
+
|
88
|
+
# If config files are deployed, some services might need to be restarted.
|
89
|
+
# If you don't need to deploy customized config files to the server then
|
90
|
+
# remove this.
|
91
|
+
:services_to_restart => %w(postfix sysklogd),
|
92
|
+
|
93
|
+
# Set an email address to forward admin mail messages to. If you don't
|
94
|
+
# want to receive mail from the server (e.g. monit alert messages) then
|
95
|
+
# remove this.
|
96
|
+
:mail_forward_address => "you@yourdomain.com",
|
97
|
+
|
98
|
+
# Set this if you want SSL to be enabled on the web server. The SSL cert
|
99
|
+
# and key files need to exist on the server, The cert file should be in
|
100
|
+
# /etc/ssl/certs/default.pem and the key file should be in
|
101
|
+
# /etc/ssl/private/default.key (see :server_config_files_root).
|
102
|
+
:enable_ssl => true
|
103
|
+
}
|
data/examples/s3.yml
ADDED
data/lib/ec2onrails.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# This file is part of EC2 on Rails.
|
2
|
+
# http://rubyforge.org/projects/ec2onrails/
|
3
|
+
#
|
4
|
+
# Copyright 2007 Paul Dowman, http://pauldowman.com/
|
5
|
+
#
|
6
|
+
# EC2 on Rails is free software; you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation; either version 2 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# EC2 on Rails is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
|
19
|
+
|
20
|
+
$:.unshift File.dirname(__FILE__)
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Ec2onrails
|
2
|
+
module CapistranoUtils
|
3
|
+
def run_local(command)
|
4
|
+
result = system command
|
5
|
+
raise("error: #{$?}") unless result
|
6
|
+
end
|
7
|
+
|
8
|
+
def run_init_script(script, arg)
|
9
|
+
# TODO only restart a service if it's already started.
|
10
|
+
# Aside from being smarter and more efficient, This will make sure we
|
11
|
+
# aren't starting a service that shouldn't be started for the current
|
12
|
+
# roles (e.g. don't start nginx when we're not in the web role)
|
13
|
+
# How? Maybe need another param with the process name?
|
14
|
+
sudo "/etc/init.d/#{script} #{arg}"
|
15
|
+
end
|
16
|
+
|
17
|
+
# return hostnames for the role named role_sym that has the specified options
|
18
|
+
def hostnames_for_role(role_sym, options = {})
|
19
|
+
role = roles[role_sym]
|
20
|
+
unless role
|
21
|
+
return []
|
22
|
+
end
|
23
|
+
# make sure we match the server with all the passed in options, BUT the server can
|
24
|
+
# have additional options defined. e.g.: :primary => true and :ebs_vol_id => 'vol-1234abcd'
|
25
|
+
# but we want to select the server where :primary => true
|
26
|
+
role.select{|s|
|
27
|
+
match = true
|
28
|
+
options.each_pair{|k,v| match = false if s.options[k] != v}
|
29
|
+
}.collect{|s| s.host}
|
30
|
+
end
|
31
|
+
|
32
|
+
# Like the capture method, but does not print out error stream and swallows
|
33
|
+
# an exception if the process's exit code != 0
|
34
|
+
def quiet_capture(command, options={})
|
35
|
+
output = ""
|
36
|
+
invoke_command(command, options.merge(:once => true)) do |ch, stream, data|
|
37
|
+
case stream
|
38
|
+
when :out then output << data
|
39
|
+
# when :err then warn "[err :: #{ch[:server]}] #{data}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
ensure
|
43
|
+
return (output || '').strip
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,146 @@
|
|
1
|
+
# This file is part of EC2 on Rails.
|
2
|
+
# http://rubyforge.org/projects/ec2onrails/
|
3
|
+
#
|
4
|
+
# Copyright 2007 Paul Dowman, http://pauldowman.com/
|
5
|
+
#
|
6
|
+
# EC2 on Rails is free software; you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation; either version 2 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# EC2 on Rails is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
|
19
|
+
require 'fileutils'
|
20
|
+
include FileUtils
|
21
|
+
require 'tmpdir'
|
22
|
+
require 'pp'
|
23
|
+
require 'zlib'
|
24
|
+
require 'archive/tar/minitar'
|
25
|
+
include Archive::Tar
|
26
|
+
|
27
|
+
require 'ec2onrails/version'
|
28
|
+
require 'ec2onrails/capistrano_utils'
|
29
|
+
include Ec2onrails::CapistranoUtils
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
Dir[File.join(File.dirname(__FILE__), "recipes/*")].find_all{|x| File.file? x}.each do |recipe|
|
34
|
+
require recipe
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
Capistrano::Configuration.instance.load do
|
39
|
+
|
40
|
+
unless ec2onrails_config
|
41
|
+
raise "ec2onrails_config variable not set. (It should be a hash.)"
|
42
|
+
end
|
43
|
+
|
44
|
+
cfg = ec2onrails_config
|
45
|
+
|
46
|
+
set :ec2onrails_version, Ec2onrails::VERSION::STRING
|
47
|
+
set :deploy_to, "/mnt/app"
|
48
|
+
set :use_sudo, false
|
49
|
+
set :user, "app"
|
50
|
+
|
51
|
+
#in case any changes were made to the configs
|
52
|
+
before "deploy:cold", "ec2onrails:setup"
|
53
|
+
|
54
|
+
after "deploy:symlink", "ec2onrails:server:set_roles", "ec2onrails:server:init_services"
|
55
|
+
after "deploy:cold", "ec2onrails:db:init_backup", "ec2onrails:db:optimize", "ec2onrails:server:restrict_sudo_access"
|
56
|
+
# TODO I don't think we can do gem source -a every time because I think it adds the same repo multiple times
|
57
|
+
after "ec2onrails:server:install_gems", "ec2onrails:server:add_gem_sources"
|
58
|
+
|
59
|
+
# There's an ordering problem here. For convenience, we want to run 'rake gems:install' automatically
|
60
|
+
# on every deploy, but in the ec2onrails:setup task I want to do update_code before any other
|
61
|
+
# setup tasks, and at that point I don't want run_rails_rake_gems_install to run. So run_rails_rake_gems_install
|
62
|
+
# can't be triggered by an "after" hook on update_code.
|
63
|
+
# But users might want to have their own tasks triggered after update_code, and those tasks will
|
64
|
+
# fail if they require gems to be installed (or anything else to be set up).
|
65
|
+
#
|
66
|
+
# The best solution is to use an after hook on "deploy:symlink" or "deploy:update" instead of on
|
67
|
+
# "deploy:update_code"
|
68
|
+
on :load do
|
69
|
+
before "deploy:symlink", "ec2onrails:server:run_rails_rake_gems_install"
|
70
|
+
before "deploy:symlink", "ec2onrails:server:install_system_files"
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
namespace :ec2onrails do
|
75
|
+
desc <<-DESC
|
76
|
+
Show the AMI id's of the current images for this version of \
|
77
|
+
EC2 on Rails.
|
78
|
+
DESC
|
79
|
+
task :ami_ids do
|
80
|
+
puts "32-bit server image (US location) for EC2 on Rails #{ec2onrails_version}: #{Ec2onrails::VERSION::AMI_ID_32_BIT_US}"
|
81
|
+
puts "64-bit server image (US location) for EC2 on Rails #{ec2onrails_version}: #{Ec2onrails::VERSION::AMI_ID_64_BIT_US}"
|
82
|
+
puts "32-bit server image (EU location) for EC2 on Rails #{ec2onrails_version}: #{Ec2onrails::VERSION::AMI_ID_32_BIT_EU}"
|
83
|
+
puts "64-bit server image (EU location) for EC2 on Rails #{ec2onrails_version}: #{Ec2onrails::VERSION::AMI_ID_64_BIT_EU}"
|
84
|
+
end
|
85
|
+
|
86
|
+
desc <<-DESC
|
87
|
+
Copies the public key from the server using the external "ssh"
|
88
|
+
command because Net::SSH, which is used by Capistrano, needs it.
|
89
|
+
This will only work if you have an ssh command in the path.
|
90
|
+
If Capistrano can successfully connect to your EC2 instance you
|
91
|
+
don't need to do this. It will copy from one of the servers
|
92
|
+
at random, this can be overridden by specifying the HOST
|
93
|
+
environment variable
|
94
|
+
DESC
|
95
|
+
task :get_public_key_from_server do
|
96
|
+
host = find_servers_for_task(current_task).first.host
|
97
|
+
privkey = ssh_options[:keys][0]
|
98
|
+
pubkey = "#{privkey}.pub"
|
99
|
+
msg = <<-MSG
|
100
|
+
Your first key in ssh_options[:keys] is #{privkey}, presumably that's
|
101
|
+
your EC2 private key. The public key will be copied from the server
|
102
|
+
named '#{host}' and saved locally as #{pubkey}. Continue? [y/n]
|
103
|
+
MSG
|
104
|
+
choice = nil
|
105
|
+
while choice != "y" && choice != "n"
|
106
|
+
choice = Capistrano::CLI.ui.ask(msg).downcase
|
107
|
+
msg = "Please enter 'y' or 'n'."
|
108
|
+
end
|
109
|
+
if choice == "y"
|
110
|
+
run_local "scp -i '#{privkey}' app@#{host}:.ssh/authorized_keys #{pubkey}"
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
desc <<-DESC
|
115
|
+
Prepare a newly-started instance for a cold deploy.
|
116
|
+
DESC
|
117
|
+
task :setup do
|
118
|
+
# we now have some things being included inside the app so we deploy
|
119
|
+
# the app's code to the server before we do any other setup
|
120
|
+
server.upload_deploy_keys
|
121
|
+
deploy.setup
|
122
|
+
deploy.update_code
|
123
|
+
|
124
|
+
ec2onrails.server.allow_sudo do
|
125
|
+
server.set_timezone
|
126
|
+
server.set_mail_forward_address
|
127
|
+
server.install_packages
|
128
|
+
server.install_gems
|
129
|
+
server.run_rails_rake_gems_install
|
130
|
+
server.deploy_files # DEPRECATED, see install_system_files
|
131
|
+
server.install_system_files
|
132
|
+
server.set_roles
|
133
|
+
server.enable_ssl if cfg[:enable_ssl]
|
134
|
+
server.set_rails_env
|
135
|
+
server.restart_services
|
136
|
+
db.create
|
137
|
+
server.harden_server
|
138
|
+
db.enable_ebs
|
139
|
+
db.set_root_password
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
|
@@ -0,0 +1,366 @@
|
|
1
|
+
Capistrano::Configuration.instance.load do
|
2
|
+
cfg = ec2onrails_config
|
3
|
+
|
4
|
+
namespace :ec2onrails do
|
5
|
+
desc <<-DESC
|
6
|
+
Deploy and restore database from S3
|
7
|
+
DESC
|
8
|
+
task :restore_db_and_deploy do
|
9
|
+
db.recreate
|
10
|
+
deploy.update_code
|
11
|
+
deploy.symlink
|
12
|
+
db.restore
|
13
|
+
deploy.migrations
|
14
|
+
end
|
15
|
+
|
16
|
+
namespace :db do
|
17
|
+
desc <<-DESC
|
18
|
+
[internal] Load configuration info for the database from
|
19
|
+
config/database.yml, and start mysql (it must be running
|
20
|
+
in order to interact with it).
|
21
|
+
DESC
|
22
|
+
task :load_config do
|
23
|
+
unless hostnames_for_role(:db, :primary => true).empty?
|
24
|
+
db_config = YAML::load(ERB.new(File.read("config/database.yml")).result)[rails_env.to_s] || {}
|
25
|
+
cfg[:db_name] ||= db_config['database']
|
26
|
+
cfg[:db_user] ||= db_config['username'] || db_config['user']
|
27
|
+
cfg[:db_password] ||= db_config['password']
|
28
|
+
cfg[:db_host] ||= db_config['host']
|
29
|
+
cfg[:db_port] ||= db_config['port']
|
30
|
+
cfg[:db_socket] ||= db_config['socket']
|
31
|
+
|
32
|
+
if (cfg[:db_host].nil? || cfg[:db_host].empty?) && (cfg[:db_socket].nil? || cfg[:db_socket].empty?)
|
33
|
+
raise "ERROR: missing database config. Make sure database.yml contains a '#{rails_env}' section with either 'host: hostname' or 'socket: /var/run/mysqld/mysqld.sock'."
|
34
|
+
end
|
35
|
+
|
36
|
+
[cfg[:db_name], cfg[:db_user], cfg[:db_password]].each do |s|
|
37
|
+
if s.nil? || s.empty?
|
38
|
+
raise "ERROR: missing database config. Make sure database.yml contains a '#{rails_env}' section with a database name, user, and password."
|
39
|
+
elsif s.match(/['"]/)
|
40
|
+
raise "ERROR: database config string '#{s}' contains quotes."
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
desc <<-DESC
|
47
|
+
Create the MySQL database. Assumes there is no MySQL root \
|
48
|
+
password. To create a MySQL root password create a task that's run \
|
49
|
+
after this task using an after hook.
|
50
|
+
DESC
|
51
|
+
task :create, :roles => :db do
|
52
|
+
on_rollback { drop }
|
53
|
+
load_config
|
54
|
+
start
|
55
|
+
puts " * Pausing to give MySQL some time to start up..."
|
56
|
+
sleep 20
|
57
|
+
|
58
|
+
run %{mysql -u root -e "drop database if exists test; flush privileges;"}
|
59
|
+
# removing anonymous mysql accounts
|
60
|
+
run %{mysql -u root -D mysql -e "delete from db where User = ''; flush privileges;"}
|
61
|
+
run %{mysql -u root -D mysql -e "delete from user where User = ''; flush privileges;"}
|
62
|
+
|
63
|
+
# qoting of database names allows special characters eg (the-database-name)
|
64
|
+
# the quotes need to be double escaped. Once for capistrano and once for the host shell
|
65
|
+
run %{mysql -u root -e "create database if not exists \\`#{cfg[:db_name]}\\`;"}
|
66
|
+
run %{mysql -u root -e "grant all on \\`#{cfg[:db_name]}\\`.* to '#{cfg[:db_user]}'@'%' identified by '#{cfg[:db_password]}';"}
|
67
|
+
run %{mysql -u root -e "grant reload on *.* to '#{cfg[:db_user]}'@'%' identified by '#{cfg[:db_password]}';"}
|
68
|
+
run %{mysql -u root -e "grant super on *.* to '#{cfg[:db_user]}'@'%' identified by '#{cfg[:db_password]}';"}
|
69
|
+
end
|
70
|
+
|
71
|
+
desc <<-DESC
|
72
|
+
Move the MySQL database to Amazon's Elastic Block Store (EBS), \
|
73
|
+
which is a persistant data store for the cloud.
|
74
|
+
OPTIONAL PARAMETERS:
|
75
|
+
* SIZE: Pass in a number representing the GB's to hold, like 10. \
|
76
|
+
It will default to 10 gigs.
|
77
|
+
* VOLUME_ID: The volume_id to use for the mysql database
|
78
|
+
NOTE: keep track of the volume ID, as you'll want to keep this for your \
|
79
|
+
records and probably add it to the :db role in your deploy.rb file \
|
80
|
+
(see the ec2onrails sample deploy.rb file for additional information)
|
81
|
+
DESC
|
82
|
+
task :enable_ebs, :roles => :db, :only => { :primary => true } do
|
83
|
+
# based off of Eric's work:
|
84
|
+
# http://developer.amazonwebservices.com/connect/entry.jspa?externalID=1663&categoryID=100
|
85
|
+
#
|
86
|
+
# EXPLAINATION:
|
87
|
+
# There is a lot going on here! At the end, the setup should be:
|
88
|
+
# * create EBS volume if run outside of the ec2onrails:setup and
|
89
|
+
# VOLUME_ID is not passed in when the cap task is called
|
90
|
+
# * EBS volume attached to /dev/sdh
|
91
|
+
# * format to xfs if new or do a xfs_check if previously existed
|
92
|
+
# * mounted on /var/local and update /etc/fstab
|
93
|
+
# * move /mnt/mysql_data -> /var/local/mysql_data
|
94
|
+
# * move /mnt/log/mysql -> /var/local/log/mysql
|
95
|
+
# * change mysql configs by writing /etc/mysql/conf.d/mysql-ec2-ebs.cnf
|
96
|
+
# * keep a copy of the mysql configs with the EBS volume, and if that volume is hooked into
|
97
|
+
# another instance, make sure the mysql configs that go with that volume are symlinked to /etc/mysql
|
98
|
+
# * update the file locations of the mysql binary logs in /mnt/log/mysql/mysql-bin.index
|
99
|
+
# * symlink the moved folders to their old position... makes the move to EBS transparent
|
100
|
+
# * Amazon doesn't contain EBS information in the meta-data API (yet). So write
|
101
|
+
# /etc/ec2onrails/ebs_info.yml
|
102
|
+
# to contain the meta-data information that we need
|
103
|
+
#
|
104
|
+
# DESIGN CONSIDERATIONS
|
105
|
+
# * only moving mysql data to EBS. seems the most obvious, and if we move over other components
|
106
|
+
# we will have to share that bandwidth (1 Gbps pipe to SAN). So limiting to what we really need
|
107
|
+
# * not moving all mysql logic over (tmp scratch space stays local). Again, this is to limit
|
108
|
+
# unnecessary bandwidth usage, PLUS, we are charged per million IO to EBS
|
109
|
+
#
|
110
|
+
# TODO:
|
111
|
+
# * make sure if we have a predefined ebs_vol_id, that we error out with a nice msg IF the zones do not match
|
112
|
+
# * can we move more of the mysql cache files back to the local disk and off of EBS, like the innodb table caches?
|
113
|
+
# * right now we force this task to only be run on one server; that works for db :primary => true
|
114
|
+
# But what is the best way to make this work if it needs to setup multiple servers (like db slaves)?
|
115
|
+
# I need to figure out how to do a direct mapping from a server definition to a ebs_vol_id
|
116
|
+
# * when we enable slaves and we setup ebs volumes on them, make it transparent to the user.
|
117
|
+
# have the slave create a snapshot of the db.master volume, and then use that to mount from
|
118
|
+
# * need to do a rollback that if the volume is created but something fails, lets uncreate it?
|
119
|
+
# carefull though! If it fails towards the end when information is copied over, it could cause information
|
120
|
+
# to be lost!
|
121
|
+
#
|
122
|
+
|
123
|
+
mysql_dir_root = '/var/local'
|
124
|
+
block_mnt = '/dev/sdh'
|
125
|
+
servers = find_servers_for_task(current_task)
|
126
|
+
|
127
|
+
if servers.empty?
|
128
|
+
raise Capistrano::NoMatchingServersError, "`#{task.fully_qualified_name}' is only run for servers matching #{task.options.inspect}, but no servers matched"
|
129
|
+
elsif servers.size > 1
|
130
|
+
raise Capistrano::Error, "`#{task.fully_qualified_name}' is can only be run on one server, not #{server.size}"
|
131
|
+
end
|
132
|
+
|
133
|
+
vol_id = ENV['VOLUME_ID'] || servers.first.options[:ebs_vol_id]
|
134
|
+
|
135
|
+
#HACK! capistrano doesn't allow arguments to be passed in if we call this task as a method, like 'db.enable_ebs'
|
136
|
+
# the places where we do call it like that, we don't want to force a move to ebs, so....
|
137
|
+
# if the call frame is > 1 (ie, another task called it), do NOT force the ebs move
|
138
|
+
no_force = task_call_frames.size > 1
|
139
|
+
prev_created = !(vol_id.nil? || vol_id.empty?)
|
140
|
+
#no vol_id was passed in, but perhaps it is already mounted...?
|
141
|
+
prev_created = true if !quiet_capture("mount | grep -inr '#{mysql_dir_root}' || echo ''").empty?
|
142
|
+
|
143
|
+
unless no_force && (vol_id.nil? || vol_id.empty?)
|
144
|
+
zone = quiet_capture("/usr/local/ec2onrails/bin/ec2_meta_data -key 'placement/availability-zone'")
|
145
|
+
instance_id = quiet_capture("/usr/local/ec2onrails/bin/ec2_meta_data -key 'instance-id'")
|
146
|
+
|
147
|
+
unless prev_created
|
148
|
+
puts "creating new ebs volume...."
|
149
|
+
size = ENV["SIZE"] || "10"
|
150
|
+
cmd = "ec2-create-volume -s #{size} -z #{zone} 2>&1"
|
151
|
+
puts "running: #{cmd}"
|
152
|
+
output = `#{cmd}`
|
153
|
+
puts output
|
154
|
+
vol_id = (output =~ /^VOLUME\t(.+?)\t/ && $1)
|
155
|
+
puts "NOTE: remember that vol_id"
|
156
|
+
sleep(2)
|
157
|
+
end
|
158
|
+
vol_id.strip! if vol_id
|
159
|
+
if quiet_capture("mount | grep -inr '#{block_mnt}' || echo ''").empty?
|
160
|
+
cmd = "ec2-attach-volume -d #{block_mnt} -i #{instance_id} #{vol_id} 2>&1"
|
161
|
+
puts "running: #{cmd}"
|
162
|
+
output = `#{cmd}`
|
163
|
+
puts output
|
164
|
+
if output =~ /Client.InvalidVolume.ZoneMismatch/i
|
165
|
+
raise Exception, "The volume you are trying to attach does not reside in the zone of your instance. Stopping!"
|
166
|
+
end
|
167
|
+
while !system( "ec2-describe-volumes | grep #{vol_id} | grep attached" )
|
168
|
+
puts "Waiting for #{vol_id} to be attached..."
|
169
|
+
sleep 1
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
ec2onrails.server.allow_sudo do
|
174
|
+
# try to format the volume... if it is already formatted, lets run a check on
|
175
|
+
# it to make sure it is ok, and then continue on
|
176
|
+
# if errors, the device is busy...something else is going on here and it is already mounted... skip!
|
177
|
+
if prev_created
|
178
|
+
# Stop the db (mysql server) for cases where this is being run after the original run
|
179
|
+
# If EBS partiion is already mounted and being used by mysql, it will fail when umount is run
|
180
|
+
god_status = quiet_capture("sudo god status")
|
181
|
+
god_status = god_status.empty? ? {} : YAML::load(god_status)
|
182
|
+
start_stop_db = false
|
183
|
+
start_stop_db = god_status['db_primary']['mysql'] == 'up'
|
184
|
+
if start_stop_db
|
185
|
+
stop
|
186
|
+
puts "Waiting for mysql to stop"
|
187
|
+
sleep(10)
|
188
|
+
end
|
189
|
+
quiet_capture("sudo umount #{mysql_dir_root}") #unmount if need to
|
190
|
+
puts "Checking if the filesystem needs to be created (if you created #{vol_id} yourself)"
|
191
|
+
existing = quiet_capture( "mkfs.xfs /dev/sdh", :via => 'sudo' ).match( /existing filesystem/ )
|
192
|
+
sudo "xfs_check #{block_mnt}"
|
193
|
+
# Restart the db if it
|
194
|
+
start if start_stop_db && existing
|
195
|
+
else
|
196
|
+
sudo "mkfs.xfs #{block_mnt}"
|
197
|
+
end
|
198
|
+
|
199
|
+
# if not added to /etc/fstab, lets do so
|
200
|
+
sudo "sh -c \"grep -iqn '#{mysql_dir_root}' /etc/fstab || echo '#{block_mnt} #{mysql_dir_root} xfs noatime 0 0' >> /etc/fstab\""
|
201
|
+
sudo "mkdir -p #{mysql_dir_root}"
|
202
|
+
#if not already mounted, lets mount it
|
203
|
+
sudo "sh -c \"mount | grep -iqn '#{mysql_dir_root}' || mount '#{mysql_dir_root}'\""
|
204
|
+
|
205
|
+
#ok, now lets move the mysql stuff off of /mnt -> mysql_dir_root
|
206
|
+
stop rescue nil #already stopped
|
207
|
+
sudo "mkdir -p #{mysql_dir_root}/log"
|
208
|
+
#move the data over, but keep a symlink to the new location for backwards compatibility
|
209
|
+
#and do not do it if /mnt/mysql_data has already been moved
|
210
|
+
quiet_capture("sudo sh -c 'test ! -d #{mysql_dir_root}/mysql_data && mv /mnt/mysql_data #{mysql_dir_root}/'")
|
211
|
+
sudo "mv /mnt/mysql_data /mnt/mysql_data_old 2>/dev/null || echo"
|
212
|
+
sudo "ln -fs #{mysql_dir_root}/mysql_data /mnt/mysql_data"
|
213
|
+
|
214
|
+
#but keep the tmpdir on mnt
|
215
|
+
sudo "sh -c 'mkdir -p /mnt/tmp/mysql && chown mysql:mysql /mnt/tmp/mysql'"
|
216
|
+
#move the logs over, but keep a symlink to the new location for backwards compatibility
|
217
|
+
#and do not do it if the logs have already been moved
|
218
|
+
quiet_capture("sudo sh -c 'test ! -d #{mysql_dir_root}/log/mysql_data && mv /mnt/log/mysql #{mysql_dir_root}/log/'")
|
219
|
+
sudo "ln -fs #{mysql_dir_root}/log/mysql /mnt/log/mysql"
|
220
|
+
quiet_capture("sudo sh -c \"test -f #{mysql_dir_root}/log/mysql/mysql-bin.index && \
|
221
|
+
perl -pi -e 's%/mnt/log/%#{mysql_dir_root}/log/%' #{mysql_dir_root}/log/mysql/mysql-bin.index\"") rescue false
|
222
|
+
|
223
|
+
if quiet_capture("test -d /var/local/etc/mysql && echo 'yes'").empty?
|
224
|
+
txt = <<-FILE
|
225
|
+
[mysqld]
|
226
|
+
datadir = #{mysql_dir_root}/mysql_data
|
227
|
+
tmpdir = /mnt/tmp/mysql
|
228
|
+
log_bin = #{mysql_dir_root}/log/mysql/mysql-bin.log
|
229
|
+
log_slow_queries = #{mysql_dir_root}/log/mysql/mysql-slow.log
|
230
|
+
FILE
|
231
|
+
put txt, '/tmp/mysql-ec2-ebs.cnf'
|
232
|
+
sudo 'mv /tmp/mysql-ec2-ebs.cnf /etc/mysql/conf.d/mysql-ec2-ebs.cnf'
|
233
|
+
|
234
|
+
#keep a copy
|
235
|
+
sudo "rsync -aR /etc/mysql #{mysql_dir_root}/"
|
236
|
+
end
|
237
|
+
# lets use the mysql configs on the EBS volume
|
238
|
+
sudo "mv /etc/mysql /etc/mysql.orig 2>/dev/null"
|
239
|
+
sudo "ln -sf #{mysql_dir_root}/etc/mysql /etc/mysql"
|
240
|
+
|
241
|
+
#just put a README on the drive so we know what this volume is for!
|
242
|
+
txt = <<-FILE
|
243
|
+
This volume is setup to be used by Ec2onRails in conjunction with Amazon's EBS, for primary MySql database persistence.
|
244
|
+
RAILS_ENV: #{fetch(:rails_env, 'undefined')}
|
245
|
+
DOMAIN: #{fetch(:domain, 'undefined')}
|
246
|
+
|
247
|
+
Modify this volume at your own risk
|
248
|
+
FILE
|
249
|
+
|
250
|
+
put txt, "/tmp/VOLUME-README"
|
251
|
+
sudo "mv /tmp/VOLUME-README #{mysql_dir_root}/VOLUME-README"
|
252
|
+
sudo "touch /etc/ec2onrails/ebs_info.yml"
|
253
|
+
ebs_info = quiet_capture("cat /etc/ec2onrails/ebs_info.yml")
|
254
|
+
|
255
|
+
ebs_info = ebs_info.empty? ? {} : YAML::load(ebs_info)
|
256
|
+
ebs_info[mysql_dir_root] = {'block_loc' => block_mnt, 'volume_id' => vol_id}
|
257
|
+
put(ebs_info.to_yaml, "/tmp/ebs_info.yml")
|
258
|
+
sudo "mv /tmp/ebs_info.yml /etc/ec2onrails/ebs_info.yml"
|
259
|
+
#lets start it back up
|
260
|
+
start
|
261
|
+
end #end of sudo
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
|
266
|
+
desc <<-DESC
|
267
|
+
[internal] Make sure the MySQL server has been started, just in case the db role
|
268
|
+
hasn't been set, e.g. when called from ec2onrails:setup.
|
269
|
+
(But don't enable monitoring on it.)
|
270
|
+
DESC
|
271
|
+
task :start, :roles => :db do
|
272
|
+
sudo "god start db_primary"
|
273
|
+
end
|
274
|
+
|
275
|
+
task :stop, :roles => :db do
|
276
|
+
sudo "god stop db_primary"
|
277
|
+
end
|
278
|
+
|
279
|
+
|
280
|
+
desc <<-DESC
|
281
|
+
Drop the MySQL database. Assumes there is no MySQL root \
|
282
|
+
password. If there is a MySQL root password, create a task that removes \
|
283
|
+
it and run that task before this one using a before hook.
|
284
|
+
DESC
|
285
|
+
task :drop, :roles => :db do
|
286
|
+
load_config
|
287
|
+
run %{mysql -u root -e "drop database if exists \\`#{cfg[:db_name]}\\`;"}
|
288
|
+
end
|
289
|
+
|
290
|
+
desc <<-DESC
|
291
|
+
db:drop and db:create.
|
292
|
+
DESC
|
293
|
+
task :recreate, :roles => :db do
|
294
|
+
drop
|
295
|
+
create
|
296
|
+
end
|
297
|
+
|
298
|
+
desc <<-DESC
|
299
|
+
Set a root password for MySQL, using the variable mysql_root_password \
|
300
|
+
if it is set. If this is done db:drop won't work.
|
301
|
+
DESC
|
302
|
+
task :set_root_password, :roles => :db do
|
303
|
+
if cfg[:mysql_root_password]
|
304
|
+
begin
|
305
|
+
run %{mysql -u root -e "UPDATE mysql.user SET Password=PASSWORD('#{cfg[:mysql_root_password]}') WHERE User='root'; FLUSH PRIVILEGES;"}
|
306
|
+
rescue Exception => e
|
307
|
+
#most likely because the password was already set
|
308
|
+
#in that case this is fine to swallow the error because the task is 'set' db password, not reset it.... we would have to know
|
309
|
+
#what the old root password was
|
310
|
+
end
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
314
|
+
desc <<-DESC
|
315
|
+
Dump the MySQL database to ebs (if enabled) or the S3 bucket specified by \
|
316
|
+
ec2onrails_config[:archive_to_bucket]. The filename will be \
|
317
|
+
"database-archive/<timestamp>/dump.sql.gz".
|
318
|
+
DESC
|
319
|
+
task :archive, :roles => :db do
|
320
|
+
run "/usr/local/ec2onrails/bin/backup_app_db --bucket #{cfg[:archive_to_bucket]} --dir #{cfg[:archive_to_bucket_subdir]}"
|
321
|
+
end
|
322
|
+
|
323
|
+
desc <<-DESC
|
324
|
+
Restore the MySQL database from the S3 bucket specified by \
|
325
|
+
ec2onrails_config[:restore_from_bucket]. The archive filename is \
|
326
|
+
expected to be the default, "mysqldump.sql.gz".
|
327
|
+
DESC
|
328
|
+
task :restore, :roles => :db do
|
329
|
+
run "/usr/local/ec2onrails/bin/restore_app_db --bucket #{cfg[:restore_from_bucket]} --dir #{cfg[:restore_from_bucket_subdir]}"
|
330
|
+
end
|
331
|
+
|
332
|
+
desc <<-DESC
|
333
|
+
[internal] Initialize the default backup folder on S3 (i.e. do a full
|
334
|
+
backup of the newly-created db so the automatic incremental backups
|
335
|
+
make sense). NOTE: Only of use if you do not have ebs enabled
|
336
|
+
DESC
|
337
|
+
task :init_backup, :roles => :db do
|
338
|
+
server.allow_sudo do
|
339
|
+
sudo "/usr/local/ec2onrails/bin/backup_app_db --reset"
|
340
|
+
end
|
341
|
+
end
|
342
|
+
|
343
|
+
# do NOT run if the flag does not exist. This is placed by a startup script
|
344
|
+
# and it is only run on the first-startup. This means after the db has been
|
345
|
+
# optimized, this task will not work again.
|
346
|
+
#
|
347
|
+
# Of course you can overload it or call the file directly
|
348
|
+
task :optimize, :roles => :db do
|
349
|
+
if !quiet_capture("test -e /tmp/optimize_db_flag && echo 'file exists'").empty?
|
350
|
+
ec2onrails.server.allow_sudo do
|
351
|
+
begin
|
352
|
+
sudo "/usr/local/ec2onrails/bin/optimize_mysql"
|
353
|
+
ensure
|
354
|
+
sudo "rm -rf /tmp/optimize_db_flag" #remove so we cannot run again
|
355
|
+
end
|
356
|
+
end
|
357
|
+
else
|
358
|
+
puts "skipping as it looks like this task has already been run"
|
359
|
+
end
|
360
|
+
end
|
361
|
+
|
362
|
+
end
|
363
|
+
|
364
|
+
end
|
365
|
+
end
|
366
|
+
|