skippy-ec2onrails 0.9.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) hide show
  1. data/CHANGELOG +159 -0
  2. data/COPYING +339 -0
  3. data/Manifest +162 -0
  4. data/README.textile +214 -0
  5. data/Rakefile +36 -0
  6. data/TODO +102 -0
  7. data/ec2onrails.gemspec +42 -0
  8. data/examples/Capfile +3 -0
  9. data/examples/deploy.rb +101 -0
  10. data/examples/s3.yml +9 -0
  11. data/lib/ec2onrails/capistrano_utils.rb +43 -0
  12. data/lib/ec2onrails/recipes.rb +844 -0
  13. data/lib/ec2onrails/version.rb +31 -0
  14. data/lib/ec2onrails.rb +20 -0
  15. data/server/build-ec2onrails.sh +44 -0
  16. data/server/files/etc/aliases +5 -0
  17. data/server/files/etc/aliases.db +0 -0
  18. data/server/files/etc/apache2/apache2.conf +295 -0
  19. data/server/files/etc/apache2/conf.d/app.proxy_cluster.conf +7 -0
  20. data/server/files/etc/apache2/conf.d/app.proxy_frontend.conf +10 -0
  21. data/server/files/etc/apache2/mods-available/proxy.conf +18 -0
  22. data/server/files/etc/apache2/sites-available/app.common +56 -0
  23. data/server/files/etc/apache2/sites-available/app.custom +0 -0
  24. data/server/files/etc/apache2/sites-available/default +14 -0
  25. data/server/files/etc/apache2/sites-available/default-ssl +19 -0
  26. data/server/files/etc/cron.d/backup_app_db_to_s3 +16 -0
  27. data/server/files/etc/cron.daily/app +9 -0
  28. data/server/files/etc/cron.daily/logrotate_post +19 -0
  29. data/server/files/etc/cron.hourly/app +10 -0
  30. data/server/files/etc/cron.monthly/app +10 -0
  31. data/server/files/etc/cron.weekly/app +10 -0
  32. data/server/files/etc/denyhosts.conf +628 -0
  33. data/server/files/etc/dpkg/dpkg.cfg +13 -0
  34. data/server/files/etc/ec2onrails/README +32 -0
  35. data/server/files/etc/ec2onrails/balancer_members +6 -0
  36. data/server/files/etc/ec2onrails/roles.yml +5 -0
  37. data/server/files/etc/environment +2 -0
  38. data/server/files/etc/god/app.god +35 -0
  39. data/server/files/etc/god/db.god +17 -0
  40. data/server/files/etc/god/examples/have_god_daemonize.god +18 -0
  41. data/server/files/etc/god/master.conf +35 -0
  42. data/server/files/etc/god/memcache.god +15 -0
  43. data/server/files/etc/god/notifications.god +14 -0
  44. data/server/files/etc/god/system.god +34 -0
  45. data/server/files/etc/god/web.god +36 -0
  46. data/server/files/etc/init.d/ec2-every-startup +29 -0
  47. data/server/files/etc/init.d/ec2-first-startup +36 -0
  48. data/server/files/etc/init.d/god +42 -0
  49. data/server/files/etc/init.d/nginx +78 -0
  50. data/server/files/etc/init.d/set_roles +3 -0
  51. data/server/files/etc/logrotate.d/apache2 +16 -0
  52. data/server/files/etc/logrotate.d/mongrel +11 -0
  53. data/server/files/etc/logrotate.d/nginx +11 -0
  54. data/server/files/etc/memcached.conf +47 -0
  55. data/server/files/etc/mongrel_cluster/app.yml +9 -0
  56. data/server/files/etc/motd.tail +13 -0
  57. data/server/files/etc/mysql/my.cnf +149 -0
  58. data/server/files/etc/nginx/nginx.conf +296 -0
  59. data/server/files/etc/postfix/main.cf +4 -0
  60. data/server/files/etc/rcS.d/S91ec2-first-startup +1 -0
  61. data/server/files/etc/rcS.d/S92ec2-every-startup +1 -0
  62. data/server/files/etc/rcS.d/S99set_roles +1 -0
  63. data/server/files/etc/ssh/sshd_config +94 -0
  64. data/server/files/etc/sudoers +1 -0
  65. data/server/files/etc/sudoers.full_access +26 -0
  66. data/server/files/etc/sudoers.restricted_access +28 -0
  67. data/server/files/etc/syslog.conf +69 -0
  68. data/server/files/usr/bin/god +26 -0
  69. data/server/files/usr/local/ec2onrails/COPYING +339 -0
  70. data/server/files/usr/local/ec2onrails/bin/archive_file.rb +44 -0
  71. data/server/files/usr/local/ec2onrails/bin/backup_app_db.rb +159 -0
  72. data/server/files/usr/local/ec2onrails/bin/ec2_meta_data.rb +80 -0
  73. data/server/files/usr/local/ec2onrails/bin/exec_runner +73 -0
  74. data/server/files/usr/local/ec2onrails/bin/init_services.rb +64 -0
  75. data/server/files/usr/local/ec2onrails/bin/optimize_mysql.rb +348 -0
  76. data/server/files/usr/local/ec2onrails/bin/rails_env +35 -0
  77. data/server/files/usr/local/ec2onrails/bin/rebundle.sh +70 -0
  78. data/server/files/usr/local/ec2onrails/bin/restore_app_db.rb +58 -0
  79. data/server/files/usr/local/ec2onrails/bin/set_rails_env +40 -0
  80. data/server/files/usr/local/ec2onrails/bin/set_roles.rb +87 -0
  81. data/server/files/usr/local/ec2onrails/bin/setup_web_proxy.rb +109 -0
  82. data/server/files/usr/local/ec2onrails/config +30 -0
  83. data/server/files/usr/local/ec2onrails/lib/aws_helper.rb +76 -0
  84. data/server/files/usr/local/ec2onrails/lib/god_helper.rb +129 -0
  85. data/server/files/usr/local/ec2onrails/lib/god_patch.rb +43 -0
  86. data/server/files/usr/local/ec2onrails/lib/mysql_helper.rb +101 -0
  87. data/server/files/usr/local/ec2onrails/lib/roles_helper.rb +151 -0
  88. data/server/files/usr/local/ec2onrails/lib/s3_helper.rb +99 -0
  89. data/server/files/usr/local/ec2onrails/lib/utils.rb +16 -0
  90. data/server/files/usr/local/ec2onrails/lib/vendor/ini.rb +268 -0
  91. data/server/files/usr/local/ec2onrails/startup-scripts/every-startup/get-hostname.sh +25 -0
  92. data/server/files/usr/local/ec2onrails/startup-scripts/first-startup/README +5 -0
  93. data/server/files/usr/local/ec2onrails/startup-scripts/first-startup/create-dirs.sh +39 -0
  94. data/server/files/usr/local/ec2onrails/startup-scripts/first-startup/generate-default-web-cert-and-key.sh +49 -0
  95. data/server/files/usr/local/ec2onrails/startup-scripts/first-startup/misc.sh +27 -0
  96. data/server/files/usr/local/ec2onrails/startup-scripts/first-startup/prepare-mysql-data-dir.sh +24 -0
  97. data/server/files/usr/local/ec2onrails/startup-scripts/first-startup/setup-credentials.sh +29 -0
  98. data/server/files/usr/local/ec2onrails/startup-scripts/first-startup/setup-file-permissions.sh +30 -0
  99. data/server/rakefile.rb +242 -0
  100. data/setup.rb +1585 -0
  101. data/test/autobench.conf +60 -0
  102. data/test/spec/lib/s3_helper_spec.rb +134 -0
  103. data/test/spec/lib/s3_old.yml +3 -0
  104. data/test/spec/test_files/test1 +0 -0
  105. data/test/spec/test_files/test2 +0 -0
  106. data/test/test_app/Capfile +3 -0
  107. data/test/test_app/README +182 -0
  108. data/test/test_app/Rakefile +10 -0
  109. data/test/test_app/app/controllers/application.rb +7 -0
  110. data/test/test_app/app/controllers/db_fast_controller.rb +6 -0
  111. data/test/test_app/app/controllers/fast_controller.rb +5 -0
  112. data/test/test_app/app/controllers/slow_controller.rb +6 -0
  113. data/test/test_app/app/controllers/very_slow_controller.rb +6 -0
  114. data/test/test_app/app/helpers/application_helper.rb +3 -0
  115. data/test/test_app/app/helpers/db_fast_helper.rb +2 -0
  116. data/test/test_app/app/helpers/fast_helper.rb +2 -0
  117. data/test/test_app/app/helpers/slow_helper.rb +2 -0
  118. data/test/test_app/app/helpers/very_slow_helper.rb +2 -0
  119. data/test/test_app/config/boot.rb +109 -0
  120. data/test/test_app/config/database.yml +19 -0
  121. data/test/test_app/config/deploy.rb +21 -0
  122. data/test/test_app/config/environment.rb +60 -0
  123. data/test/test_app/config/environments/development.rb +21 -0
  124. data/test/test_app/config/environments/production.rb +18 -0
  125. data/test/test_app/config/environments/test.rb +19 -0
  126. data/test/test_app/config/routes.rb +27 -0
  127. data/test/test_app/db/schema.rb +7 -0
  128. data/test/test_app/doc/README_FOR_APP +2 -0
  129. data/test/test_app/public/404.html +30 -0
  130. data/test/test_app/public/500.html +30 -0
  131. data/test/test_app/public/dispatch.cgi +10 -0
  132. data/test/test_app/public/dispatch.fcgi +24 -0
  133. data/test/test_app/public/dispatch.rb +10 -0
  134. data/test/test_app/public/favicon.ico +0 -0
  135. data/test/test_app/public/images/rails.png +0 -0
  136. data/test/test_app/public/javascripts/application.js +2 -0
  137. data/test/test_app/public/javascripts/controls.js +963 -0
  138. data/test/test_app/public/javascripts/dragdrop.js +972 -0
  139. data/test/test_app/public/javascripts/effects.js +1120 -0
  140. data/test/test_app/public/javascripts/prototype.js +4225 -0
  141. data/test/test_app/public/robots.txt +1 -0
  142. data/test/test_app/script/about +3 -0
  143. data/test/test_app/script/breakpointer +3 -0
  144. data/test/test_app/script/console +3 -0
  145. data/test/test_app/script/destroy +3 -0
  146. data/test/test_app/script/generate +3 -0
  147. data/test/test_app/script/performance/benchmarker +3 -0
  148. data/test/test_app/script/performance/profiler +3 -0
  149. data/test/test_app/script/performance/request +3 -0
  150. data/test/test_app/script/plugin +3 -0
  151. data/test/test_app/script/process/inspector +3 -0
  152. data/test/test_app/script/process/reaper +3 -0
  153. data/test/test_app/script/process/spawner +3 -0
  154. data/test/test_app/script/runner +3 -0
  155. data/test/test_app/script/server +3 -0
  156. data/test/test_app/test/functional/db_fast_controller_test.rb +18 -0
  157. data/test/test_app/test/functional/fast_controller_test.rb +18 -0
  158. data/test/test_app/test/functional/slow_controller_test.rb +18 -0
  159. data/test/test_app/test/functional/very_slow_controller_test.rb +18 -0
  160. data/test/test_app/test/test_helper.rb +28 -0
  161. data/test/test_ec2onrails.rb +11 -0
  162. data/test/test_helper.rb +2 -0
  163. metadata +274 -0
