gigpark-ec2onrails 0.9.10.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (161) hide show
  1. data/CHANGELOG +190 -0
  2. data/COPYING +339 -0
  3. data/Manifest +160 -0
  4. data/README.textile +233 -0
  5. data/Rakefile +31 -0
  6. data/TODO +104 -0
  7. data/ec2onrails.gemspec +46 -0
  8. data/echoe_config.rb +27 -0
  9. data/examples/Capfile +3 -0
  10. data/examples/deploy.rb +103 -0
  11. data/examples/s3.yml +9 -0
  12. data/lib/ec2onrails.rb +20 -0
  13. data/lib/ec2onrails/capistrano_utils.rb +47 -0
  14. data/lib/ec2onrails/recipes.rb +146 -0
  15. data/lib/ec2onrails/recipes/db.rb +366 -0
  16. data/lib/ec2onrails/recipes/deploy.rb +26 -0
  17. data/lib/ec2onrails/recipes/server.rb +517 -0
  18. data/lib/ec2onrails/version.rb +29 -0
  19. data/server/build +74 -0
  20. data/server/files/etc/README +7 -0
  21. data/server/files/etc/aliases +5 -0
  22. data/server/files/etc/cron.d/ec2onrails +16 -0
  23. data/server/files/etc/cron.daily/app +31 -0
  24. data/server/files/etc/cron.daily/logrotate_post +25 -0
  25. data/server/files/etc/cron.hourly/app +31 -0
  26. data/server/files/etc/cron.monthly/app +31 -0
  27. data/server/files/etc/cron.weekly/app +31 -0
  28. data/server/files/etc/default/varnish +33 -0
  29. data/server/files/etc/default/varnishncsa +11 -0
  30. data/server/files/etc/denyhosts.conf +628 -0
  31. data/server/files/etc/dpkg/dpkg.cfg +13 -0
  32. data/server/files/etc/ec2onrails/rails_env +1 -0
  33. data/server/files/etc/ec2onrails/roles.yml +5 -0
  34. data/server/files/etc/environment +2 -0
  35. data/server/files/etc/event.d/god +8 -0
  36. data/server/files/etc/god/db_primary.god +16 -0
  37. data/server/files/etc/god/dkim_filter.god +17 -0
  38. data/server/files/etc/god/master.conf +40 -0
  39. data/server/files/etc/god/memcache.god +15 -0
  40. data/server/files/etc/god/notifications.god +11 -0
  41. data/server/files/etc/god/proxy.god +40 -0
  42. data/server/files/etc/god/system.god +37 -0
  43. data/server/files/etc/god/web.god +23 -0
  44. data/server/files/etc/init.d/ec2-every-startup +29 -0
  45. data/server/files/etc/init.d/ec2-first-startup +37 -0
  46. data/server/files/etc/init.d/nginx +78 -0
  47. data/server/files/etc/logrotate.d/nginx +10 -0
  48. data/server/files/etc/logrotate.d/rails +8 -0
  49. data/server/files/etc/logrotate.d/varnish +14 -0
  50. data/server/files/etc/memcached.conf +47 -0
  51. data/server/files/etc/motd.tail +13 -0
  52. data/server/files/etc/mysql/my.cnf +152 -0
  53. data/server/files/etc/nginx/conf.d/custom.conf +1 -0
  54. data/server/files/etc/nginx/nginx.conf.erb +152 -0
  55. data/server/files/etc/postfix/main.cf +4 -0
  56. data/server/files/etc/ssh/sshd_config +96 -0
  57. data/server/files/etc/sudoers +31 -0
  58. data/server/files/etc/syslog.conf +63 -0
  59. data/server/files/etc/varnish/default.vcl.erb +140 -0
  60. data/server/files/usr/local/ec2onrails/COPYING +339 -0
  61. data/server/files/usr/local/ec2onrails/bin/archive_file +44 -0
  62. data/server/files/usr/local/ec2onrails/bin/backup_app_db +160 -0
  63. data/server/files/usr/local/ec2onrails/bin/backup_dir +89 -0
  64. data/server/files/usr/local/ec2onrails/bin/ec2_meta_data +80 -0
  65. data/server/files/usr/local/ec2onrails/bin/exec_runner +76 -0
  66. data/server/files/usr/local/ec2onrails/bin/in_role +33 -0
  67. data/server/files/usr/local/ec2onrails/bin/init_services +43 -0
  68. data/server/files/usr/local/ec2onrails/bin/install_system_files +56 -0
  69. data/server/files/usr/local/ec2onrails/bin/optimize_mysql +346 -0
  70. data/server/files/usr/local/ec2onrails/bin/public-hostname +24 -0
  71. data/server/files/usr/local/ec2onrails/bin/rails_env +33 -0
  72. data/server/files/usr/local/ec2onrails/bin/rebundle +62 -0
  73. data/server/files/usr/local/ec2onrails/bin/restore_app_db +58 -0
  74. data/server/files/usr/local/ec2onrails/bin/set_rails_env +36 -0
  75. data/server/files/usr/local/ec2onrails/bin/set_roles +36 -0
  76. data/server/files/usr/local/ec2onrails/bin/uninstall_system_files +34 -0
  77. data/server/files/usr/local/ec2onrails/config +30 -0
  78. data/server/files/usr/local/ec2onrails/lib/aws_helper.rb +75 -0
  79. data/server/files/usr/local/ec2onrails/lib/god_helper.rb +84 -0
  80. data/server/files/usr/local/ec2onrails/lib/mysql_helper.rb +100 -0
  81. data/server/files/usr/local/ec2onrails/lib/roles_helper.rb +156 -0
  82. data/server/files/usr/local/ec2onrails/lib/s3_helper.rb +116 -0
  83. data/server/files/usr/local/ec2onrails/lib/system_files_helper.rb +110 -0
  84. data/server/files/usr/local/ec2onrails/lib/system_files_manifest.rb +107 -0
  85. data/server/files/usr/local/ec2onrails/lib/utils.rb +26 -0
  86. data/server/files/usr/local/ec2onrails/lib/vendor/ini.rb +268 -0
  87. data/server/files/usr/local/ec2onrails/startup-scripts/every-startup/README +5 -0
  88. data/server/files/usr/local/ec2onrails/startup-scripts/every-startup/create-mysqld-pid-dir +26 -0
  89. data/server/files/usr/local/ec2onrails/startup-scripts/first-startup/README +5 -0
  90. data/server/files/usr/local/ec2onrails/startup-scripts/first-startup/create-dirs +45 -0
  91. data/server/files/usr/local/ec2onrails/startup-scripts/first-startup/generate-default-web-cert-and-key +49 -0
  92. data/server/files/usr/local/ec2onrails/startup-scripts/first-startup/get-hostname +27 -0
  93. data/server/files/usr/local/ec2onrails/startup-scripts/first-startup/misc +27 -0
  94. data/server/files/usr/local/ec2onrails/startup-scripts/first-startup/prepare-mysql-data-dir +24 -0
  95. data/server/files/usr/local/ec2onrails/startup-scripts/first-startup/setup-credentials +32 -0
  96. data/server/files/usr/local/ec2onrails/startup-scripts/first-startup/setup-file-permissions +30 -0
  97. data/server/rakefile-wrapper +26 -0
  98. data/server/rakefile.rb +267 -0
  99. data/test/autobench.conf +60 -0
  100. data/test/spec/lib/s3_helper_spec.rb +154 -0
  101. data/test/spec/lib/s3_old.yml +3 -0
  102. data/test/spec/lib/system_files_manifest_spec.rb +122 -0
  103. data/test/spec/test_files/system_files1/_manifest +13 -0
  104. data/test/spec/test_files/system_files1/test1 +0 -0
  105. data/test/spec/test_files/system_files1/test2 +0 -0
  106. data/test/spec/test_files/system_files1/testfolder/test3 +0 -0
  107. data/test/spec/test_files/system_files2/_manifest +2 -0
  108. data/test/spec/test_files/system_files2/test1 +0 -0
  109. data/test/spec/test_files/system_files2/test2 +0 -0
  110. data/test/spec/test_files/system_files2/testfolder/test3 +0 -0
  111. data/test/spec/test_files/test2 +0 -0
  112. data/test/test_app/Capfile +3 -0
  113. data/test/test_app/README +243 -0
  114. data/test/test_app/Rakefile +10 -0
  115. data/test/test_app/app/controllers/application_controller.rb +10 -0
  116. data/test/test_app/app/controllers/db_fast_controller.rb +6 -0
  117. data/test/test_app/app/controllers/fast_controller.rb +5 -0
  118. data/test/test_app/app/controllers/slow_controller.rb +6 -0
  119. data/test/test_app/app/controllers/very_slow_controller.rb +6 -0
  120. data/test/test_app/app/helpers/application_helper.rb +3 -0
  121. data/test/test_app/config/boot.rb +110 -0
  122. data/test/test_app/config/database.yml +24 -0
  123. data/test/test_app/config/deploy.rb +22 -0
  124. data/test/test_app/config/ec2onrails/config.rb +5 -0
  125. data/test/test_app/config/environment.rb +41 -0
  126. data/test/test_app/config/environments/development.rb +17 -0
  127. data/test/test_app/config/environments/production.rb +28 -0
  128. data/test/test_app/config/environments/test.rb +28 -0
  129. data/test/test_app/config/initializers/backtrace_silencers.rb +7 -0
  130. data/test/test_app/config/initializers/inflections.rb +10 -0
  131. data/test/test_app/config/initializers/mime_types.rb +5 -0
  132. data/test/test_app/config/initializers/new_rails_defaults.rb +19 -0
  133. data/test/test_app/config/initializers/session_store.rb +15 -0
  134. data/test/test_app/config/locales/en.yml +5 -0
  135. data/test/test_app/config/routes.rb +43 -0
  136. data/test/test_app/doc/README_FOR_APP +2 -0
  137. data/test/test_app/public/404.html +30 -0
  138. data/test/test_app/public/422.html +30 -0
  139. data/test/test_app/public/500.html +30 -0
  140. data/test/test_app/public/favicon.ico +0 -0
  141. data/test/test_app/public/images/rails.png +0 -0
  142. data/test/test_app/public/index.html +275 -0
  143. data/test/test_app/public/javascripts/application.js +2 -0
  144. data/test/test_app/public/javascripts/controls.js +963 -0
  145. data/test/test_app/public/javascripts/dragdrop.js +973 -0
  146. data/test/test_app/public/javascripts/effects.js +1128 -0
  147. data/test/test_app/public/javascripts/prototype.js +4320 -0
  148. data/test/test_app/public/robots.txt +5 -0
  149. data/test/test_app/script/about +4 -0
  150. data/test/test_app/script/console +3 -0
  151. data/test/test_app/script/dbconsole +3 -0
  152. data/test/test_app/script/destroy +3 -0
  153. data/test/test_app/script/generate +3 -0
  154. data/test/test_app/script/performance/benchmarker +3 -0
  155. data/test/test_app/script/performance/profiler +3 -0
  156. data/test/test_app/script/plugin +3 -0
  157. data/test/test_app/script/runner +3 -0
  158. data/test/test_app/script/server +3 -0
  159. data/test/test_app/test/performance/browsing_test.rb +9 -0
  160. data/test/test_app/test/test_helper.rb +38 -0
  161. metadata +266 -0
