mdh-ec2onrails 0.9.10
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +180 -0
- data/COPYING +339 -0
- data/Manifest +162 -0
- data/README.textile +214 -0
- data/Rakefile +36 -0
- data/TODO +102 -0
- data/ec2onrails.gemspec +42 -0
- data/examples/Capfile +3 -0
- data/examples/deploy.rb +101 -0
- data/examples/s3.yml +9 -0
- data/lib/ec2onrails.rb +20 -0
- data/lib/ec2onrails/capistrano_utils.rb +43 -0
- data/lib/ec2onrails/recipes.rb +844 -0
- data/lib/ec2onrails/version.rb +31 -0
- data/server/build-ec2onrails.sh +44 -0
- data/server/files/etc/aliases +5 -0
- data/server/files/etc/aliases.db +0 -0
- data/server/files/etc/apache2/apache2.conf +295 -0
- data/server/files/etc/apache2/conf.d/app.proxy_cluster.conf +7 -0
- data/server/files/etc/apache2/conf.d/app.proxy_frontend.conf +10 -0
- data/server/files/etc/apache2/mods-available/proxy.conf +18 -0
- data/server/files/etc/apache2/sites-available/app.common +56 -0
- data/server/files/etc/apache2/sites-available/app.custom +0 -0
- data/server/files/etc/apache2/sites-available/default +14 -0
- data/server/files/etc/apache2/sites-available/default-ssl +19 -0
- data/server/files/etc/cron.d/backup_app_db_to_s3 +16 -0
- data/server/files/etc/cron.daily/app +9 -0
- data/server/files/etc/cron.daily/logrotate_post +19 -0
- data/server/files/etc/cron.hourly/app +10 -0
- data/server/files/etc/cron.monthly/app +10 -0
- data/server/files/etc/cron.weekly/app +10 -0
- data/server/files/etc/denyhosts.conf +628 -0
- data/server/files/etc/dpkg/dpkg.cfg +13 -0
- data/server/files/etc/ec2onrails/README +32 -0
- data/server/files/etc/ec2onrails/balancer_members +6 -0
- data/server/files/etc/ec2onrails/roles.yml +5 -0
- data/server/files/etc/environment +2 -0
- data/server/files/etc/god/app.god +35 -0
- data/server/files/etc/god/db.god +17 -0
- data/server/files/etc/god/examples/have_god_daemonize.god +18 -0
- data/server/files/etc/god/master.conf +35 -0
- data/server/files/etc/god/memcache.god +15 -0
- data/server/files/etc/god/notifications.god +14 -0
- data/server/files/etc/god/system.god +34 -0
- data/server/files/etc/god/web.god +36 -0
- data/server/files/etc/init.d/ec2-every-startup +29 -0
- data/server/files/etc/init.d/ec2-first-startup +36 -0
- data/server/files/etc/init.d/god +42 -0
- data/server/files/etc/init.d/nginx +78 -0
- data/server/files/etc/init.d/set_roles +3 -0
- data/server/files/etc/logrotate.d/apache2 +16 -0
- data/server/files/etc/logrotate.d/mongrel +11 -0
- data/server/files/etc/logrotate.d/nginx +11 -0
- data/server/files/etc/memcached.conf +47 -0
- data/server/files/etc/mongrel_cluster/app.yml +9 -0
- data/server/files/etc/motd.tail +13 -0
- data/server/files/etc/mysql/my.cnf +152 -0
- data/server/files/etc/nginx/nginx.conf +296 -0
- data/server/files/etc/postfix/main.cf +4 -0
- data/server/files/etc/rcS.d/S91ec2-first-startup +1 -0
- data/server/files/etc/rcS.d/S92ec2-every-startup +1 -0
- data/server/files/etc/rcS.d/S99set_roles +1 -0
- data/server/files/etc/ssh/sshd_config +94 -0
- data/server/files/etc/sudoers +1 -0
- data/server/files/etc/sudoers.full_access +26 -0
- data/server/files/etc/sudoers.restricted_access +28 -0
- data/server/files/etc/syslog.conf +69 -0
- data/server/files/usr/bin/god +26 -0
- data/server/files/usr/local/ec2onrails/COPYING +339 -0
- data/server/files/usr/local/ec2onrails/bin/archive_file.rb +44 -0
- data/server/files/usr/local/ec2onrails/bin/backup_app_db.rb +159 -0
- data/server/files/usr/local/ec2onrails/bin/ec2_meta_data.rb +80 -0
- data/server/files/usr/local/ec2onrails/bin/exec_runner +73 -0
- data/server/files/usr/local/ec2onrails/bin/init_services.rb +64 -0
- data/server/files/usr/local/ec2onrails/bin/optimize_mysql.rb +348 -0
- data/server/files/usr/local/ec2onrails/bin/rails_env +35 -0
- data/server/files/usr/local/ec2onrails/bin/rebundle.sh +70 -0
- data/server/files/usr/local/ec2onrails/bin/restore_app_db.rb +58 -0
- data/server/files/usr/local/ec2onrails/bin/set_rails_env +40 -0
- data/server/files/usr/local/ec2onrails/bin/set_roles.rb +87 -0
- data/server/files/usr/local/ec2onrails/bin/setup_web_proxy.rb +109 -0
- data/server/files/usr/local/ec2onrails/config +30 -0
- data/server/files/usr/local/ec2onrails/lib/aws_helper.rb +76 -0
- data/server/files/usr/local/ec2onrails/lib/god_helper.rb +129 -0
- data/server/files/usr/local/ec2onrails/lib/god_patch.rb +43 -0
- data/server/files/usr/local/ec2onrails/lib/mysql_helper.rb +101 -0
- data/server/files/usr/local/ec2onrails/lib/roles_helper.rb +151 -0
- data/server/files/usr/local/ec2onrails/lib/s3_helper.rb +99 -0
- data/server/files/usr/local/ec2onrails/lib/utils.rb +16 -0
- data/server/files/usr/local/ec2onrails/lib/vendor/ini.rb +268 -0
- data/server/files/usr/local/ec2onrails/startup-scripts/every-startup/get-hostname.sh +25 -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.sh +39 -0
- data/server/files/usr/local/ec2onrails/startup-scripts/first-startup/generate-default-web-cert-and-key.sh +49 -0
- data/server/files/usr/local/ec2onrails/startup-scripts/first-startup/misc.sh +27 -0
- data/server/files/usr/local/ec2onrails/startup-scripts/first-startup/prepare-mysql-data-dir.sh +24 -0
- data/server/files/usr/local/ec2onrails/startup-scripts/first-startup/setup-credentials.sh +29 -0
- data/server/files/usr/local/ec2onrails/startup-scripts/first-startup/setup-file-permissions.sh +30 -0
- data/server/rakefile.rb +248 -0
- data/setup.rb +1585 -0
- data/test/autobench.conf +60 -0
- data/test/spec/lib/s3_helper_spec.rb +134 -0
- data/test/spec/lib/s3_old.yml +3 -0
- data/test/spec/test_files/test1 +0 -0
- data/test/spec/test_files/test2 +0 -0
- data/test/test_app/Capfile +3 -0
- data/test/test_app/README +182 -0
- data/test/test_app/Rakefile +10 -0
- data/test/test_app/app/controllers/application.rb +7 -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/app/helpers/db_fast_helper.rb +2 -0
- data/test/test_app/app/helpers/fast_helper.rb +2 -0
- data/test/test_app/app/helpers/slow_helper.rb +2 -0
- data/test/test_app/app/helpers/very_slow_helper.rb +2 -0
- data/test/test_app/config/boot.rb +109 -0
- data/test/test_app/config/database.yml +19 -0
- data/test/test_app/config/deploy.rb +21 -0
- data/test/test_app/config/environment.rb +60 -0
- data/test/test_app/config/environments/development.rb +21 -0
- data/test/test_app/config/environments/production.rb +18 -0
- data/test/test_app/config/environments/test.rb +19 -0
- data/test/test_app/config/routes.rb +27 -0
- data/test/test_app/db/schema.rb +7 -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/500.html +30 -0
- data/test/test_app/public/dispatch.cgi +10 -0
- data/test/test_app/public/dispatch.fcgi +24 -0
- data/test/test_app/public/dispatch.rb +10 -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/javascripts/application.js +2 -0
- data/test/test_app/public/javascripts/controls.js +963 -0
- data/test/test_app/public/javascripts/dragdrop.js +972 -0
- data/test/test_app/public/javascripts/effects.js +1120 -0
- data/test/test_app/public/javascripts/prototype.js +4225 -0
- data/test/test_app/public/robots.txt +1 -0
- data/test/test_app/script/about +3 -0
- data/test/test_app/script/breakpointer +3 -0
- data/test/test_app/script/console +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/performance/request +3 -0
- data/test/test_app/script/plugin +3 -0
- data/test/test_app/script/process/inspector +3 -0
- data/test/test_app/script/process/reaper +3 -0
- data/test/test_app/script/process/spawner +3 -0
- data/test/test_app/script/runner +3 -0
- data/test/test_app/script/server +3 -0
- data/test/test_app/test/functional/db_fast_controller_test.rb +18 -0
- data/test/test_app/test/functional/fast_controller_test.rb +18 -0
- data/test/test_app/test/functional/slow_controller_test.rb +18 -0
- data/test/test_app/test/functional/very_slow_controller_test.rb +18 -0
- data/test/test_app/test/test_helper.rb +28 -0
- data/test/test_ec2onrails.rb +11 -0
- data/test/test_helper.rb +2 -0
- metadata +274 -0
@@ -0,0 +1,35 @@
|
|
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 the value that's specified
|
23
|
+
# in the the mongrel_cluster config file. If a command isn't given as an
|
24
|
+
# argument it simply prints the value of RAILS_ENV
|
25
|
+
|
26
|
+
require "yaml"
|
27
|
+
|
28
|
+
@rails_env = YAML::load_file("/etc/mongrel_cluster/app.yml")["environment"]
|
29
|
+
|
30
|
+
if ARGV.any?
|
31
|
+
result = system "env RAILS_ENV=#{@rails_env} #{ARGV.join(' ')}"
|
32
|
+
raise("error: #{$?}") unless result
|
33
|
+
else
|
34
|
+
puts @rails_env
|
35
|
+
end
|
@@ -0,0 +1,70 @@
|
|
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
|
+
cleanup() {
|
23
|
+
rm -f /ec2onrails-first-boot
|
24
|
+
}
|
25
|
+
|
26
|
+
fail() {
|
27
|
+
echo "`basename $0`: ERROR: $1"
|
28
|
+
cleanup
|
29
|
+
exit 1
|
30
|
+
}
|
31
|
+
|
32
|
+
if [ `whoami` != 'root' ] ; then
|
33
|
+
fail "This script must be run as root, use 'sudo $0'".
|
34
|
+
fi
|
35
|
+
|
36
|
+
. "/usr/local/ec2onrails/config"
|
37
|
+
|
38
|
+
TIMESTAMP="`date '+%Y-%m-%d--%H-%M-%S'`"
|
39
|
+
NEW_BUCKET_NAME="$BUCKET_BASE_NAME-image-$TIMESTAMP"
|
40
|
+
|
41
|
+
if [ ! -e /usr/local/ec2-api-tools ] ; then
|
42
|
+
echo "The EC2 api command-line tools don't seem to be installed."
|
43
|
+
echo "To install them (and Java, which they require), press enter..."
|
44
|
+
read
|
45
|
+
curl http://s3.amazonaws.com/ec2-downloads/ec2-api-tools.zip > /tmp/ec2-api-tools.zip || fail "couldn't download ec2-api-tools.zip"
|
46
|
+
unzip /tmp/ec2-api-tools.zip -d /usr/local || fail "couldn't unzip ec2-api-tools.zip"
|
47
|
+
chmod -R go-w /usr/local/ec2-api-tools*
|
48
|
+
ln -sf /usr/local/ec2-api-tools-* /usr/local/ec2-api-tools
|
49
|
+
aptitude install -y sun-java6-jre || fail "couldn't install Java package"
|
50
|
+
fi
|
51
|
+
|
52
|
+
echo "--> Clearing apt cache..."
|
53
|
+
aptitude clean
|
54
|
+
|
55
|
+
touch /ec2onrails-first-boot || fail
|
56
|
+
|
57
|
+
echo "--> Clearing sensitive files..."
|
58
|
+
rm -f /root/{.bash_history,.lesshst}
|
59
|
+
|
60
|
+
echo "--> Creating image..."
|
61
|
+
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"
|
62
|
+
|
63
|
+
echo "--> Uploading image to $NEW_BUCKET_NAME"
|
64
|
+
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"
|
65
|
+
|
66
|
+
echo "--> Registering image..."
|
67
|
+
ec2-register "$NEW_BUCKET_NAME/image.manifest.xml" || fail "ec2-register failed"
|
68
|
+
|
69
|
+
echo "--> Done."
|
70
|
+
cleanup
|
@@ -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}-#{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,40 @@
|
|
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 value of "environment" in the the mongrel_cluster
|
23
|
+
# config file.
|
24
|
+
|
25
|
+
require "yaml"
|
26
|
+
require "erb"
|
27
|
+
|
28
|
+
if ARGV.length != 1
|
29
|
+
puts "usage: set_rails_env <value>"
|
30
|
+
exit 1
|
31
|
+
end
|
32
|
+
|
33
|
+
@rails_env = ARGV[0]
|
34
|
+
|
35
|
+
# update mongrel_cluster config
|
36
|
+
config = YAML::load_file("/etc/mongrel_cluster/app.yml")
|
37
|
+
config["environment"] = @rails_env
|
38
|
+
File.open("/etc/mongrel_cluster/app.yml", 'w') do |f|
|
39
|
+
YAML.dump(config, f)
|
40
|
+
end
|
@@ -0,0 +1,87 @@
|
|
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
|
+
# To customze the apache or nginx config files, you can setup a template like:
|
22
|
+
# /etc/ec2onrails/balancer_members.erb
|
23
|
+
# /etc/ec2onrails/nginx_upstream_members.erb
|
24
|
+
#
|
25
|
+
|
26
|
+
require 'erb'
|
27
|
+
require "#{File.dirname(__FILE__)}/../lib/roles_helper"
|
28
|
+
include Ec2onrails::RolesHelper
|
29
|
+
|
30
|
+
puts "Roles: "
|
31
|
+
pp roles
|
32
|
+
|
33
|
+
|
34
|
+
# web role:
|
35
|
+
if in_role?(:web)
|
36
|
+
puts "setting up reverse proxy for web role. starting port: #{web_starting_port} up to #{web_starting_port + web_num_instances - 1}"
|
37
|
+
|
38
|
+
## lets update/modify web balancer file templates, if need be
|
39
|
+
files_written = []
|
40
|
+
Dir["/etc/ec2onrails/*.erb"].each do |filename|
|
41
|
+
#what other variables would be helpful?
|
42
|
+
@web_port_range = web_port_range
|
43
|
+
@web_starting_port = web_starting_port
|
44
|
+
@roles = roles
|
45
|
+
file = ERB.new(IO.read(filename)).result(binding)
|
46
|
+
file_name = filename.sub(/\.erb$/, '')
|
47
|
+
files_written << file_name
|
48
|
+
File.open(file_name, 'w'){|f| f << file}
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
if system("which apache2")
|
53
|
+
apache_config_file = "/etc/ec2onrails/balancer_members"
|
54
|
+
unless files_written.index(apache_config_file)
|
55
|
+
File.open(apache_config_file, "w") do |f|
|
56
|
+
roles[:app].each do |address|
|
57
|
+
web_port_range.each do |port|
|
58
|
+
f << "BalancerMember http://#{address}:#{port}\n"
|
59
|
+
end
|
60
|
+
f << "\n"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
if system("which nginx")
|
67
|
+
nginx_config_file = "/etc/ec2onrails/nginx_upstream_members"
|
68
|
+
unless files_written.index(nginx_config_file)
|
69
|
+
File.open(nginx_config_file, "w") do |f|
|
70
|
+
f << "upstream mongrel{\n"
|
71
|
+
roles[:app].each do |address|
|
72
|
+
web_port_range.each do |port|
|
73
|
+
f << "\tserver #{address}:#{port};\n"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
f << "fair;\n}\n"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
if in_role?(:db_primary) || in_role?(:app)
|
83
|
+
db_primary_addr = roles[:db_primary][0]
|
84
|
+
add_etc_hosts_entry('db_primary', db_primary_addr)
|
85
|
+
end
|
86
|
+
|
87
|
+
|
@@ -0,0 +1,109 @@
|
|
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
|
+
# enable either apache or nginx as the proxy server.
|
22
|
+
#
|
23
|
+
# to do this, we symlink a few folders to use a common name web_proxy,
|
24
|
+
# which makes the handling of log files and what not easier to keep
|
25
|
+
# track of
|
26
|
+
|
27
|
+
require "rubygems"
|
28
|
+
require "optiflag"
|
29
|
+
require "#{File.dirname(__FILE__)}/../lib/roles_helper"
|
30
|
+
include Ec2onrails::RolesHelper
|
31
|
+
|
32
|
+
PROXY_CHOICES = ["apache","nginx"]
|
33
|
+
module CommandLineArgs extend OptiFlagSet
|
34
|
+
flag "mode" do
|
35
|
+
# this is our second new clause-level modifier
|
36
|
+
value_in_set PROXY_CHOICES
|
37
|
+
description "The web proxy server that will be installed and used."
|
38
|
+
end
|
39
|
+
and_process!
|
40
|
+
end
|
41
|
+
|
42
|
+
# make the log directories even if they won't be used...
|
43
|
+
# keeps logrotate configs easy
|
44
|
+
sudo "mkdir -p -m 755 /mnt/log/apache2"
|
45
|
+
sudo "mkdir -p -m 755 /mnt/log/nginx"
|
46
|
+
|
47
|
+
case ARGV.flags.mode
|
48
|
+
when 'apache'
|
49
|
+
# it is a *LOT* easier to have apache2 pre-installed on the image
|
50
|
+
# (and have the default server configs placed after apache2 is installed)
|
51
|
+
#
|
52
|
+
# so assume it is installed by this time
|
53
|
+
# sudo "sh -c 'export DEBIAN_FRONTEND=noninteractive; aptitude -q -y install apache2'"
|
54
|
+
|
55
|
+
sudo "a2enmod deflate"
|
56
|
+
sudo "a2enmod proxy_balancer"
|
57
|
+
sudo "a2enmod proxy_http"
|
58
|
+
sudo "a2enmod rewrite"
|
59
|
+
|
60
|
+
|
61
|
+
sudo "rm -rf /var/log/apache2"
|
62
|
+
sudo "ln -sf /mnt/log/apache2 /var/log/apache2"
|
63
|
+
sudo "ln -sf /etc/init.d/apache2 /etc/init.d/web_proxy"
|
64
|
+
sudo "ln -sf /mnt/log/apache2 /mnt/log/web_proxy"
|
65
|
+
|
66
|
+
when 'nginx'
|
67
|
+
#nginx does not have a precompiled package, so....
|
68
|
+
|
69
|
+
src_dir = "#{Dir.pwd}/src"
|
70
|
+
|
71
|
+
nginx_img = "http://sysoev.ru/nginx/nginx-0.6.32.tar.gz"
|
72
|
+
fair_bal_img = "http://github.com/gnosek/nginx-upstream-fair/tarball/master"
|
73
|
+
nginx_dir = "#{src_dir}/nginx"
|
74
|
+
puts "installing nginx 6.32 (src dir: #{nginx_dir})"
|
75
|
+
run "mkdir -p -m 755 #{nginx_dir} && rm -rf #{nginx_dir}/*"
|
76
|
+
run "mkdir -p -m 755 #{nginx_dir}/modules/nginx-upstream-fair"
|
77
|
+
run "cd #{nginx_dir} && wget -q #{nginx_img} && tar -xzf nginx-0.6.32.tar.gz"
|
78
|
+
|
79
|
+
run "cd #{nginx_dir}/modules && \
|
80
|
+
wget -q #{fair_bal_img} && \
|
81
|
+
tar -xzf *nginx-upstream-fair*.tar.gz -o -C ./nginx-upstream-fair && \
|
82
|
+
mv nginx-upstream-fair/*/* nginx-upstream-fair/."
|
83
|
+
|
84
|
+
sudo "sh -c 'export DEBIAN_FRONTEND=noninteractive; aptitude -q -y install libpcre3-dev'"
|
85
|
+
|
86
|
+
run "cd #{nginx_dir}/nginx-0.6.32 && \
|
87
|
+
./configure \
|
88
|
+
--sbin-path=/usr/sbin \
|
89
|
+
--conf-path=/etc/nginx/nginx.conf \
|
90
|
+
--pid-path=/var/run/nginx.pid \
|
91
|
+
--with-http_ssl_module \
|
92
|
+
--with-http_stub_status_module \
|
93
|
+
--add-module=#{nginx_dir}/modules/nginx-upstream-fair && \
|
94
|
+
make && \
|
95
|
+
sudo make install"
|
96
|
+
|
97
|
+
run "sudo rm -rf /usr/local/nginx/logs; sudo ln -sf /mnt/log/nginx /usr/local/nginx/logs"
|
98
|
+
#an init.d script is in the default server config... lets link it up
|
99
|
+
sudo "ln -sf /etc/init.d/nginx /etc/init.d/web_proxy"
|
100
|
+
sudo "ln -sf /mnt/log/nginx /mnt/log/web_proxy"
|
101
|
+
# sudo "ln -sf /usr/local/nginx/sbin/nginx /usr/sbin/nginx"
|
102
|
+
# sudo "ln -sf /usr/local/nginx/conf /etc/nginx"
|
103
|
+
else
|
104
|
+
puts "The mode: #{ARGV.flags.mode} was not recognized. Must be one of these #{["apache","nginx"].join(', ')}"
|
105
|
+
exit 1
|
106
|
+
end
|
107
|
+
|
108
|
+
#restart god... the config file will automatically pick up the changes but we need to restart god
|
109
|
+
sudo("/etc/init.d/god restart")
|
@@ -0,0 +1,30 @@
|
|
1
|
+
############################################################
|
2
|
+
# This script is sourced by .bashrc and by /usr/local/ec2onrails/rebundle.sh
|
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
|
+
export JAVA_HOME="/usr/lib/jvm/java-6-sun"
|
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,76 @@
|
|
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 'aws/s3'
|
21
|
+
require 'yaml'
|
22
|
+
require 'erb'
|
23
|
+
require 'fileutils'
|
24
|
+
require "#{File.dirname(__FILE__)}/utils"
|
25
|
+
|
26
|
+
module Ec2onrails
|
27
|
+
class AwsHelper
|
28
|
+
|
29
|
+
DEFAULT_CONFIG_FILE = "/mnt/app/current/config/aws.yml"
|
30
|
+
DEFAULT_CONFIG_FILE_OLD = "/mnt/app/current/config/s3.yml"
|
31
|
+
|
32
|
+
# make attributes available for specs
|
33
|
+
attr_accessor :config_file
|
34
|
+
attr_accessor :rails_env
|
35
|
+
attr_accessor :aws_access_key
|
36
|
+
attr_accessor :aws_secret_access_key
|
37
|
+
attr_accessor :bucket_base_name
|
38
|
+
|
39
|
+
def initialize(config_file = AwsHelper.default_config_file, rails_env = Utils.rails_env)
|
40
|
+
@rails_env = rails_env
|
41
|
+
@config_file = config_file
|
42
|
+
|
43
|
+
if File.exists?(@config_file)
|
44
|
+
aws_config = YAML::load(ERB.new(File.read(@config_file)).result)
|
45
|
+
|
46
|
+
# try to load the section for the current RAILS_ENV
|
47
|
+
section = aws_config[@rails_env]
|
48
|
+
if section.nil?
|
49
|
+
# fall back to keys at the root of the tree
|
50
|
+
section = aws_config
|
51
|
+
end
|
52
|
+
|
53
|
+
@aws_access_key = section['aws_access_key']
|
54
|
+
@aws_secret_access_key = section['aws_secret_access_key']
|
55
|
+
@bucket_base_name = section['bucket_base_name']
|
56
|
+
else
|
57
|
+
if !File.exists?('/mnt/aws-config/config')
|
58
|
+
raise "Can't find either #{@config_file} or /mnt/aws-config/config"
|
59
|
+
end
|
60
|
+
@aws_access_key = get_bash_config('AWS_ACCESS_KEY_ID')
|
61
|
+
@aws_secret_access_key = get_bash_config('AWS_SECRET_ACCESS_KEY')
|
62
|
+
@bucket_base_name = get_bash_config('BUCKET_BASE_NAME')
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# load an env value from the shared config file
|
67
|
+
def get_bash_config(name)
|
68
|
+
`bash -c 'source /mnt/aws-config/config; echo $#{name}'`.strip
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.default_config_file
|
72
|
+
File.exists?(DEFAULT_CONFIG_FILE) ? DEFAULT_CONFIG_FILE : DEFAULT_CONFIG_FILE_OLD
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|