data/README.textile ADDED
@@ -0,0 +1,214 @@
1
+ h1. EC2 on Rails
2
+
3
+ h2. Deploy a Ruby on Rails app on EC2 in five minutes
4
+
5
+ Main Page: "https://ec2onrails.rubyforge.org":https://ec2onrails.rubyforge.org
6
+
7
+ Code on Github: "https://github.com/pauldowman/ec2onrails":https://github.com/pauldowman/ec2onrails
8
+
9
+ EC2 on Rails is an Ubuntu Linux server image for "Amazon's EC2 hosting service":http://www.amazon.com/b/ref=sc_fe_l_2/102-6342260-7987311?ie=UTF8&node=201590011&no=3435361 that's ready to run a standard Ruby on Rails application with little or no customization. It's a Ruby on Rails "virtual appliance":http://en.wikipedia.org/wiki/Virtual_appliance.
10
+
11
+ If you have an EC2 account and can start EC2 instances you're five minutes away from deploying your Rails app.
12
+
13
+ EC2 on Rails is "opinionated software":http://gettingreal.37signals.com/ch04_Make_Opinionated_Software.php: the opinion is that for many rails apps the server setup can be generalized and shared the same way as the web application framework itself. For many people (Twitter, this isn't for you) the server image can be treated the same way as other shared libraries. And if the day comes when your needs areunique enough that EC2 on Rails can't be configured to work for you then you can bundle your own image from it or fork the build source and customize it.
14
+
15
+ But until then, why spend your time configuring servers?
16
+
17
+ Features of the EC2 image:
18
+
19
+ * Ready to deploy a Rails app with little or no configuration of the server required
20
+ * Optional Amazon Elastic Block Store (EBS) setup and support for MySQL database persistence.
21
+ * Automatic backup of MySQL database to S3 (EBS enabled: snapshots taken every 2 hrs; Non-EBS enabled: full backup nightly + incremental backup using binary logs every 5 minutes if not using )
22
+ * Capistrano tasks to customize the server image, archive and restore the database to/from S3, and more (available as a rubygem)
23
+ * Mongrel_cluster behind Apache 2.2, configured according to
24
+ "Coda Hale's excellent guide":http://blog.codahale.com/2006/06/19/time-for-a-grown-up-server-rails-mongrel-apache-capistrano-and-you/
25
+ * Ruby on Rails 2.1.0, 2.0.2 and 1.2.6
26
+ * Ruby 1.8.6
27
+ * MySQL 5
28
+ * "memcached":http://www.danga.com/memcached/
29
+ * "monit":http://www.tildeslash.com/monit/ configured to monitor apache, mongrel, mysql, memcached, drive space and system load
30
+ * Ubuntu 8.04 LTS "Hardy" base image built using "Eric Hammond's EC2 Ubuntu script":http://alestic.com/
31
+ * SSL support
32
+ * Amazon AMI tools installed
33
+ * Apache or Nginx web proxies
34
+ * MySQL, Apache/Nginx, and syslog configured to use /mnt for data and logging so you don't fill up EC2's small root filesystem
35
+ * Automatically archives Rails and Apache logs to S3 nightly.
36
+ * 32-bit and 64-bit images available (supports all instance types, small to extra large).
37
+ * Created using a build file, full source is "available":http://rubyforge.org/scm/?group_id=4552 (the EC2 on Rails script is run from "Eric Hammond's EC2 Ubuntu script":http://alestic.com/)
38
+ * Can be used as a clustered Rails app running on multiple instances
39
+ * Automatically runs hourly, daily, weekly and monthly scripts if they exist in Rails application's script directory
40
+ * Local "Postfix":http://www.postfix.org/ SMTP mail server (only available from within the instance, not listening on external network interfaces)
41
+
42
+
43
+ h2. Using the image
44
+
45
+ This documentation will be improved soon, for now hopefully this covers the basics.
46
+
47
+ The current AMI id's are:
48
+ * ami-c9bc58a0 (32-bit)
49
+ * ami-cbbc58a2 (64-bit)
50
+
51
+ _I will keep these images available for as long as possible, they will not be deleted for at least a few years._
52
+
53
+
54
+ h4. 1. Install the gem
55
+
56
+ <pre>sudo gem install ec2onrails</pre>
57
+
58
+ h4. 2. Add the config files to your Rails app
59
+
60
+ You will need to place "Capfile":http://github.com/pauldowman/ec2onrails/tree/master/examples/Capfile?raw=true in the root of your rails folder, and put "deploy.rb":http://github.com/pauldowman/ec2onrails/tree/master/examples/deploy.rb?raw=true and "s3.yml":http://github.com/pauldowman/ec2onrails/tree/master/examples/s3.yml?raw=true in the config folder.
61
+
62
+ Within your rails directory, run
63
+ <code>
64
+ wget -q -O Capfile http://github.com/pauldowman/ec2onrails/tree/master/examples/Capfile?raw=true
65
+ wget -q -O config/deploy.rb http://github.com/pauldowman/ec2onrails/tree/master/examples/deploy.rb?raw=true
66
+ wget -q -O config/s3.yml http://github.com/pauldowman/ec2onrails/tree/master/examples/s3.yml?raw=true
67
+ </code>
68
+
69
+
70
+ _Be sure to customize those files and read the comments._
71
+
72
+ Also, use the hostname "db_primary" in your database.yml file. After running "cap ec2onrails:server:set_roles" it will resolve to the instance defined in your Capistrano "db" role.
73
+
74
+ h4. 3. Start up one or more instances of the image.
75
+
76
+ There is nothing EC2 on Rails-specific here yet (though soon there will be a Capistrano task to do this for you), if you've started EC2 instances before you can skip this section. Otherwise, I'm not going to lie, this part is complicated and will take a lot more than 5 minutes the first time.
77
+
78
+ Read the "running an instance section":http://docs.amazonwebservices.com/AWSEC2/2007-08-29/GettingStartedGuide/running-an-instance.html in Amazon's getting started guide.
79
+
80
+ For the AMI id's of the current images do <code>cap ec2onrails:ami_ids</code> from within the app that you configured in the previous step (they're also listed earlier on this page).
81
+
82
+ _NOTE: Only use the images that match the current version of the gem._
83
+
84
+ Please see the "change log":http://ec2onrails.rubyforge.org/svn/trunk/gem/CHANGELOG for release notes, and see the "list of open issues":http://rubyforge.org/tracker/?atid=17558&group_id=4552&func=browse.
85
+
86
+ As is "standard for public AMI's":http://docs.amazonwebservices.com/AWSEC2/2007-08-29/DeveloperGuide/public-ami-guidelines.html, password-based logins are disabled. You log in with your own "public/private keypair":http://docs.amazonwebservices.com/AWSEC2/2007-08-29/GettingStartedGuide/running-an-instance.html.
87
+
88
+ Most basic things can be configured automatically by the Capistrano tasks, but if you want to you can login by ssh as a user named "admin" (has sudo ability) or as "app" (the user that the app runs as, does not have sudo ability). The Capistrano tasks automatically use the app user to deploy the app, and the admin user for server admin tasks that require sudo.
89
+
90
+ IMPORTANT: Double-check "your firewall settings":http://docs.amazonwebservices.com/AWSEC2/2007-08-29/GettingStartedGuide/running-an-instance.html. Be sure that you haven't allowed public access to any ports other than TCP 22 and TCP 80 (and possibly TCP 443 if you're going to enable HTTPS). If you're using multiple instances, be sure to allow them network access to each other.
91
+
92
+
93
+ h4. 4. Copy your public key from the server to keep Capistrano happy
94
+
95
+ This is a workaround for a quirk in Capistrano. Technically all you should need to connect to the server is the private key file, the public key is on the server. But for some reason "Capistrano requires that you have both the public key and the private key files together on the client":http://groups.google.com/group/capistrano/browse_thread/thread/1102208ff925d18.
96
+
97
+ There is a Capistrano task that tries to fix this for you. From within the root of your rails app do:
98
+
99
+ <pre>cap ec2onrails:get_public_key_from_server</pre>
100
+
101
+ Note, this will only work if you have an external ssh command in the path, it won't work for most Windows users.
102
+
103
+
104
+ h4. 5. Deploy the app with Capistrano
105
+
106
+ Now that the gem is installed, your deploy.rb is configured and you can start and stop EC2 instances, this is the only thing you'll need to do from now on.
107
+
108
+ <pre>
109
+ cap ec2onrails:setup
110
+ cap deploy:cold
111
+ </pre>
112
+
113
+ Yes, it's that easy! The setup task will set the server's timezone, install any gems and Ubuntu packages that you specified in the config file, and create your database.
114
+
115
+ That's it, your app is now running on EC2!!
116
+
117
+
118
+ h2. Capistrano tasks
119
+
120
+ "Capistrano":http://capify.org is the most commonly used Rails deployment tool. It comes with many standard "tasks", and the EC2 on Rails gem includes Capistrano tasks specifically for configuring the server instance.
121
+
122
+ Capistrano is run from the command-line using the "cap" command, with a task name given as an argument.
123
+
124
+ h3. Commonly-used tasks
125
+
126
+ You'll mostly need just the following Capistrano tasks:
127
+
128
+ * <code>cap ec2onrails:ami_ids</code> Shows the AMI id's of the images that match the current version of the gem.
129
+
130
+ * <code>cap ec2onrails:setup</code> This task configures a newly-launched instance. This is the first thing you should do after starting a new instance. It can be run more than once without ill effect. After running "cap ec2onrails:setup" the next thing to do is run "cap deploy:cold"
131
+
132
+ * <code>cap ec2onrails:db:enable_ebs</code> This task will move the _primary_ mysql database onto an Amazon Elastic Storage Block (EBS) volume. You can call this task with the optional SIZE parameter defined (defaults to 10 gigs) like <pre>cap ec2onrails:db:enable_ebs SIZE=10</pre>
133
+
134
+ You should then specify your own volume (or the one created by this task) in your capistrano deploy.rb file like so: <pre>role :db, "ec2-xx-xxx-xx-xxx.compute-1.amazonaws.com", :primary => true, :ebs_vol_id => 'vol-12345abc'</pre>
135
+
136
+ *NOTE* MySQL EBS is not enabled by default. You may call this task at anytime to move your MySQL over to EBS, but just make sure you keep track of the volume-id that is printed out by this task and use it to modify your deploy.rb file
137
+
138
+ * <code>cap ec2onrails:server:set_roles</code> Customizes each instance for it's role(s) (as defined in your Capistrano deploy.rb file). Run this after starting or stopping instances. For now this just makes sure that only the appropriate services (Apache, Mongrel, and/or MySQL) are running. Eventually this will customize settings for the running services also. Note that an instance can have more than one role. If there's only one instance it will have all roles.
139
+
140
+ Note that due to the way that Capistrano works all tasks are run against all hosts that are currently defined in the deploy.rb file. So if you start a new instance then add it to your deploy.rb you will need to run "cap ec2onrails:setup" again which will be run on all existing instances.
141
+
142
+
143
+ h3. Database management tasks
144
+
145
+ * <code>cap ec2onrails:db:archive</code> Archive the MySQL database to the bucket specified in your deploy.rb. This is for archiving a snapshot of your database into any S3 bucket. For example, you might want to do this before deploying.
146
+
147
+ * <code>cap ec2onrails:db:restore</code> Restore the MySQL database from the bucket specified in your deploy.rb For example, I use this to restore the current production data (from my actual production backup bucket) onto a staging server that has the current production version of my app. I then deploy the new version which tests migrations exactly as they'll run on the production server.
148
+
149
+ To get a full list of the Capistrano tasks at any time type <code>cap -T</code> from with your rails app root.
150
+
151
+ h2. Building the image
152
+
153
+ Building the image is not required, most people will simply use the prebuilt public image, but there is also a build script that builds the image. It's meant to be called by "Eric Hammond's EC2 Ubuntu script":http://alestic.com/.
154
+
155
+ Here is how you go about setting it up:
156
+
157
+
158
+ h4. Notes
159
+
160
+ * amazon-keypair is your amazon keypair, which in this case has has had the public and private keys copied into the ~/.ssh folder
161
+ * we need to copy the ec2onrails source folder onto the image instance
162
+ * HOST_PUBLIC_INSTANCE is the hostname of the instance that you will soon be creating. run <code>ec2-describe-instances</code> to find this value. It will look something like <code>ec2-xxx-xxx-xxx-xxx.compute-x.amazonaws.com</code>
163
+
164
+ h4. Getting started...
165
+
166
+ * launch one of Eric's default images (see "Eric Hammond's":http://alestic.com/ page for the most recent ami-images): <code>ec2-run-instances ami-1cd73375 -k amazon-keypair</code> (for a 64-bit image, launch: <code>ec2-run-instances ami-17d7337e -k amazon-keypair --instance-type m1.large</code>)
167
+ * lets get your amazon keypair up onto the instance: <code>scp -i ~/.ssh/id_rsa-amazon-keypair ~/.ec2/{cert,pk}-*.pem root@HOST_PUBLIC_ADDRESS:/mnt/</code>
168
+ * ditto for getting the ec2onrails server code up onto your new instance: <code>scp -rp -i ~/.ssh/id_rsa-amazon-keypair ~/your/copy/of/ec2onrails/. root@HOST_PUBLIC_ADDRESS:/mnt/ec2onrails</code>
169
+ * time to log into your instance: <code>ssh -i ~/.ssh/id_rsa-amazon-keypair root@HOST_PUBLIC_ADDRESS</code>
170
+ * get the most recent ec2ubuntu script: <code>curl -Lo /mnt/ec2ubuntu-build-ami http://ec2ubuntu-build-ami.notlong.com</code>
171
+ * time to get the instance ready for ec2onrails. The script will end with a command you need to run to finish creating an amazon ami-image. <pre>bash /mnt/ec2ubuntu-build-ami \
172
+ --codename hardy \
173
+ --bucket YOURNAME_ec2onrails \
174
+ --prefix ec2onrails \
175
+ --user YOUR_AMAZON_USER_ID \
176
+ --access-key AMAZON_ACCESS_KEY \
177
+ --secret-key AMAZON_SECRET_KEY \
178
+ --private-key /mnt/pk-*.pem \
179
+ --cert /mnt/cert-*.pem \
180
+ --script /mnt/ec2onrails/server/build-ec2onrails.sh</pre>
181
+
182
+ h2. Mailing lists
183
+
184
+ There are two Google groups, one for "announcements":http://groups.google.com/group/ec2-on-rails-announce (usually just new release announcements) and one for "discussion":http://groups.google.com/group/ec2-on-rails-discuss.
185
+
186
+
187
+ h2. Comments
188
+
189
+ Comments are welcome. Send an email to "Paul Dowman":http://pauldowman.com/contact/ or to the "Google group":http://groups.google.com/group/ec2-on-rails-discuss. If you find bugs please file them "here":http://rubyforge.org/tracker/?atid=17558&group_id=4552&func=browse or send me an "email":http://pauldowman.com/contact/.
190
+
191
+
192
+ h2. Change log
193
+
194
+ See the "change log":http://ec2onrails.rubyforge.org/svn/trunk/gem/CHANGELOG.
195
+
196
+
197
+ h2. How to submit patches
198
+
199
+ Pleae read the "8 steps for fixing other people's code":http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/. The source code can be checked out anonymously using:
200
+ <pre>
201
+ svn checkout http://ec2onrails.rubyforge.org/svn/trunk ec2onrails
202
+ </pre>
203
+
204
+ Code on Github: "https://github.com/pauldowman/ec2onrails":https://github.com/pauldowman/ec2onrails
205
+
206
+ Patches can be submitted to the "RubyForge Tracker":http://rubyforge.org/tracker/?atid=17560&group_id=4552&func=browse or "emailed directly to me":http://pauldowman.com/contact/ .
207
+
208
+ h2. License
209
+
210
+ This code is free to use under the terms of the GPL v2.
211
+
212
+ If you find EC2 on Rails useful please "recommend Paul Dowman":http://www.workingwithrails.com/person/10131-paul-dowman at Working With Rails.
213
+
214
+ Copyright 2007 Paul Dowman, http://pauldowman.com/ This is free software, and you are welcome to redistribute it under certain conditions. This software comes with ABSOLUTELY NO WARRANTY. See the file named COPYING for details.
data/Rakefile ADDED
@@ -0,0 +1,36 @@
1
+ require "./lib/ec2onrails/version"
2
+
3
+ begin
4
+ require 'echoe'
5
+ rescue LoadError
6
+ abort "You'll need to have `echoe' installed to use ec2onrails' Rakefile"
7
+ end
8
+
9
+ version = Ec2onrails::VERSION::STRING.dup
10
+
11
+ Echoe.new('ec2onrails', version) do |p|
12
+ p.changelog = "CHANGELOG"
13
+
14
+ p.author = ['Paul Dowman', 'Adam Greene']
15
+ p.email = "paul@pauldowman.com"
16
+
17
+ p.summary = <<-DESC.strip.gsub(/\n\s+/, " ")
18
+ Client-side libraries (Capistrano tasks) for managing and
19
+ deploying to EC2 on Rails servers.
20
+ DESC
21
+
22
+ #OTHER helpful options
23
+ # p.install_message = "perhaps telling them where to find the example docs?"
24
+ # p.rdoc_pattern
25
+ p.url = "http://ec2onrails.rubyforge.org"
26
+ p.need_zip = true
27
+ p.rdoc_pattern = /^(lib|README.textile|CHANGELOG)/
28
+
29
+ p.dependencies = [
30
+ 'capistrano >= 2.4.3',
31
+ 'archive-tar-minitar >= 0.5.2',
32
+ 'optiflag >= 0.6.5']
33
+
34
+ p.development_dependencies = ['rake >=0.7.1']
35
+
36
+ end
data/TODO ADDED
@@ -0,0 +1,102 @@
1
+ here are a list of upcoming changes or ones I'm thinking about
2
+
3
+ FUTURE CHANGES
4
+ [ ] do not change the Capify file. This is an issue if you want to use ec2 for staging but something else (engineyard) for production. The issue is that require 'ec2onrails/recipes' cannot be called until after the deploy file has been run because of some loading dependencies. SO, is it possible to not have this behavior, or is this making a mnt out of a mole-hill?
5
+
6
+ [ ] be able to save an ami file after cap ec2onrails:setup is run... this way you can just launch more instances of that specific ami file (can we automate this? )
7
+
8
+ [ ] use mongrel_cluster from app directory (shared or directly in the app/config dir), and then default to the one at /etc/mongrel_cluster/app.yml
9
+
10
+ [ ] customize roles. For example, lets say I want to have nginx publish to multiple proxy's instead of the set_roles.rb default ones. Have a hook where I, as an end user, can extend custom roles... but where do I put it? is there a custom_roles_file location pref that is set in the cap deploy file?
11
+
12
+ [ ] hook memcached into nginx...
13
+
14
+ [ ] hook ssl setup hooks for nginx
15
+
16
+ [ ] automatic firewall setup. The hitch is can we find the amazon user_id automatically?
17
+
18
+ [ ] automatic and randomized initial mysql root password setup. Place the root password in a text file only to be read by 'root', perhaps in /etc/ec2onrails/mysq_root_passwd. 'mysqladmin -u root -h localhost password subGen1us'
19
+
20
+ [ ] rename the root username for mysql, like 'update user set user="mydbadmin" where user="root";'. Make sure we do this at startup but also have a check that if a user is upgrading their server that this is switched
21
+
22
+ [ ] multi-database setup. Master -> n slave(s)
23
+
24
+ [ ] when generating roles file for each server, so each server knows where/how to find the internal IP of other servers in the cluster, generate this based on the roles that actually exist so arbitrary new ones can be added (recipes.rb, task :set_roles). Capistrano has a variable 'roles', that should be useable...? is an array, with Capistrano::ServerDefinition objects, which have the following attributes :host, :user, :port, :options
25
+
26
+ [ ] allow memcache servers to reside on a separate host/cluster
27
+
28
+ [ ] do a little memcache optimization, especially if it is its own host
29
+
30
+ [ ] allow to pull memcache file from application directory ./config
31
+
32
+ [ ] hook in pauls postfix changes to be able to use an external smtp provider. make it configurable:
33
+ http://pauldowman.com/2008/02/17/smtp-mail-from-ec2-web-server-setup/
34
+ also see this file for updates:
35
+ http://www.babbleon.co.uk/2008/05/email-with-ec2/
36
+
37
+ [ ] preload mysql timezone information (UPDATE: not sure if this is needed...)
38
+
39
+ [ ] mysql optimizations are not calculating the num of cores avail correctly
40
+
41
+ [ ] right now cron has a task called 'app' in cron.daily, cron.hourly, cron.monthly, and cron.weekly. BUT, these are run on every server. we should probably provide some sort of mechanism so a user can specify particular jobs for particular roles
42
+
43
+ [ ] consolidate all logs to /mnt/log, including /mnt/app/current... it makes it easier to rotate and shuffle them off to s3
44
+
45
+ [ ] get all user-data and meta-data variables from the amazon image in a similar way to rightscale? Makes it dead simple to use/manipulate that information. UPDATE: rightscale gave us permission to use their open-sourced files, as long as we credit them
46
+
47
+ [ ] hook in encryption of backup archives
48
+
49
+ [ ] hook in backup of server... or should we wait for persistent storage snapshots? http://www.webmonkey.com/tutorial/Back_Up_a_Web_Server
50
+
51
+ [ ] allow a non-standard ssh port (and make sure the firewall is setup correctly). modify /etc/ssh/ssh_config, update /etc/services. Also turn off root access...but only if we have another full sudo user like 'admin'
52
+
53
+ [ ] should we go back to having a sudo user like 'admin' that we flip into when we need sudo access instead of root?
54
+
55
+ [ ] install and setup an intrusion detection system. Do we want to do something as simple fcheck(apt-get fcheck, run with fcheck -cadsxl, and add /mnt to its exclusion list?), or something more complex like snort or prelude? fcheck is small, but simple; snort is quite complex and will either require its own capistrano role or live on the web role... plus it needs to be hooked into email and other notification paths to make it useful.
56
+
57
+ [ ] make difficult security/hardening changes optional, especially if they will get in the way of getting up and running. For example, do not install denyhosts by default...or disable it if the security_hardening flag == false
58
+
59
+ POSSIBLE CHANGES
60
+ [ ] do not put users custom files up there until before deploy:cold? Right now I'm pushing a lot of custom stuff out there into monit which is failing because the code it is supposed to monitor is not there yet. will pushing it to "before 'deploy:cold' cause an issues"
61
+
62
+ [ ] possibly put /tmp on its own mnt point, and then lock it down in /etc/fstab. Modify tmp to something like this '/dev/hda2 /tmp ext3 nodev,nosuid, noexec 0 0'
63
+ this means nonone will be able to execute, or a bunch of other things, from within /tmp
64
+
65
+
66
+ QUESTIONS
67
+ * during setup, what do you choose for Postfix configurations? ANSWER:
68
+
69
+ * why install php5? ANSWER: Can't tell... seems to run fine without it, so removing it as a direct aptitude fetch (if it is a dependency somewhere else, it will get downloaded)
70
+
71
+ * WHO runs the script/migration? App or db? ANSWER: the (primary-) db does. This make sense in that you don't want every app instance running a rake db:migration. This means that the db role needs to be fully setup to handle rake db:migration, meaning the /etc/hosts file needs to contain db_primary as an alias to 127.0.0.1
72
+
73
+
74
+ COMPLETED
75
+ [X] Move to Echoe? It just seems a LOT easier to setup and handle than hoe. It can remove a lot of cruft, probably including ./config, ./script, ./tasks (or most of them), and ./website (move that to the README file?... looks like would need to be moved to ./docs ). A few folks have branched ec2onrails into github before and they've all done this...
76
+
77
+ [X] set -y flag when installing/updating gems UPDATE: not needed... does it automatically for the other non-interactive flags we are using
78
+
79
+ [X] mysql optimizations
80
+
81
+ [X] hook in ebs, and use eric's writeup as the starting point:
82
+ http://developer.amazonwebservices.com/connect/entry.jspa?externalID=1663&categoryID=100
83
+
84
+
85
+ [X] /etc/monit/monitrc needs to be chmod 700. see error at: http://pastie.org/251895, with custom task at http://pastie.org/251896.. Perhaps this should be solved in set_roles.rb or init_services or something a bit higher`
86
+
87
+ [X] remove the *_admin capistrano roles. can we use admin for sudo access but continue to deploy and run under a user without sudo access? It looks like we can if we add this to the recipes.rb file:
88
+ set :use_sudo, true
89
+ set :user, "app"
90
+ set :admin_runner, "admin"
91
+ UPDATE: this didn't work as then admin would need to behave as root... SO, here is what I did:
92
+ * remove _admin roles AND the admin user
93
+ * give app user full sudo access to begin with
94
+ * have /etc/sudoers -> /etc/sudoers.full_access
95
+ * after ec2onrails:setup, trigger ec2onrails:server:restrict_sudo_access
96
+ - flips /etc/sudoers -> /etc/sudoers.restricted_access
97
+ - at this point, the app user ONLY has access to sudo to monit
98
+ * provide cap tasks to restrict or grant full sudo access
99
+
100
+ [X] allow config to be able to flip between nginx and apache as proxy...
101
+
102
+ [X] move to god from monit. One advantage is that right now, we don't use monit to send start/stop/restart signals to the underlying processes. Monit does not always stop mongrel, and if mongrel doesn't restart monit doesn't go in with the oh-holy 'kill -9'. So we unmonit mongrel, then use the /etc/init.d/mongrel stop to kill it. This works (quite well actually) BUT it makes it tricky because if we limit sudo access to only monit, we cannot run the /etc/init.d/*. It would be best if we provide sudo access to ONLY one process. God, supposedly, doesn't have this issue. So if we use god instead of monit, can we have god be responsible for restarts and what not?
@@ -0,0 +1,42 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = %q{ec2onrails}
3
+ s.version = "0.9.10"
4
+
5
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
6
+ s.authors = ["Paul Dowman, Adam Greene"]
7
+ s.date = %q{2008-12-19}
8
+ s.description = %q{Client-side libraries (Capistrano tasks) for managing and deploying to EC2 on Rails servers.}
9
+ s.email = %q{paul@pauldowman.com}
10
+ s.extra_rdoc_files = ["CHANGELOG", "lib/ec2onrails/capistrano_utils.rb", "lib/ec2onrails/recipes.rb", "lib/ec2onrails/version.rb", "lib/ec2onrails.rb", "README.textile"]
11
+ s.files = ["CHANGELOG", "COPYING", "ec2onrails.gemspec", "examples/Capfile", "examples/deploy.rb", "examples/s3.yml", "lib/ec2onrails/capistrano_utils.rb", "lib/ec2onrails/recipes.rb", "lib/ec2onrails/version.rb", "lib/ec2onrails.rb", "Manifest", "Rakefile", "README.textile", "server/build-ec2onrails.sh", "server/files/etc/aliases", "server/files/etc/aliases.db", "server/files/etc/apache2/apache2.conf", "server/files/etc/apache2/conf.d/app.proxy_cluster.conf", "server/files/etc/apache2/conf.d/app.proxy_frontend.conf", "server/files/etc/apache2/mods-available/proxy.conf", "server/files/etc/apache2/sites-available/app.common", "server/files/etc/apache2/sites-available/app.custom", "server/files/etc/apache2/sites-available/default", "server/files/etc/apache2/sites-available/default-ssl", "server/files/etc/cron.d/backup_app_db_to_s3", "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/denyhosts.conf", "server/files/etc/dpkg/dpkg.cfg", "server/files/etc/ec2onrails/balancer_members", "server/files/etc/ec2onrails/README", "server/files/etc/ec2onrails/roles.yml", "server/files/etc/environment", "server/files/etc/god/app.god", "server/files/etc/god/db.god", "server/files/etc/god/examples/have_god_daemonize.god", "server/files/etc/god/master.conf", "server/files/etc/god/memcache.god", "server/files/etc/god/notifications.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/god", "server/files/etc/init.d/nginx", "server/files/etc/init.d/set_roles", "server/files/etc/logrotate.d/apache2", "server/files/etc/logrotate.d/mongrel", "server/files/etc/logrotate.d/nginx", "server/files/etc/memcached.conf", "server/files/etc/mongrel_cluster/app.yml", "server/files/etc/motd.tail", "server/files/etc/mysql/my.cnf", "server/files/etc/nginx/nginx.conf", "server/files/etc/postfix/main.cf", "server/files/etc/rcS.d/S91ec2-first-startup", "server/files/etc/rcS.d/S92ec2-every-startup", "server/files/etc/rcS.d/S99set_roles", "server/files/etc/ssh/sshd_config", "server/files/etc/sudoers", "server/files/etc/sudoers.full_access", "server/files/etc/sudoers.restricted_access", "server/files/etc/syslog.conf", "server/files/usr/bin/god", "server/files/usr/local/ec2onrails/bin/archive_file.rb", "server/files/usr/local/ec2onrails/bin/backup_app_db.rb", "server/files/usr/local/ec2onrails/bin/ec2_meta_data.rb", "server/files/usr/local/ec2onrails/bin/exec_runner", "server/files/usr/local/ec2onrails/bin/init_services.rb", "server/files/usr/local/ec2onrails/bin/optimize_mysql.rb", "server/files/usr/local/ec2onrails/bin/rails_env", "server/files/usr/local/ec2onrails/bin/rebundle.sh", "server/files/usr/local/ec2onrails/bin/restore_app_db.rb", "server/files/usr/local/ec2onrails/bin/set_rails_env", "server/files/usr/local/ec2onrails/bin/set_roles.rb", "server/files/usr/local/ec2onrails/bin/setup_web_proxy.rb", "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/god_patch.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/utils.rb", "server/files/usr/local/ec2onrails/lib/vendor/ini.rb", "server/files/usr/local/ec2onrails/startup-scripts/every-startup/get-hostname.sh", "server/files/usr/local/ec2onrails/startup-scripts/first-startup/create-dirs.sh", "server/files/usr/local/ec2onrails/startup-scripts/first-startup/generate-default-web-cert-and-key.sh", "server/files/usr/local/ec2onrails/startup-scripts/first-startup/misc.sh", "server/files/usr/local/ec2onrails/startup-scripts/first-startup/prepare-mysql-data-dir.sh", "server/files/usr/local/ec2onrails/startup-scripts/first-startup/README", "server/files/usr/local/ec2onrails/startup-scripts/first-startup/setup-credentials.sh", "server/files/usr/local/ec2onrails/startup-scripts/first-startup/setup-file-permissions.sh", "server/rakefile.rb", "setup.rb", "test/autobench.conf", "test/spec/lib/s3_helper_spec.rb", "test/spec/lib/s3_old.yml", "test/spec/test_files/test1", "test/spec/test_files/test2", "test/test_app/app/controllers/application.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/app/helpers/db_fast_helper.rb", "test/test_app/app/helpers/fast_helper.rb", "test/test_app/app/helpers/slow_helper.rb", "test/test_app/app/helpers/very_slow_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/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/routes.rb", "test/test_app/db/schema.rb", "test/test_app/doc/README_FOR_APP", "test/test_app/public/404.html", "test/test_app/public/500.html", "test/test_app/public/dispatch.cgi", "test/test_app/public/dispatch.fcgi", "test/test_app/public/dispatch.rb", "test/test_app/public/favicon.ico", "test/test_app/public/images/rails.png", "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/breakpointer", "test/test_app/script/console", "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/performance/request", "test/test_app/script/plugin", "test/test_app/script/process/inspector", "test/test_app/script/process/reaper", "test/test_app/script/process/spawner", "test/test_app/script/runner", "test/test_app/script/server", "test/test_app/test/functional/db_fast_controller_test.rb", "test/test_app/test/functional/fast_controller_test.rb", "test/test_app/test/functional/slow_controller_test.rb", "test/test_app/test/functional/very_slow_controller_test.rb", "test/test_app/test/test_helper.rb", "test/test_ec2onrails.rb", "test/test_helper.rb", "TODO"]
12
+ s.has_rdoc = true
13
+ s.homepage = %q{http://ec2onrails.rubyforge.org}
14
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Ec2onrails", "--main", "README.textile"]
15
+ s.require_paths = ["lib"]
16
+ s.rubyforge_project = %q{ec2onrails}
17
+ s.rubygems_version = %q{1.2.0}
18
+ s.summary = %q{Client-side libraries (Capistrano tasks) for managing and deploying to EC2 on Rails servers.}
19
+ s.test_files = ["test/test_app/test/functional/db_fast_controller_test.rb", "test/test_app/test/functional/fast_controller_test.rb", "test/test_app/test/functional/slow_controller_test.rb", "test/test_app/test/functional/very_slow_controller_test.rb", "test/test_app/test/test_helper.rb", "test/test_ec2onrails.rb", "test/test_helper.rb"]
20
+
21
+ if s.respond_to? :specification_version then
22
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
23
+ s.specification_version = 2
24
+
25
+ if current_version >= 3 then
26
+ s.add_runtime_dependency(%q<capistrano>, [">= 0", "= 2.4.3"])
27
+ s.add_runtime_dependency(%q<archive-tar-minitar>, [">= 0", "= 0.5.2"])
28
+ s.add_runtime_dependency(%q<optiflag>, [">= 0", "= 0.6.5"])
29
+ s.add_development_dependency(%q<rake>, [">= 0.7.1"])
30
+ else
31
+ s.add_dependency(%q<capistrano>, [">= 0", "= 2.4.3"])
32
+ s.add_dependency(%q<archive-tar-minitar>, [">= 0", "= 0.5.2"])
33
+ s.add_dependency(%q<optiflag>, [">= 0", "= 0.6.5"])
34
+ s.add_dependency(%q<rake>, [">= 0.7.1"])
35
+ end
36
+ else
37
+ s.add_dependency(%q<capistrano>, [">= 0", "= 2.4.3"])
38
+ s.add_dependency(%q<archive-tar-minitar>, [">= 0", "= 0.5.2"])
39
+ s.add_dependency(%q<optiflag>, [">= 0", "= 0.6.5"])
40
+ s.add_dependency(%q<rake>, [">= 0.7.1"])
41
+ end
42
+ end
data/examples/Capfile ADDED
@@ -0,0 +1,3 @@
1
+ load 'deploy' if respond_to?(:namespace) # cap2 differentiator
2
+ load 'config/deploy'
3
+ require 'ec2onrails/recipes'
@@ -0,0 +1,101 @@
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 :app, "ec2-34-xx-xx-xx.z-1.compute-1.amazonaws.com"
18
+ role :memcache, "ec2-12-xx-xx-xx.z-1.compute-1.amazonaws.com"
19
+ role :db, "ec2-56-xx-xx-xx.z-1.compute-1.amazonaws.com", :primary => true
20
+ # role :db, "ec2-56-xx-xx-xx.z-1.compute-1.amazonaws.com", :primary => true, :ebs_vol_id => 'vol-12345abc'
21
+ # optinally, you can specify Amazon's EBS volume ID if the database is persisted
22
+ # via Amazon's EBS. See the main README for more information.
23
+
24
+ # Whatever you set here will be taken set as the default RAILS_ENV value
25
+ # on the server. Your app and your hourly/daily/weekly/monthly scripts
26
+ # will run with RAILS_ENV set to this value.
27
+ set :rails_env, "production"
28
+
29
+ # EC2 on Rails config.
30
+ # NOTE: Some of these should be omitted if not needed.
31
+ set :ec2onrails_config, {
32
+ # S3 bucket and "subdir" used by the ec2onrails:db:restore task
33
+ # NOTE: this only applies if you are not using EBS
34
+ :restore_from_bucket => "your-bucket",
35
+ :restore_from_bucket_subdir => "database",
36
+
37
+ # S3 bucket and "subdir" used by the ec2onrails:db:archive task
38
+ # This does not affect the automatic backup of your MySQL db to S3, it's
39
+ # just for manually archiving a db snapshot to a different bucket if
40
+ # desired.
41
+ # NOTE: this only applies if you are not using EBS
42
+ :archive_to_bucket => "your-other-bucket",
43
+ :archive_to_bucket_subdir => "db-archive/#{Time.new.strftime('%Y-%m-%d--%H-%M-%S')}",
44
+
45
+ # Set a root password for MySQL. Run "cap ec2onrails:db:set_root_password"
46
+ # to enable this. This is optional, and after doing this the
47
+ # ec2onrails:db:drop task won't work, but be aware that MySQL accepts
48
+ # connections on the public network interface (you should block the MySQL
49
+ # port with the firewall anyway).
50
+ # If you don't care about setting the mysql root password then remove this.
51
+ :mysql_root_password => "your-mysql-root-password",
52
+
53
+ # Any extra Ubuntu packages to install if desired
54
+ # If you don't want to install extra packages then remove this.
55
+ :packages => ["logwatch", "imagemagick"],
56
+
57
+ # Any extra RubyGems to install if desired: can be "gemname" or if a
58
+ # particular version is desired "gemname -v 1.0.1"
59
+ # If you don't want to install extra rubygems then remove this
60
+ # NOTE: if you are using rails 2.1, ec2onrails calls 'sudo rake gem:install',
61
+ # which will install gems defined in your rails configuration
62
+ :rubygems => ["rmagick", "rfacebook -v 0.9.7"],
63
+
64
+ # Defines the web proxy that will be used. Choices are :apache or :nginx
65
+ :web_proxy_server => :apache,
66
+
67
+ # extra security measures are taken if this is true, BUT it makes initial
68
+ # experimentation and setup a bit tricky. For example, if you do not
69
+ # have your ssh keys setup correctly, you will be locked out of your
70
+ # server after 3 attempts for upto 3 months.
71
+ :harden_server => false,
72
+
73
+ # Set the server timezone. run "cap -e ec2onrails:server:set_timezone" for
74
+ # details
75
+ :timezone => "UTC",
76
+
77
+ # Files to deploy to the server (they'll be owned by root). It's intended
78
+ # mainly for customized config files for new packages installed via the
79
+ # ec2onrails:server:install_packages task. Subdirectories and files inside
80
+ # here will be placed in the same structure relative to the root of the
81
+ # server's filesystem.
82
+ # If you don't need to deploy customized config files to the server then
83
+ # remove this.
84
+ :server_config_files_root => "../server_config",
85
+
86
+ # If config files are deployed, some services might need to be restarted.
87
+ # If you don't need to deploy customized config files to the server then
88
+ # remove this.
89
+ :services_to_restart => %w(postfix sysklogd),
90
+
91
+ # Set an email address to forward admin mail messages to. If you don't
92
+ # want to receive mail from the server (e.g. monit alert messages) then
93
+ # remove this.
94
+ :mail_forward_address => "you@yourdomain.com",
95
+
96
+ # Set this if you want SSL to be enabled on the web server. The SSL cert
97
+ # and key files need to exist on the server, The cert file should be in
98
+ # /etc/ssl/certs/default.pem and the key file should be in
99
+ # /etc/ssl/private/default.key (see :server_config_files_root).
100
+ :enable_ssl => true
101
+ }
data/examples/s3.yml ADDED
@@ -0,0 +1,9 @@
1
+ staging:
2
+ aws_access_key: ABC123
3
+ aws_secret_access_key: abc123abc123abc123abc123
4
+ bucket_base_name: yourbucket
5
+
6
+ production:
7
+ aws_access_key: DEF456
8
+ aws_secret_access_key: def456def456def456def456
9
+ bucket_base_name: yourbucket
@@ -0,0 +1,43 @@
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
+ # since init scripts might have the execute bit unset by the set_roles script we need to check
10
+ sudo "sh -c 'if [ -x /etc/init.d/#{script} ] ; then /etc/init.d/#{script} #{arg}; fi'"
11
+ end
12
+
13
+ # return hostnames for the role named role_sym that has the specified options
14
+ def hostnames_for_role(role_sym, options = {})
15
+ role = roles[role_sym]
16
+ unless role
17
+ return []
18
+ end
19
+ # make sure we match the server with all the passed in options, BUT the server can
20
+ # have additional options defined. e.g.: :primary => true and :ebs_vol_id => 'vol-1234abcd'
21
+ # but we want to select the server where :primary => true
22
+ role.select{|s|
23
+ match = true
24
+ options.each_pair{|k,v| match = false if s.options[k] != v}
25
+ }.collect{|s| s.host}
26
+ end
27
+
28
+ # Like the capture method, but does not print out error stream and swallows
29
+ # an exception if the process's exit code != 0
30
+ def quiet_capture(command, options={})
31
+ output = ""
32
+ invoke_command(command, options.merge(:once => true)) do |ch, stream, data|
33
+ case stream
34
+ when :out then output << data
35
+ # when :err then warn "[err :: #{ch[:server]}] #{data}"
36
+ end
37
+ end
38
+ ensure
39
+ return (output || '').strip
40
+ end
41
+
42
+ end
43
+ end