@@ -0,0 +1,24 @@
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
+ # This script prints the instance's public hostname
23
+
24
+ echo `curl -s http://169.254.169.254/latest/meta-data/public-hostname`
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/ruby
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
+ # This script runs a command with RAILS_ENV set to current value for
23
+ # this instance. If a command isn't given as an argument it simply
24
+ # prints the value of RAILS_ENV
25
+
26
+ require "yaml"
27
+ require "#{File.dirname(__FILE__)}/../lib/utils"
28
+
29
+ if ARGV.any?
30
+ exec "env RAILS_ENV=#{Ec2onrails::Utils.rails_env} #{ARGV.join(' ')}"
31
+ else
32
+ puts Ec2onrails::Utils.rails_env
33
+ end
@@ -0,0 +1,62 @@
1
+ #!/bin/bash
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
+ fail() {
23
+ echo "`basename $0`: ERROR: $1"
24
+ exit 1
25
+ }
26
+
27
+ if [ `whoami` != 'root' ] ; then
28
+ fail "This script must be run as root, use 'sudo $0'".
29
+ fi
30
+
31
+ . "/usr/local/ec2onrails/config"
32
+
33
+ TIMESTAMP="`date '+%Y-%m-%d--%H-%M-%S'`"
34
+ NEW_BUCKET_NAME="$BUCKET_BASE_NAME-image-$TIMESTAMP"
35
+
36
+ if [ ! -e /usr/local/ec2-api-tools ] ; then
37
+ echo "The EC2 api command-line tools don't seem to be installed."
38
+ echo "To install them (and Java, which they require), press enter..."
39
+ read
40
+ curl http://s3.amazonaws.com/ec2-downloads/ec2-api-tools.zip > /tmp/ec2-api-tools.zip || fail "couldn't download ec2-api-tools.zip"
41
+ unzip /tmp/ec2-api-tools.zip -d /usr/local || fail "couldn't unzip ec2-api-tools.zip"
42
+ chmod -R go-w /usr/local/ec2-api-tools*
43
+ ln -sf /usr/local/ec2-api-tools-* /usr/local/ec2-api-tools
44
+ aptitude install -y sun-java6-jre || fail "couldn't install Java package"
45
+ fi
46
+
47
+ echo "--> Clearing apt cache..."
48
+ aptitude clean
49
+
50
+ echo "--> Clearing sensitive files..."
51
+ rm -f /root/{.bash_history,.lesshst}
52
+
53
+ echo "--> Creating image..."
54
+ ec2-bundle-vol -e "/root/.ssh,/home/app/.ssh,/tmp,/mnt" -d /mnt -k "$EC2_PRIVATE_KEY" -c "$EC2_CERT" -u "$AWS_ACCOUNT_ID" || fail "ec2-bundle-vol failed"
55
+
56
+ echo "--> Uploading image to $NEW_BUCKET_NAME"
57
+ ec2-upload-bundle -b "$NEW_BUCKET_NAME" -m /mnt/image.manifest.xml -a "$AWS_ACCESS_KEY_ID" -s "$AWS_SECRET_ACCESS_KEY" || fail "ec2-upload-bundle failed"
58
+
59
+ echo "--> Registering image..."
60
+ ec2-register "$NEW_BUCKET_NAME/image.manifest.xml" || fail "ec2-register failed"
61
+
62
+ echo "--> Done."
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/ruby
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
+ require "rubygems"
22
+ require "optiflag"
23
+ require "fileutils"
24
+ require "#{File.dirname(__FILE__)}/../lib/mysql_helper"
25
+ require "#{File.dirname(__FILE__)}/../lib/s3_helper"
26
+ require "#{File.dirname(__FILE__)}/../lib/utils"
27
+
28
+ module CommandLineArgs extend OptiFlagSet
29
+ optional_flag "bucket"
30
+ optional_flag "dir"
31
+ and_process!
32
+ end
33
+
34
+ bucket = ARGV.flags.bucket
35
+ dir = ARGV.flags.dir || "database"
36
+ @s3 = Ec2onrails::S3Helper.new(bucket, dir)
37
+ @mysql = Ec2onrails::MysqlHelper.new
38
+ @temp_dir = "/mnt/tmp/ec2onrails-backup-#{@s3.bucket_name}-#{dir.gsub(/\//, "-")}"
39
+ if File.exists?(@temp_dir)
40
+ puts "Temp dir exists (#{@temp_dir}), aborting. Is another backup process running?"
41
+ exit
42
+ end
43
+
44
+ begin
45
+ FileUtils.mkdir_p @temp_dir
46
+
47
+ file = "#{@temp_dir}/dump.sql.gz"
48
+ @s3.retrieve_file(file)
49
+ @mysql.load_from_dump(file)
50
+
51
+ @s3.retrieve_files("mysql-bin.", @temp_dir)
52
+ logs = Dir.glob("#{@temp_dir}/mysql-bin.[0-9]*").sort
53
+ logs.each {|log| @mysql.execute_binary_log(log) }
54
+
55
+ @mysql.execute_sql "reset master" # TODO maybe we shouldn't do this if we're not going to delete the logs from the S3 bucket because this restarts the numbering again
56
+ ensure
57
+ FileUtils.rm_rf(@temp_dir)
58
+ end
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/ruby
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
+ # This script updates the current RAILS_ENV setting for this instance
23
+
24
+ require "yaml"
25
+ require "erb"
26
+
27
+ if ARGV.length != 1
28
+ puts "usage: set_rails_env <value>"
29
+ exit 1
30
+ end
31
+
32
+ @rails_env = ARGV[0]
33
+
34
+ File.open("/etc/ec2onrails/rails_env", 'w') do |f|
35
+ f << @rails_env
36
+ end
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/ruby
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
+ # To customize the nginx config files, you can setup a template like:
23
+ # /etc/ec2onrails/balancer_members.erb
24
+ # /etc/ec2onrails/nginx_upstream_members.erb
25
+
26
+
27
+ require "#{File.dirname(__FILE__)}/../lib/roles_helper"
28
+ include Ec2onrails::RolesHelper
29
+
30
+ puts "Roles: "
31
+ pp roles
32
+
33
+ resolve_hostnames_in_roles_file
34
+ set_hostnames
35
+ process_config_file_templates
36
+
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/ruby
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
+ # This script removes system files that were installed with the deployed Rails
23
+ # app. This only works if the previously installed files had a manifest.
24
+ #
25
+ # See install_system_files for more info.
26
+
27
+
28
+ require "fileutils"
29
+ require "#{File.dirname(__FILE__)}/../lib/system_files_helper"
30
+ require "#{File.dirname(__FILE__)}/../lib/utils"
31
+
32
+
33
+ Ec2onrails::SystemFilesHelper.new.uninstall_system_files
34
+
@@ -0,0 +1,30 @@
1
+ ############################################################
2
+ # This script is sourced by .bashrc and by /usr/local/ec2onrails/rebundle
3
+ # You shouldn't need to change anything in here
4
+
5
+ if [ -r /mnt/aws-config/config ] ; then
6
+ . /mnt/aws-config/config
7
+ export EC2_PRIVATE_KEY="/mnt/aws-config/$KEY_FILE_NAME"
8
+ export EC2_CERT="/mnt/aws-config/$CERT_FILE_NAME"
9
+
10
+ fi
11
+
12
+ export EC2_HOME=/usr/local/ec2-api-tools
13
+ export PATH="$PATH:$EC2_HOME/bin"
14
+
15
+ if [ -e "/usr/lib/jvm/java-6-sun" ]; then export JAVA_HOME="/usr/lib/jvm/java-6-sun"; fi
16
+
17
+ # Set the bash prompt to include the rails environment name
18
+ case "$TERM" in
19
+ xterm-color)
20
+ PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]-\[\033[01;35m\]`/usr/local/ec2onrails/bin/rails_env`\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
21
+ ;;
22
+ *)
23
+ PS1='${debian_chroot:+($debian_chroot)}\u@\h-`/usr/local/ec2onrails/bin/rails_env`:\w\$ '
24
+ ;;
25
+ esac
26
+
27
+ # Set some useful aliases
28
+ alias app="pushd /mnt/app/current && sudo su app && popd"
29
+ alias log="tail -f /mnt/app/current/log/`/usr/local/ec2onrails/bin/rails_env`.log"
30
+ alias logs="tail -f /mnt/app/current/log/*.log /mnt/log/syslog /mnt/log/*.log /mnt/log/*/*.log /mnt/log/*/*/.log"
@@ -0,0 +1,75 @@
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 'rubygems'
20
+ require 'yaml'
21
+ require 'erb'
22
+ require 'fileutils'
23
+ require "#{File.dirname(__FILE__)}/utils"
24
+
25
+ module Ec2onrails
26
+ class AwsHelper
27
+
28
+ DEFAULT_CONFIG_FILE = "/mnt/app/current/config/aws.yml"
29
+ DEFAULT_CONFIG_FILE_OLD = "/mnt/app/current/config/s3.yml"
30
+
31
+ # make attributes available for specs
32
+ attr_accessor :config_file
33
+ attr_accessor :rails_env
34
+ attr_accessor :aws_access_key
35
+ attr_accessor :aws_secret_access_key
36
+ attr_accessor :bucket_base_name
37
+
38
+ def initialize(config_file = AwsHelper.default_config_file, rails_env = Utils.rails_env)
39
+ @rails_env = rails_env
40
+ @config_file = config_file
41
+
42
+ if File.exists?(@config_file)
43
+ aws_config = YAML::load(ERB.new(File.read(@config_file)).result)
44
+
45
+ # try to load the section for the current RAILS_ENV
46
+ section = aws_config[@rails_env]
47
+ if section.nil?
48
+ # fall back to keys at the root of the tree
49
+ section = aws_config
50
+ end
51
+
52
+ @aws_access_key = section['aws_access_key']
53
+ @aws_secret_access_key = section['aws_secret_access_key']
54
+ @bucket_base_name = section['bucket_base_name']
55
+ else
56
+ if !File.exists?('/mnt/aws-config/config')
57
+ raise "Can't find either #{@config_file} or /mnt/aws-config/config"
58
+ end
59
+ @aws_access_key = get_bash_config('AWS_ACCESS_KEY_ID')
60
+ @aws_secret_access_key = get_bash_config('AWS_SECRET_ACCESS_KEY')
61
+ @bucket_base_name = get_bash_config('BUCKET_BASE_NAME')
62
+ end
63
+ end
64
+
65
+ # load an env value from the shared config file
66
+ def get_bash_config(name)
67
+ `bash -c 'source /mnt/aws-config/config; echo $#{name}'`.strip
68
+ end
69
+
70
+ def self.default_config_file
71
+ File.exists?(DEFAULT_CONFIG_FILE) ? DEFAULT_CONFIG_FILE : DEFAULT_CONFIG_FILE_OLD
72
+ end
73
+
74
+ end
75
+ end
@@ -0,0 +1,84 @@
1
+ module GodHelper
2
+ require '/usr/local/ec2onrails/lib/roles_helper'
3
+ require '/usr/local/ec2onrails/lib/utils'
4
+ require 'fileutils'
5
+
6
+ def default_configurations(w)
7
+ w.interval = 30.seconds
8
+ w.grace = 30.seconds
9
+
10
+
11
+ w.behavior(:clean_pid_file)
12
+
13
+ w.start_if do |start|
14
+ start.condition(:process_running) do |c|
15
+ c.interval = 5.seconds
16
+ c.running = false
17
+ end
18
+ end
19
+
20
+ # determine when process has finished starting
21
+ w.transition([:start, :restart], :up) do |on|
22
+ on.condition(:process_running) do |c|
23
+ c.running = true
24
+ end
25
+
26
+ # failsafe
27
+ on.condition(:tries) do |c|
28
+ c.times = 8
29
+ c.within = 2.minutes
30
+ c.transition = :start
31
+ end
32
+ end
33
+
34
+ # start if process is not running
35
+ w.transition(:up, :start) do |on|
36
+ on.condition(:process_exits) do |c|
37
+ c.notify = {:contacts => ['default'], :category => "RAILS_ENV=#{Ec2onrails::Utils.rails_env}"}
38
+ end
39
+ end
40
+
41
+ w.lifecycle do |on|
42
+ on.condition(:flapping) do |c|
43
+ c.notify = {:contacts => ['default'], :category => "RAILS_ENV=#{Ec2onrails::Utils.rails_env}"}
44
+ c.to_state = [:start, :restart]
45
+ c.times = 5
46
+ c.within = 5.minutes
47
+ c.transition = :unmonitored
48
+ c.retry_in = 10.minutes
49
+ c.retry_times = 5
50
+ c.retry_within = 2.hours
51
+ end
52
+ end
53
+
54
+ end
55
+
56
+ def restart_if_resource_hog(w, options={})
57
+ options = {:memory_usage => 175.megabytes, :cpu_usage => 50.percent}.merge(options)
58
+ w.restart_if do |restart|
59
+ if options[:memory_usage]
60
+ restart.condition(:memory_usage) do |c|
61
+ c.notify = {:contacts => ['default'], :category => "RAILS_ENV=#{Ec2onrails::Utils.rails_env}"}
62
+ c.above = options[:memory_usage]
63
+ c.times = [3,5]
64
+ end
65
+ end
66
+
67
+ if options[:cpu_usage]
68
+ restart.condition(:cpu_usage) do |c|
69
+ c.notify = {:contacts => ['default'], :category => "RAILS_ENV=#{Ec2onrails::Utils.rails_env}"}
70
+ c.above = options[:cpu_usage]
71
+ c.times = 5
72
+ end
73
+ end
74
+
75
+ yield restart if block_given?
76
+
77
+ end
78
+ end
79
+
80
+ class Configs
81
+ include Ec2onrails::RolesHelper
82
+ end
83
+
84
+ end