ec2_setup 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/README +6 -0
- data/Rakefile +1 -0
- data/ec2_setup.gemspec +24 -0
- data/lib/ec2_setup.rb +11 -0
- data/lib/ec2_setup/version.rb +3 -0
- data/lib/tasks/ec2setup.rake +138 -0
- metadata +64 -0
data/Gemfile
ADDED
data/README
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/ec2_setup.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "ec2_setup/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "ec2_setup"
|
7
|
+
s.version = Ec2Setup::VERSION
|
8
|
+
s.authors = ["Lee Atchison"]
|
9
|
+
s.email = ["lee@leeatchison.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Setup an EC2 instance running Amazon Linux to be a Rails webserver.}
|
12
|
+
s.description = %q{Setup an EC2 instance running Amazon Linux to be a Rails webserver.}
|
13
|
+
|
14
|
+
s.rubyforge_project = "ec2_setup"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
# s.add_development_dependency "rspec"
|
23
|
+
s.add_runtime_dependency "vlad"
|
24
|
+
end
|
data/lib/ec2_setup.rb
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
#
|
2
|
+
#
|
3
|
+
# EC2 Setup
|
4
|
+
#
|
5
|
+
#
|
6
|
+
namespace :setup do
|
7
|
+
desc "Setup a new app server on EC2 without the app. Useful for creating an EBS image. Usage: HOSTS=<ec2_server> PROMPTNAME=<promptname> [DNSNAME=<desired_name>]."
|
8
|
+
remote_task :ec2_core do
|
9
|
+
ENV["DNSNAME"] ||= ENV["HOSTS"]
|
10
|
+
if ENV["HOSTS"].nil? or ENV["HOSTS"]=="" or ENV["PROMPTNAME"].nil? or ENV["PROMPTNAME"]=="" then
|
11
|
+
puts "Usage:"
|
12
|
+
puts "rake setup:ec2_core HOSTS=<ec2_server> PROMPTNAME=<promptname> [DNSNAME=<desired_name>]"
|
13
|
+
puts "Where:"
|
14
|
+
puts " HOSTS - hostname of the EC2 instance to setup."
|
15
|
+
puts " DNSNAME - The ultimate hostname that the EC2 instance will use."
|
16
|
+
exit
|
17
|
+
end
|
18
|
+
break unless target_host == ENV["HOSTS"]
|
19
|
+
puts "Setup EC2 instance #{target_host} for application #{application}..."
|
20
|
+
|
21
|
+
#
|
22
|
+
# Yum Packages
|
23
|
+
#
|
24
|
+
packages=[
|
25
|
+
"gcc", "gcc-c++", "make",
|
26
|
+
"openssl-devel","libcurl-devel",
|
27
|
+
"libxml2","libxml2-devel",
|
28
|
+
"libxslt","libxslt-devel",
|
29
|
+
"mysql","mysql-devel",
|
30
|
+
"openssl","zlib",
|
31
|
+
"pcre","pcre-devel",
|
32
|
+
"git",
|
33
|
+
"rubygems","ruby-devel"
|
34
|
+
]
|
35
|
+
|
36
|
+
#
|
37
|
+
# Core Gems
|
38
|
+
#
|
39
|
+
core_gems=[
|
40
|
+
"bundler",
|
41
|
+
"bluepill",
|
42
|
+
"unicorn"
|
43
|
+
]
|
44
|
+
|
45
|
+
|
46
|
+
#
|
47
|
+
# Setup ~ec2-user and ~root
|
48
|
+
#
|
49
|
+
rsync "#{ENV['HOME']}/.ssh/id_rsa","~/.ssh/id_rsa"
|
50
|
+
rsync "config/templates/known_hosts","~/.ssh/known_hosts"
|
51
|
+
put "~/.bashrc" do
|
52
|
+
File.read("config/templates/bashrc.tmpl").gsub("%%%PROMPTNAME%%%",ENV["PROMPTNAME"])
|
53
|
+
end
|
54
|
+
run "chmod 600 ~/.bashrc ~/.ssh/known_hosts"
|
55
|
+
run "chmod 400 ~/.ssh/id_rsa"
|
56
|
+
sudo "cp ~ec2-user/.bashrc ~root/.bashrc"
|
57
|
+
sudo "cp ~ec2-user/.ssh/known_hosts ~root/.ssh/known_hosts"
|
58
|
+
sudo "cp ~ec2-user/.ssh/id_rsa ~root/.ssh/id_rsa"
|
59
|
+
sudo "chmod 600 ~root/.bashrc ~root/.ssh/known_hosts"
|
60
|
+
sudo "chmod 400 ~root/.ssh/id_rsa"
|
61
|
+
sudo "hostname #{ENV["DNSNAME"]}" if ENV["DNSNAME"]!=ENV["HOSTS"]
|
62
|
+
|
63
|
+
#
|
64
|
+
# Yum Packages
|
65
|
+
#
|
66
|
+
sudo "yum -y remove ruby"
|
67
|
+
sudo "yum -y install "+packages.join(' ')
|
68
|
+
sudo "yum -y update"
|
69
|
+
|
70
|
+
|
71
|
+
#
|
72
|
+
# Setup Users
|
73
|
+
#
|
74
|
+
sudo "groupadd -f apps"
|
75
|
+
sudo "useradd -g apps -c \"Nginx Webserver\" nginx"
|
76
|
+
sudo "useradd -g apps -c \"Unicorn Appserver\" unicorn"
|
77
|
+
sudo "useradd -g apps -c \"Resque Background Tasks\" resque"
|
78
|
+
sudo "useradd -g apps -c \"Bluepill Process Monitoring\" bluepill"
|
79
|
+
sudo "usermod -a -G apps ec2-user"
|
80
|
+
|
81
|
+
#
|
82
|
+
# Log directory setup
|
83
|
+
#
|
84
|
+
sudo "chgrp apps /var/log"
|
85
|
+
sudo "chmod 775 /var/log"
|
86
|
+
|
87
|
+
#
|
88
|
+
# Ruby & Core Gems
|
89
|
+
#
|
90
|
+
ruby_version="ruby-1.9.2-p290"
|
91
|
+
run "rm -f /tmp/#{ruby_version}.tz"
|
92
|
+
run "rm -rf /tmp/#{ruby_version}"
|
93
|
+
run "wget -O /tmp/#{ruby_version}.tz http://ftp.ruby-lang.org/pub/ruby/1.9/#{ruby_version}.tar.gz"
|
94
|
+
run "(cd /tmp;tar xzf #{ruby_version}.tz)"
|
95
|
+
run "(cd /tmp/#{ruby_version};./configure --prefix=/usr)"
|
96
|
+
run "(cd /tmp/#{ruby_version};make)"
|
97
|
+
run "(cd /tmp/#{ruby_version};sudo make install)"
|
98
|
+
sudo "gem install "+core_gems.join(' ')
|
99
|
+
|
100
|
+
#
|
101
|
+
# Nginx
|
102
|
+
#
|
103
|
+
nginx_version="nginx-1.0.8"
|
104
|
+
run "rm -f /tmp/#{nginx_version}.tz"
|
105
|
+
run "rm -rf /tmp/#{nginx_version}"
|
106
|
+
run "wget -O /tmp/#{nginx_version}.tz http://nginx.org/download/#{nginx_version}.tar.gz"
|
107
|
+
run "(cd /tmp;tar xzf #{nginx_version}.tz)"
|
108
|
+
run "(cd /tmp/#{nginx_version};./configure --prefix=/opt/nginx --with-http_ssl_module --with-http_realip_module)"
|
109
|
+
run "(cd /tmp/#{nginx_version};make)"
|
110
|
+
run "(cd /tmp/#{nginx_version};sudo make install)"
|
111
|
+
sudo "chown nginx /opt/nginx/conf/"
|
112
|
+
sudo "chgrp apps /opt/nginx/conf/"
|
113
|
+
sudo "chmod 771 /opt/nginx/conf/"
|
114
|
+
sudo "mkdir -p /var/log/nginx"
|
115
|
+
sudo "chown nginx /var/log/nginx"
|
116
|
+
sudo "chgrp apps /var/log/nginx"
|
117
|
+
sudo "chmod 771 /var/log/nginx"
|
118
|
+
sudo "rm -f /opt/nginx/conf/nginx.conf" # Don't leave the default one lying around
|
119
|
+
|
120
|
+
#
|
121
|
+
# Unicorn: Setup Application Base
|
122
|
+
#
|
123
|
+
sudo "mkdir -p /var/server"
|
124
|
+
sudo "chown unicorn /var/server"
|
125
|
+
sudo "chgrp apps /var/server"
|
126
|
+
sudo "chmod 771 /var/server"
|
127
|
+
|
128
|
+
#
|
129
|
+
# Setup Bluepill
|
130
|
+
#
|
131
|
+
sudo "mkdir -p /etc/bluepill"
|
132
|
+
sudo "chown bluepill /etc/bluepill"
|
133
|
+
sudo "chgrp apps /etc/bluepill"
|
134
|
+
sudo "chmod 771 /etc/bluepill"
|
135
|
+
|
136
|
+
puts "Setup EC2 instance #{target_host}...done"
|
137
|
+
end
|
138
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ec2_setup
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Lee Atchison
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-10-23 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: vlad
|
16
|
+
requirement: &70318560138920 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70318560138920
|
25
|
+
description: Setup an EC2 instance running Amazon Linux to be a Rails webserver.
|
26
|
+
email:
|
27
|
+
- lee@leeatchison.com
|
28
|
+
executables: []
|
29
|
+
extensions: []
|
30
|
+
extra_rdoc_files: []
|
31
|
+
files:
|
32
|
+
- .gitignore
|
33
|
+
- Gemfile
|
34
|
+
- README
|
35
|
+
- Rakefile
|
36
|
+
- ec2_setup.gemspec
|
37
|
+
- lib/ec2_setup.rb
|
38
|
+
- lib/ec2_setup/version.rb
|
39
|
+
- lib/tasks/ec2setup.rake
|
40
|
+
homepage: ''
|
41
|
+
licenses: []
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
48
|
+
requirements:
|
49
|
+
- - ! '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubyforge_project: ec2_setup
|
60
|
+
rubygems_version: 1.8.10
|
61
|
+
signing_key:
|
62
|
+
specification_version: 3
|
63
|
+
summary: Setup an EC2 instance running Amazon Linux to be a Rails webserver.
|
64
|
+
test_files: []
|