rubber 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +39 -0
- data/COPYING +339 -0
- data/README +6 -0
- data/TODO +11 -0
- data/VERSION +1 -0
- data/bin/vulcanize +41 -0
- data/generators/vulcanize/USAGE +6 -0
- data/generators/vulcanize/templates/apache/config/rubber/deploy-apache.rb +51 -0
- data/generators/vulcanize/templates/apache/config/rubber/role/apache/deflate.conf +10 -0
- data/generators/vulcanize/templates/apache/config/rubber/role/apache/expires.conf +9 -0
- data/generators/vulcanize/templates/apache/config/rubber/role/apache/headers.conf +6 -0
- data/generators/vulcanize/templates/apache/config/rubber/role/apache/monit-apache.conf +8 -0
- data/generators/vulcanize/templates/apache/config/rubber/role/apache/ports.conf +5 -0
- data/generators/vulcanize/templates/apache/config/rubber/role/apache/setenvif.conf +52 -0
- data/generators/vulcanize/templates/apache/config/rubber/role/web_tools/tools-apache-vhost.conf +62 -0
- data/generators/vulcanize/templates/apache/config/rubber/role/web_tools/tools-apache.auth +7 -0
- data/generators/vulcanize/templates/apache/config/rubber/role/web_tools/tools-index.html +30 -0
- data/generators/vulcanize/templates/apache/config/rubber/rubber-apache.yml +7 -0
- data/generators/vulcanize/templates/apache/templates.yml +1 -0
- data/generators/vulcanize/templates/base/Capfile +14 -0
- data/generators/vulcanize/templates/base/config/deploy.rb +55 -0
- data/generators/vulcanize/templates/base/config/rubber/common/crontab +16 -0
- data/generators/vulcanize/templates/base/config/rubber/common/profile.rc +9 -0
- data/generators/vulcanize/templates/base/config/rubber/deploy-setup.rb +104 -0
- data/generators/vulcanize/templates/base/config/rubber/rubber.yml +241 -0
- data/generators/vulcanize/templates/base/lib/tasks/rubber.rake +15 -0
- data/generators/vulcanize/templates/base/script/cron-rake +18 -0
- data/generators/vulcanize/templates/base/script/cron-runner +18 -0
- data/generators/vulcanize/templates/base/script/cron-sh +67 -0
- data/generators/vulcanize/templates/base/templates.yml +1 -0
- data/generators/vulcanize/templates/complete_mongrel_mysql/config/rubber/role/haproxy/haproxy-mongrel.conf +23 -0
- data/generators/vulcanize/templates/complete_mongrel_mysql/config/rubber/role/nginx/nginx-mongrel.conf +113 -0
- data/generators/vulcanize/templates/complete_mongrel_mysql/config/rubber/rubber-complete.yml +41 -0
- data/generators/vulcanize/templates/complete_mongrel_mysql/templates.yml +6 -0
- data/generators/vulcanize/templates/complete_passenger_mysql/config/rubber/role/haproxy/haproxy-passenger.conf +19 -0
- data/generators/vulcanize/templates/complete_passenger_mysql/config/rubber/rubber-complete.yml +40 -0
- data/generators/vulcanize/templates/complete_passenger_mysql/templates.yml +10 -0
- data/generators/vulcanize/templates/cruise/config/rubber/deploy-cruise.rb +72 -0
- data/generators/vulcanize/templates/cruise/config/rubber/role/cruise/cruise +40 -0
- data/generators/vulcanize/templates/cruise/config/rubber/role/cruise/my.cnf +165 -0
- data/generators/vulcanize/templates/cruise/config/rubber/role/cruise/production.rb +8 -0
- data/generators/vulcanize/templates/cruise/config/rubber/role/cruise/site_config.rb +76 -0
- data/generators/vulcanize/templates/cruise/config/rubber/role/web_tools/cruise-nginx.conf +11 -0
- data/generators/vulcanize/templates/cruise/config/rubber/rubber-cruise.yml +18 -0
- data/generators/vulcanize/templates/cruise/templates.yml +1 -0
- data/generators/vulcanize/templates/haproxy/config/rubber/deploy-haproxy.rb +45 -0
- data/generators/vulcanize/templates/haproxy/config/rubber/role/haproxy/haproxy-base.conf +26 -0
- data/generators/vulcanize/templates/haproxy/config/rubber/role/haproxy/haproxy-default.conf +8 -0
- data/generators/vulcanize/templates/haproxy/config/rubber/role/haproxy/monit-haproxy.conf +9 -0
- data/generators/vulcanize/templates/haproxy/config/rubber/role/haproxy/syslog-haproxy.conf +6 -0
- data/generators/vulcanize/templates/haproxy/config/rubber/role/haproxy/syslogd-default.conf +17 -0
- data/generators/vulcanize/templates/haproxy/config/rubber/role/web_tools/haproxy-nginx.conf +10 -0
- data/generators/vulcanize/templates/haproxy/config/rubber/rubber-haproxy.yml +7 -0
- data/generators/vulcanize/templates/haproxy/templates.yml +1 -0
- data/generators/vulcanize/templates/memcached/config/memcached.yml +28 -0
- data/generators/vulcanize/templates/memcached/config/rubber/common/memcached.yml +14 -0
- data/generators/vulcanize/templates/memcached/config/rubber/role/memcached/memcached.conf +52 -0
- data/generators/vulcanize/templates/memcached/config/rubber/role/memcached/memcached_munin_plugin +249 -0
- data/generators/vulcanize/templates/memcached/config/rubber/rubber-memcached.yml +7 -0
- data/generators/vulcanize/templates/memcached/templates.yml +1 -0
- data/generators/vulcanize/templates/minimal_mysql/templates.yml +7 -0
- data/generators/vulcanize/templates/minimal_nodb/templates.yml +6 -0
- data/generators/vulcanize/templates/mongrel/config/rubber/deploy-mongrel.rb +75 -0
- data/generators/vulcanize/templates/mongrel/config/rubber/role/mongrel/mongrel_cluster.yml +12 -0
- data/generators/vulcanize/templates/mongrel/config/rubber/role/mongrel/monit-mongrel.conf +20 -0
- data/generators/vulcanize/templates/mongrel/config/rubber/rubber-mongrel.yml +9 -0
- data/generators/vulcanize/templates/mongrel/templates.yml +1 -0
- data/generators/vulcanize/templates/monit/config/rubber/common/monit-default.conf +15 -0
- data/generators/vulcanize/templates/monit/config/rubber/common/monit.conf +251 -0
- data/generators/vulcanize/templates/monit/config/rubber/deploy-monit.rb +32 -0
- data/generators/vulcanize/templates/monit/config/rubber/role/web_tools/monit-admin-nginx.conf +10 -0
- data/generators/vulcanize/templates/monit/config/rubber/rubber-monit.yml +6 -0
- data/generators/vulcanize/templates/monit/templates.yml +1 -0
- data/generators/vulcanize/templates/munin/config/rubber/common/monit-munin.conf +8 -0
- data/generators/vulcanize/templates/munin/config/rubber/common/munin-node.conf +48 -0
- data/generators/vulcanize/templates/munin/config/rubber/deploy-munin.rb +46 -0
- data/generators/vulcanize/templates/munin/config/rubber/role/web_tools/munin-nginx.conf +8 -0
- data/generators/vulcanize/templates/munin/config/rubber/role/web_tools/munin-plugins.conf +31 -0
- data/generators/vulcanize/templates/munin/config/rubber/role/web_tools/munin.conf +80 -0
- data/generators/vulcanize/templates/munin/config/rubber/rubber-munin.yml +8 -0
- data/generators/vulcanize/templates/munin/script/munin/example_mysql_query.rb +57 -0
- data/generators/vulcanize/templates/munin/script/munin/example_simple.rb +24 -0
- data/generators/vulcanize/templates/munin/templates.yml +1 -0
- data/generators/vulcanize/templates/mysql/config/rubber/common/database.yml +11 -0
- data/generators/vulcanize/templates/mysql/config/rubber/deploy-mysql.rb +156 -0
- data/generators/vulcanize/templates/mysql/config/rubber/role/db/crontab +14 -0
- data/generators/vulcanize/templates/mysql/config/rubber/role/db/monit-mysql.cnf +10 -0
- data/generators/vulcanize/templates/mysql/config/rubber/role/db/my.cnf +167 -0
- data/generators/vulcanize/templates/mysql/config/rubber/role/mysql_slave/mysql_slave_munin_plugin +51 -0
- data/generators/vulcanize/templates/mysql/config/rubber/rubber-mysql.yml +46 -0
- data/generators/vulcanize/templates/mysql/templates.yml +1 -0
- data/generators/vulcanize/templates/mysql_cluster/config/rubber/common/mysql_cluster_migrations.rb +13 -0
- data/generators/vulcanize/templates/mysql_cluster/config/rubber/deploy-mysql_cluster.rb +173 -0
- data/generators/vulcanize/templates/mysql_cluster/config/rubber/role/mysql_data/my.cnf +15 -0
- data/generators/vulcanize/templates/mysql_cluster/config/rubber/role/mysql_mgm/ndb_mgmd.cnf +39 -0
- data/generators/vulcanize/templates/mysql_cluster/config/rubber/role/mysql_sql/monit-mysql_cluster_sql.cnf +10 -0
- data/generators/vulcanize/templates/mysql_cluster/config/rubber/role/mysql_sql/my.cnf +23 -0
- data/generators/vulcanize/templates/mysql_cluster/config/rubber/rubber-mysql_cluster.yml +32 -0
- data/generators/vulcanize/templates/mysql_cluster/templates.yml +1 -0
- data/generators/vulcanize/templates/mysql_proxy/config/rubber/common/database.yml +16 -0
- data/generators/vulcanize/templates/mysql_proxy/config/rubber/common/monit-mysql_proxy.cnf +10 -0
- data/generators/vulcanize/templates/mysql_proxy/config/rubber/common/mysql-proxy +153 -0
- data/generators/vulcanize/templates/mysql_proxy/config/rubber/common/mysql-proxy.conf +10 -0
- data/generators/vulcanize/templates/mysql_proxy/config/rubber/common/mysql-proxy.lua +5 -0
- data/generators/vulcanize/templates/mysql_proxy/config/rubber/deploy-mysql_proxy.rb +52 -0
- data/generators/vulcanize/templates/mysql_proxy/config/rubber/rubber-mysql_proxy.yml +11 -0
- data/generators/vulcanize/templates/mysql_proxy/templates.yml +1 -0
- data/generators/vulcanize/templates/nginx/config/rubber/deploy-nginx.rb +45 -0
- data/generators/vulcanize/templates/nginx/config/rubber/role/nginx/crontab +9 -0
- data/generators/vulcanize/templates/nginx/config/rubber/role/nginx/monit-nginx.conf +8 -0
- data/generators/vulcanize/templates/nginx/config/rubber/role/nginx/nginx.conf +42 -0
- data/generators/vulcanize/templates/nginx/config/rubber/role/web_tools/nginx-tools.conf +55 -0
- data/generators/vulcanize/templates/nginx/config/rubber/role/web_tools/tools-index.html +30 -0
- data/generators/vulcanize/templates/nginx/config/rubber/role/web_tools/tools-nginx.auth +7 -0
- data/generators/vulcanize/templates/nginx/config/rubber/rubber-nginx.yml +10 -0
- data/generators/vulcanize/templates/nginx/templates.yml +1 -0
- data/generators/vulcanize/templates/passenger/config/rubber/deploy-passenger.rb +37 -0
- data/generators/vulcanize/templates/passenger/config/rubber/role/passenger/munin-passenger-sudoers.conf +6 -0
- data/generators/vulcanize/templates/passenger/config/rubber/role/passenger/munin-passenger.conf +47 -0
- data/generators/vulcanize/templates/passenger/config/rubber/role/passenger/passenger-apache-vhost.conf +46 -0
- data/generators/vulcanize/templates/passenger/config/rubber/role/passenger/passenger.conf +10 -0
- data/generators/vulcanize/templates/passenger/config/rubber/rubber-passenger.yml +12 -0
- data/generators/vulcanize/templates/passenger/templates.yml +1 -0
- data/generators/vulcanize/templates/sphinx/config/rubber/common/sphinx.yml +46 -0
- data/generators/vulcanize/templates/sphinx/config/rubber/deploy-sphinx.rb +112 -0
- data/generators/vulcanize/templates/sphinx/config/rubber/role/sphinx/crontab +11 -0
- data/generators/vulcanize/templates/sphinx/config/rubber/role/sphinx/monit-sphinx.conf +10 -0
- data/generators/vulcanize/templates/sphinx/config/rubber/rubber-sphinx.yml +6 -0
- data/generators/vulcanize/templates/sphinx/templates.yml +1 -0
- data/generators/vulcanize/vulcanize_generator.rb +67 -0
- data/lib/capistrano/hostcmd.rb +12 -0
- data/lib/rubber.rb +38 -0
- data/lib/rubber/capistrano.rb +1 -0
- data/lib/rubber/cloud.rb +13 -0
- data/lib/rubber/cloud/aws.rb +305 -0
- data/lib/rubber/cloud/base.rb +16 -0
- data/lib/rubber/configuration.rb +47 -0
- data/lib/rubber/dns.rb +13 -0
- data/lib/rubber/dns/base.rb +69 -0
- data/lib/rubber/dns/dyndns.rb +63 -0
- data/lib/rubber/dns/nettica.rb +73 -0
- data/lib/rubber/dns/zerigo.rb +131 -0
- data/lib/rubber/environment.rb +161 -0
- data/lib/rubber/generator.rb +197 -0
- data/lib/rubber/instance.rb +165 -0
- data/lib/rubber/recipes/rubber.rb +89 -0
- data/lib/rubber/recipes/rubber/bundles.rb +28 -0
- data/lib/rubber/recipes/rubber/deploy.rb +90 -0
- data/lib/rubber/recipes/rubber/instances.rb +348 -0
- data/lib/rubber/recipes/rubber/load_balancers.rb +44 -0
- data/lib/rubber/recipes/rubber/security_groups.rb +189 -0
- data/lib/rubber/recipes/rubber/setup.rb +357 -0
- data/lib/rubber/recipes/rubber/static_ips.rb +107 -0
- data/lib/rubber/recipes/rubber/utils.rb +203 -0
- data/lib/rubber/recipes/rubber/volumes.rb +264 -0
- data/lib/rubber/tasks/rubber.rb +221 -0
- data/lib/rubber/util.rb +37 -0
- data/test/environment_test.rb +118 -0
- data/test/generator_test.rb +323 -0
- data/test/instance_test.rb +93 -0
- data/test/test_helper.rb +4 -0
- data/test/util_test.rb +16 -0
- metadata +274 -0
@@ -0,0 +1,44 @@
|
|
1
|
+
namespace :rubber do
|
2
|
+
|
3
|
+
#desc <<-DESC
|
4
|
+
# Sets up the network load balancers
|
5
|
+
#DESC
|
6
|
+
#required_task :setup_load_balancers do
|
7
|
+
# setup_load_balancers()
|
8
|
+
#end
|
9
|
+
#
|
10
|
+
#desc <<-DESC
|
11
|
+
# Describes the network load balancers
|
12
|
+
#DESC
|
13
|
+
#required_task :describe_load_balancers do
|
14
|
+
# lbs = cloud.describe_load_balancers()
|
15
|
+
# pp lbs
|
16
|
+
#end
|
17
|
+
|
18
|
+
def setup_load_balancers
|
19
|
+
# OPTIONAL: Automatically provision and assign instances to a Cloud provided
|
20
|
+
# load balancer.
|
21
|
+
#load_balancers:
|
22
|
+
# my_lb_name:
|
23
|
+
# listeners:
|
24
|
+
# - protocol: http
|
25
|
+
# port: 80
|
26
|
+
# instance_port: 8080
|
27
|
+
# - protocol: tcp
|
28
|
+
# port: 443
|
29
|
+
# instance_port: 8080
|
30
|
+
# target_roles: [app]
|
31
|
+
#
|
32
|
+
#isolate_load_balancers: true
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
# get remote lbs
|
37
|
+
# for each local not in remote, add it
|
38
|
+
# get all zones for all instances for roles, and make sure in lb
|
39
|
+
# warn if lb not balanced (count of instances per zone is equal)
|
40
|
+
# for each local that is in remote, sync listeners and zones
|
41
|
+
# for each remote not in local, remove it
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,189 @@
|
|
1
|
+
namespace :rubber do
|
2
|
+
|
3
|
+
desc <<-DESC
|
4
|
+
Sets up the network security groups
|
5
|
+
All defined groups will be created, and any not defined will be removed.
|
6
|
+
Likewise, rules within a group will get created, and those not will be removed
|
7
|
+
DESC
|
8
|
+
required_task :setup_security_groups do
|
9
|
+
setup_security_groups()
|
10
|
+
end
|
11
|
+
|
12
|
+
desc <<-DESC
|
13
|
+
Describes the network security groups
|
14
|
+
DESC
|
15
|
+
required_task :describe_security_groups do
|
16
|
+
groups = cloud.describe_security_groups()
|
17
|
+
groups.each do |group|
|
18
|
+
puts "#{group[:name]}, #{group[:description]}"
|
19
|
+
group[:permissions].each do |perm|
|
20
|
+
puts " protocol: #{perm[:protocol]}"
|
21
|
+
puts " from_port: #{perm[:from_port]}"
|
22
|
+
puts " to_port: #{perm[:to_port]}"
|
23
|
+
puts " source_groups: #{perm[:source_groups].collect {|g| g[:name]}.join(", ") }" if perm[:source_groups]
|
24
|
+
puts " source_ips: #{perm[:source_ips].join(", ") }" if perm[:source_ips]
|
25
|
+
puts "\n"
|
26
|
+
end if group[:permissions]
|
27
|
+
puts "\n"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
def get_assigned_security_groups(host=nil, roles=[])
|
33
|
+
env = rubber_cfg.environment.bind(roles, host)
|
34
|
+
security_groups = env.assigned_security_groups
|
35
|
+
if env.auto_security_groups
|
36
|
+
security_groups << host
|
37
|
+
security_groups += roles
|
38
|
+
end
|
39
|
+
security_groups = security_groups.uniq.compact
|
40
|
+
security_groups = security_groups.collect {|x| isolate_group_name(x) } if env.isolate_security_groups
|
41
|
+
return security_groups
|
42
|
+
end
|
43
|
+
|
44
|
+
def setup_security_groups(host=nil, roles=[])
|
45
|
+
env = rubber_cfg.environment.bind(roles, host)
|
46
|
+
security_group_defns = env.security_groups
|
47
|
+
if env.auto_security_groups
|
48
|
+
sghosts = (rubber_instances.collect{|ic| ic.name } + [host]).uniq.compact
|
49
|
+
sgroles = (rubber_instances.all_roles + roles).uniq.compact
|
50
|
+
security_group_defns = inject_auto_security_groups(security_group_defns, sghosts, sgroles)
|
51
|
+
sync_security_groups(security_group_defns)
|
52
|
+
else
|
53
|
+
sync_security_groups(security_group_defns)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def inject_auto_security_groups(groups, hosts, roles)
|
58
|
+
hosts.each do |name|
|
59
|
+
group_name = name
|
60
|
+
groups[group_name] ||= {'description' => "Rubber automatic security group for host: #{name}", 'rules' => []}
|
61
|
+
end
|
62
|
+
roles.each do |name|
|
63
|
+
group_name = name
|
64
|
+
groups[group_name] ||= {'description' => "Rubber automatic security group for role: #{name}", 'rules' => []}
|
65
|
+
end
|
66
|
+
return groups
|
67
|
+
end
|
68
|
+
|
69
|
+
def isolate_prefix
|
70
|
+
return "#{rubber_env.app_name}_#{RUBBER_ENV}_"
|
71
|
+
end
|
72
|
+
|
73
|
+
def isolate_group_name(group_name)
|
74
|
+
new_name = "#{isolate_prefix}#{group_name}"
|
75
|
+
return new_name
|
76
|
+
end
|
77
|
+
|
78
|
+
def isolate_groups(groups)
|
79
|
+
renamed = {}
|
80
|
+
groups.each do |name, group|
|
81
|
+
new_name = name =~ /^#{isolate_prefix}/ ? name : isolate_group_name(name)
|
82
|
+
new_group = Marshal.load(Marshal.dump(group))
|
83
|
+
new_group['rules'].each do |rule|
|
84
|
+
old_ref_name = rule['source_group_name']
|
85
|
+
if old_ref_name && old_ref_name !~ /^#{isolate_prefix}/
|
86
|
+
rule['source_group_name'] = isolate_group_name(old_ref_name)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
renamed[new_name] = new_group
|
90
|
+
end
|
91
|
+
return renamed
|
92
|
+
end
|
93
|
+
|
94
|
+
def sync_security_groups(groups)
|
95
|
+
return unless groups
|
96
|
+
|
97
|
+
groups = Rubber::Util::stringify(groups)
|
98
|
+
groups = isolate_groups(groups) if rubber_env.isolate_security_groups
|
99
|
+
group_keys = groups.keys.clone()
|
100
|
+
|
101
|
+
# For each group that does already exist in cloud
|
102
|
+
cloud_groups = cloud.describe_security_groups()
|
103
|
+
cloud_groups.each do |cloud_group|
|
104
|
+
group_name = cloud_group[:name]
|
105
|
+
|
106
|
+
# skip those groups that don't belong to this project/env
|
107
|
+
next if rubber_env.isolate_security_groups && group_name !~ /^#{isolate_prefix}/
|
108
|
+
|
109
|
+
if group_keys.delete(group_name)
|
110
|
+
# sync rules
|
111
|
+
logger.debug "Security Group already in cloud, syncing rules: #{group_name}"
|
112
|
+
group = groups[group_name]
|
113
|
+
rules = group['rules'].clone
|
114
|
+
rule_maps = []
|
115
|
+
|
116
|
+
# first collect the rule maps from the request (group/user pairs are duplicated for tcp/udp/icmp,
|
117
|
+
# so we need to do this up frnot and remove duplicates before checking against the local rubber rules)
|
118
|
+
cloud_group[:permissions].each do |rule|
|
119
|
+
if rule[:source_groups]
|
120
|
+
rule.source_groups.each do |source_group|
|
121
|
+
rule_map = {:source_group_name => source_group[:name], :source_group_account => source_group[:account]}
|
122
|
+
rule_map = Rubber::Util::stringify(rule_map)
|
123
|
+
rule_maps << rule_map unless rule_maps.include?(rule_map)
|
124
|
+
end
|
125
|
+
else
|
126
|
+
rule_map = Rubber::Util::stringify(rule)
|
127
|
+
rule_maps << rule_map unless rule_maps.include?(rule_map)
|
128
|
+
end
|
129
|
+
end if cloud_group[:permissions]
|
130
|
+
# For each rule, if it exists, do nothing, otherwise remove it as its no longer defined locally
|
131
|
+
rule_maps.each do |rule_map|
|
132
|
+
if rules.delete(rule_map)
|
133
|
+
# rules match, don't need to do anything
|
134
|
+
# logger.debug "Rule in sync: #{rule_map.inspect}"
|
135
|
+
else
|
136
|
+
# rules don't match, remove them from cloud and re-add below
|
137
|
+
answer = Capistrano::CLI.ui.ask("Rule '#{rule_map.inspect}' exists in cloud, but not locally, remove from cloud? [y/N]?: ")
|
138
|
+
rule_map = Rubber::Util::symbolize_keys(rule_map)
|
139
|
+
if rule_map[:source_group_name]
|
140
|
+
cloud.remove_security_group_rule(group_name, nil, nil, nil, {:name => rule_map[:source_group_name], :account => rule_map[:source_group_account]})
|
141
|
+
else
|
142
|
+
rule_map[:source_ips].each do |source_ip|
|
143
|
+
cloud.remove_security_group_rule(group_name, rule_map[:protocol], rule_map[:from_port], rule_map[:to_port], source_ip)
|
144
|
+
end if rule_map[:source_ips] && answer =~ /^y/
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
rules.each do |rule_map|
|
150
|
+
# create non-existing rules
|
151
|
+
logger.debug "Missing rule, creating: #{rule_map.inspect}"
|
152
|
+
rule_map = Rubber::Util::symbolize_keys(rule_map)
|
153
|
+
if rule_map[:source_group_name]
|
154
|
+
cloud.add_security_group_rule(group_name, nil, nil, nil, {:name => rule_map[:source_group_name], :account => rule_map[:source_group_account]})
|
155
|
+
else
|
156
|
+
rule_map[:source_ips].each do |source_ip|
|
157
|
+
cloud.add_security_group_rule(group_name, rule_map[:protocol], rule_map[:from_port], rule_map[:to_port], source_ip)
|
158
|
+
end if rule_map[:source_ips]
|
159
|
+
end
|
160
|
+
end
|
161
|
+
else
|
162
|
+
# delete group
|
163
|
+
answer = Capistrano::CLI.ui.ask("Security group '#{group_name}' exists in cloud but not locally, remove from cloud? [y/N]: ")
|
164
|
+
cloud.destroy_security_group(group_name) if answer =~ /^y/
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
# For each group that didnt already exist in cloud
|
169
|
+
group_keys.each do |group_name|
|
170
|
+
group = groups[group_name]
|
171
|
+
logger.debug "Creating new security group: #{group_name}"
|
172
|
+
# create each group
|
173
|
+
cloud.create_security_group(group_name, group['description'])
|
174
|
+
# create rules for group
|
175
|
+
group['rules'].each do |rule_map|
|
176
|
+
logger.debug "Creating new rule: #{rule_map.inspect}"
|
177
|
+
rule_map = Rubber::Util::symbolize_keys(rule_map)
|
178
|
+
if rule_map[:source_group_name]
|
179
|
+
cloud.add_security_group_rule(group_name, nil, nil, nil, {:name => rule_map[:source_group_name], :account => rule_map[:source_group_account]})
|
180
|
+
else
|
181
|
+
rule_map[:source_ips].each do |source_ip|
|
182
|
+
cloud.add_security_group_rule(group_name, rule_map[:protocol], rule_map[:from_port], rule_map[:to_port], source_ip)
|
183
|
+
end if rule_map[:source_ips]
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
end
|
@@ -0,0 +1,357 @@
|
|
1
|
+
namespace :rubber do
|
2
|
+
|
3
|
+
desc <<-DESC
|
4
|
+
Bootstraps instances by setting timezone, installing packages and gems
|
5
|
+
DESC
|
6
|
+
task :bootstrap do
|
7
|
+
set_timezone
|
8
|
+
link_bash
|
9
|
+
upgrade_packages
|
10
|
+
install_packages
|
11
|
+
setup_volumes
|
12
|
+
setup_gem_sources
|
13
|
+
install_gems
|
14
|
+
deploy.setup
|
15
|
+
end
|
16
|
+
|
17
|
+
desc <<-DESC
|
18
|
+
Sets up aliases for instance hostnames based on contents of instance.yml.
|
19
|
+
Generates /etc/hosts for local/remote machines and sets hostname on
|
20
|
+
remote instances, and sets values in dynamic dns entries
|
21
|
+
DESC
|
22
|
+
required_task :setup_aliases do
|
23
|
+
setup_local_aliases
|
24
|
+
setup_remote_aliases
|
25
|
+
setup_dns_aliases
|
26
|
+
end
|
27
|
+
|
28
|
+
desc <<-DESC
|
29
|
+
Sets up local aliases for instance hostnames based on contents of instance.yml.
|
30
|
+
Generates/etc/hosts for local machine
|
31
|
+
DESC
|
32
|
+
required_task :setup_local_aliases do
|
33
|
+
hosts_file = '/etc/hosts'
|
34
|
+
|
35
|
+
# Generate /etc/hosts contents for the local machine from instance config
|
36
|
+
delim = "## rubber config #{rubber_env.domain} #{RUBBER_ENV}"
|
37
|
+
local_hosts = delim + "\n"
|
38
|
+
rubber_instances.each do |ic|
|
39
|
+
# don't add unqualified hostname in local hosts file since user may be
|
40
|
+
# managing multiple domains with same aliases
|
41
|
+
hosts_data = [ic.full_name, ic.external_host, ic.internal_host].join(' ')
|
42
|
+
local_hosts << ic.external_ip << ' ' << hosts_data << "\n"
|
43
|
+
end
|
44
|
+
local_hosts << delim << "\n"
|
45
|
+
|
46
|
+
# Write out the hosts file for this machine, use sudo
|
47
|
+
filtered = File.read(hosts_file).gsub(/^#{delim}.*^#{delim}\n?/m, '')
|
48
|
+
logger.info "Writing out aliases into local machines #{hosts_file}, sudo access needed"
|
49
|
+
Rubber::Util::sudo_open(hosts_file, 'w') do |f|
|
50
|
+
f.write(filtered)
|
51
|
+
f.write(local_hosts)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
desc <<-DESC
|
56
|
+
Sets up aliases in dynamic dns provider for instance hostnames based on contents of instance.yml.
|
57
|
+
DESC
|
58
|
+
required_task :setup_dns_aliases do
|
59
|
+
rubber_instances.each do |ic|
|
60
|
+
update_dyndns(ic)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
desc <<-DESC
|
65
|
+
Sets up aliases for instance hostnames based on contents of instance.yml.
|
66
|
+
Generates /etc/hosts for remote machines and sets hostname on remote instances
|
67
|
+
DESC
|
68
|
+
task :setup_remote_aliases do
|
69
|
+
hosts_file = '/etc/hosts'
|
70
|
+
|
71
|
+
# Generate /etc/hosts contents for the remote instance from instance config
|
72
|
+
delim = "## rubber config"
|
73
|
+
delim = "#{delim} #{RUBBER_ENV}"
|
74
|
+
remote_hosts = delim + "\n"
|
75
|
+
rubber_instances.each do |ic|
|
76
|
+
hosts_data = [ic.name, ic.full_name, ic.external_host, ic.internal_host].join(' ')
|
77
|
+
remote_hosts << ic.internal_ip << ' ' << hosts_data << "\n"
|
78
|
+
end
|
79
|
+
remote_hosts << delim << "\n"
|
80
|
+
if rubber_instances.size > 0
|
81
|
+
# write out the hosts file for the remote instances
|
82
|
+
# NOTE that we use "capture" to get the existing hosts
|
83
|
+
# file, which only grabs the hosts file from the first host
|
84
|
+
filtered = (capture "cat #{hosts_file}").gsub(/^#{delim}.*^#{delim}\n?/m, '')
|
85
|
+
filtered = filtered + remote_hosts
|
86
|
+
# Put the generated hosts back on remote instance
|
87
|
+
put filtered, hosts_file
|
88
|
+
|
89
|
+
# Setup hostname on instance so shell, etcs have nice display
|
90
|
+
sudo "echo $CAPISTRANO:HOST$ > /etc/hostname && hostname $CAPISTRANO:HOST$"
|
91
|
+
end
|
92
|
+
|
93
|
+
# TODO
|
94
|
+
# /etc/resolv.conf to add search domain
|
95
|
+
# ~/.ssh/options to setup user/host/key aliases
|
96
|
+
end
|
97
|
+
|
98
|
+
desc <<-DESC
|
99
|
+
Update to the newest versions of all packages/gems.
|
100
|
+
DESC
|
101
|
+
task :update do
|
102
|
+
upgrade_packages
|
103
|
+
update_gems
|
104
|
+
end
|
105
|
+
|
106
|
+
desc <<-DESC
|
107
|
+
Upgrade to the newest versions of all Ubuntu packages.
|
108
|
+
DESC
|
109
|
+
task :upgrade_packages do
|
110
|
+
package_helper(true)
|
111
|
+
end
|
112
|
+
|
113
|
+
desc <<-DESC
|
114
|
+
Upgrade to the newest versions of all rubygems.
|
115
|
+
DESC
|
116
|
+
task :update_gems do
|
117
|
+
gem_helper(true)
|
118
|
+
end
|
119
|
+
|
120
|
+
desc <<-DESC
|
121
|
+
Install extra packages and gems.
|
122
|
+
DESC
|
123
|
+
task :install do
|
124
|
+
install_packages
|
125
|
+
install_gems
|
126
|
+
end
|
127
|
+
|
128
|
+
desc <<-DESC
|
129
|
+
Install Ubuntu packages. Set 'packages' in rubber.yml to \
|
130
|
+
be an array of strings.
|
131
|
+
DESC
|
132
|
+
task :install_packages do
|
133
|
+
package_helper(false)
|
134
|
+
end
|
135
|
+
|
136
|
+
desc <<-DESC
|
137
|
+
Install ruby gems. Set 'gems' in rubber.yml to \
|
138
|
+
be an array of strings.
|
139
|
+
DESC
|
140
|
+
task :install_gems do
|
141
|
+
gem_helper(false)
|
142
|
+
end
|
143
|
+
|
144
|
+
desc <<-DESC
|
145
|
+
Install ruby gems defined in the rails environment.rb
|
146
|
+
DESC
|
147
|
+
after "deploy:symlink", "rubber:install_rails_gems" if Rubber::Util.is_rails?
|
148
|
+
task :install_rails_gems do
|
149
|
+
sudo "sh -c 'cd #{current_path} && RAILS_ENV=#{RUBBER_ENV} rake gems:install'"
|
150
|
+
end
|
151
|
+
|
152
|
+
desc <<-DESC
|
153
|
+
Setup ruby gems sources. Set 'gemsources' in rubber.yml to \
|
154
|
+
be an array of URI strings.
|
155
|
+
DESC
|
156
|
+
task :setup_gem_sources do
|
157
|
+
if rubber_env.gemsources
|
158
|
+
script = prepare_script 'gem_sources_helper', <<-'ENDSCRIPT'
|
159
|
+
ruby - $@ <<-'EOF'
|
160
|
+
|
161
|
+
sources = ARGV
|
162
|
+
|
163
|
+
installed = []
|
164
|
+
`gem sources -l`.grep(/^[^*]/) do |line|
|
165
|
+
line = line.strip
|
166
|
+
installed << line if line.size > 0
|
167
|
+
end
|
168
|
+
|
169
|
+
to_install = sources - installed
|
170
|
+
to_remove = installed - sources
|
171
|
+
|
172
|
+
if to_install.size > 0
|
173
|
+
to_install.each do |source|
|
174
|
+
system "gem sources -a #{source}"
|
175
|
+
fail "Unable to add gem sources" if $?.exitstatus > 0
|
176
|
+
end
|
177
|
+
end
|
178
|
+
if to_remove.size > 0
|
179
|
+
to_remove.each do |source|
|
180
|
+
system "gem sources -r #{source}"
|
181
|
+
fail "Unable to remove gem sources" if $?.exitstatus > 0
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
'EOF'
|
186
|
+
ENDSCRIPT
|
187
|
+
|
188
|
+
sudo "sh #{script} #{rubber_env.gemsources.join(' ')}"
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
desc <<-DESC
|
193
|
+
The ubuntu has /bin/sh linking to dash instead of bash, fix this
|
194
|
+
You can override this task if you don't want this to happen
|
195
|
+
DESC
|
196
|
+
task :link_bash do
|
197
|
+
sudo("ln -sf /bin/bash /bin/sh")
|
198
|
+
end
|
199
|
+
|
200
|
+
desc <<-DESC
|
201
|
+
Set the timezone using the value of the variable named timezone. \
|
202
|
+
Valid options for timezone can be determined by the contents of \
|
203
|
+
/usr/share/zoneinfo, which can be seen here: \
|
204
|
+
http://packages.ubuntu.com/cgi-bin/search_contents.pl?searchmode=filelist&word=tzdata&version=gutsy&arch=all&page=1&number=all \
|
205
|
+
Remove 'usr/share/zoneinfo/' from the filename, and use the last \
|
206
|
+
directory and file as the value. For example 'Africa/Abidjan' or \
|
207
|
+
'posix/GMT' or 'Canada/Eastern'.
|
208
|
+
DESC
|
209
|
+
task :set_timezone do
|
210
|
+
opts = get_host_options('timezone')
|
211
|
+
sudo "bash -c 'echo $CAPISTRANO:VAR$ > /etc/timezone'", opts
|
212
|
+
sudo "cp /usr/share/zoneinfo/$CAPISTRANO:VAR$ /etc/localtime", opts
|
213
|
+
# restart syslog so that times match timezone
|
214
|
+
sudo "/etc/init.d/sysklogd restart"
|
215
|
+
end
|
216
|
+
|
217
|
+
def update_dyndns(instance_item)
|
218
|
+
env = rubber_cfg.environment.bind(instance_item.role_names, instance_item.name)
|
219
|
+
if env.dns_provider
|
220
|
+
provider = Rubber::Dns::get_provider(env.dns_provider, env)
|
221
|
+
provider.update(instance_item.name, instance_item.external_ip)
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
def destroy_dyndns(instance_item)
|
226
|
+
env = rubber_cfg.environment.bind(instance_item.role_names, instance_item.name)
|
227
|
+
if env.dns_provider
|
228
|
+
provider = Rubber::Dns::get_provider(env.dns_provider, env)
|
229
|
+
provider.destroy(instance_item.name)
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
def package_helper(upgrade=false)
|
234
|
+
opts = get_host_options('packages') do |pkg_list|
|
235
|
+
expanded_pkg_list = []
|
236
|
+
pkg_list.each do |pkg_spec|
|
237
|
+
if pkg_spec.is_a?(Array)
|
238
|
+
expanded_pkg_list << "#{pkg_spec[0]}=#{pkg_spec[1]}"
|
239
|
+
else
|
240
|
+
expanded_pkg_list << pkg_spec
|
241
|
+
end
|
242
|
+
end
|
243
|
+
expanded_pkg_list.join(' ')
|
244
|
+
end
|
245
|
+
|
246
|
+
sudo "apt-get -q update"
|
247
|
+
if upgrade
|
248
|
+
sudo "/bin/sh -c 'export DEBIAN_FRONTEND=noninteractive; apt-get -q -y --force-yes dist-upgrade'"
|
249
|
+
else
|
250
|
+
sudo "/bin/sh -c 'export DEBIAN_FRONTEND=noninteractive; apt-get -q -y --force-yes install $CAPISTRANO:VAR$'", opts
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
def custom_package(url_base, name, ver, install_test)
|
255
|
+
rubber.run_script "install_#{name}", <<-ENDSCRIPT
|
256
|
+
if [[ #{install_test} ]]; then
|
257
|
+
arch=`uname -m`
|
258
|
+
if [ "$arch" = "x86_64" ]; then
|
259
|
+
src="#{url_base}/#{name}_#{ver}_amd64.deb"
|
260
|
+
else
|
261
|
+
src="#{url_base}/#{name}_#{ver}_i386.deb"
|
262
|
+
fi
|
263
|
+
src_file="${src##*/}"
|
264
|
+
wget -qP /tmp ${src}
|
265
|
+
dpkg -i /tmp/${src_file}
|
266
|
+
fi
|
267
|
+
ENDSCRIPT
|
268
|
+
end
|
269
|
+
|
270
|
+
def handle_gem_prompt(ch, data, str)
|
271
|
+
ch[:data] ||= ""
|
272
|
+
ch[:data] << data
|
273
|
+
if data =~ />\s*$/
|
274
|
+
logger.info data
|
275
|
+
logger.info "The gem command is asking for a number:"
|
276
|
+
choice = STDIN.gets
|
277
|
+
ch.send_data(choice)
|
278
|
+
else
|
279
|
+
logger.info data
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
# Helper for installing gems,allows one to respond to prompts
|
284
|
+
def gem_helper(update=false)
|
285
|
+
cmd = update ? "update" : "install"
|
286
|
+
|
287
|
+
|
288
|
+
opts = get_host_options('gems') do |gem_list|
|
289
|
+
expanded_gem_list = []
|
290
|
+
gem_list.each do |gem_spec|
|
291
|
+
if gem_spec.is_a?(Array)
|
292
|
+
expanded_gem_list << "#{gem_spec[0]}:#{gem_spec[1]}"
|
293
|
+
else
|
294
|
+
expanded_gem_list << gem_spec
|
295
|
+
end
|
296
|
+
end
|
297
|
+
expanded_gem_list.join(' ')
|
298
|
+
end
|
299
|
+
|
300
|
+
if opts.size > 0
|
301
|
+
# Rubygems always installs even if the gem is already installed
|
302
|
+
# When providing versions, rubygems fails unless versions are provided for all gems
|
303
|
+
# This helper script works around these issues by installing gems only if they
|
304
|
+
# aren't already installed, and separates versioned/unversioned into two separate
|
305
|
+
# calls to rubygems
|
306
|
+
script = prepare_script 'gem_helper', <<-'ENDSCRIPT'
|
307
|
+
ruby - $@ <<-'EOF'
|
308
|
+
|
309
|
+
gem_cmd = ARGV[0]
|
310
|
+
gems = ARGV[1..-1]
|
311
|
+
cmd = "gem #{gem_cmd} --no-rdoc --no-ri"
|
312
|
+
|
313
|
+
to_install = {}
|
314
|
+
to_install_ver = {}
|
315
|
+
# gem list passed in, possibly with versions, as "gem1 gem2:1.2 gem3"
|
316
|
+
gems.each do |gem_spec|
|
317
|
+
parts = gem_spec.split(':')
|
318
|
+
if parts[1]
|
319
|
+
to_install_ver[parts[0]] = parts[1]
|
320
|
+
else
|
321
|
+
to_install[parts[0]] = true
|
322
|
+
end
|
323
|
+
end
|
324
|
+
|
325
|
+
installed = {}
|
326
|
+
`gem list --local`.each do |line|
|
327
|
+
parts = line.scan(/(.*) \((.*)\)/).first
|
328
|
+
next unless parts && parts.size == 2
|
329
|
+
installed[parts[0]] = parts[1].split(",")
|
330
|
+
end
|
331
|
+
|
332
|
+
to_install.delete_if {|g, v| installed.has_key?(g) } if gem_cmd == 'install'
|
333
|
+
to_install_ver.delete_if {|g, v| installed.has_key?(g) && installed[g].include?(v) }
|
334
|
+
|
335
|
+
# rubygems can only do asingle versioned gem at a time so we need
|
336
|
+
# to do the two groups separately
|
337
|
+
# install versioned ones first so unversioned don't pull in a newer version
|
338
|
+
to_install_ver.each do |g, v|
|
339
|
+
system "#{cmd} #{g} -v #{v}"
|
340
|
+
fail "Unable to install versioned gem #{g}:#{v}" if $?.exitstatus > 0
|
341
|
+
end
|
342
|
+
if to_install.size > 0
|
343
|
+
gem_list = to_install.keys.join(' ')
|
344
|
+
system "#{cmd} #{gem_list}"
|
345
|
+
fail "Unable to install gems" if $?.exitstatus > 0
|
346
|
+
end
|
347
|
+
|
348
|
+
'EOF'
|
349
|
+
ENDSCRIPT
|
350
|
+
|
351
|
+
sudo "sh #{script} #{cmd} $CAPISTRANO:VAR$", opts do |ch, str, data|
|
352
|
+
handle_gem_prompt(ch, data, str)
|
353
|
+
end
|
354
|
+
end
|
355
|
+
end
|
356
|
+
|
357
|
+
end
|