andyh-deprec 1.99.26
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +187 -0
- data/COPYING +19 -0
- data/LICENSE +339 -0
- data/README +138 -0
- data/THANKS +5 -0
- data/bin/depify +133 -0
- data/docs/ANNOUNCE.deprec2 +47 -0
- data/docs/README.install +88 -0
- data/docs/README.nagios +22 -0
- data/docs/README.rails +20 -0
- data/docs/README.svn +31 -0
- data/docs/ROADMAP.txt +74 -0
- data/docs/deprec-1.x/deprec-1.x.quickstart +50 -0
- data/docs/deprec-1.x/notes.txt +12 -0
- data/docs/deprec_banner.gif +0 -0
- data/docs/windows_linux.txt +350 -0
- data/docs/xen/plan.txt +5 -0
- data/docs/xen/traffic_monitoring_with_vnstat.txt +95 -0
- data/docs/xen/xen-tools-notes.txt +31 -0
- data/docs/xen/xen_on_hardy.txt +39 -0
- data/lib/deprec/capistrano_extensions.rb +391 -0
- data/lib/deprec/recipes/aoe.rb +80 -0
- data/lib/deprec/recipes/apache.rb +179 -0
- data/lib/deprec/recipes/ar_sendmail.rb +65 -0
- data/lib/deprec/recipes/canonical.rb +57 -0
- data/lib/deprec/recipes/deprec.rb +188 -0
- data/lib/deprec/recipes/deprecated.rb +71 -0
- data/lib/deprec/recipes/example.rb +115 -0
- data/lib/deprec/recipes/git.rb +97 -0
- data/lib/deprec/recipes/gitosis.rb +48 -0
- data/lib/deprec/recipes/heartbeat.rb +138 -0
- data/lib/deprec/recipes/logrotate.rb +54 -0
- data/lib/deprec/recipes/lvm.rb +20 -0
- data/lib/deprec/recipes/memcache.rb +49 -0
- data/lib/deprec/recipes/mongrel.rb +219 -0
- data/lib/deprec/recipes/monit.rb +135 -0
- data/lib/deprec/recipes/mysql.rb +115 -0
- data/lib/deprec/recipes/nagios.rb +305 -0
- data/lib/deprec/recipes/network.rb +81 -0
- data/lib/deprec/recipes/nginx.rb +144 -0
- data/lib/deprec/recipes/ntp.rb +103 -0
- data/lib/deprec/recipes/php.rb +99 -0
- data/lib/deprec/recipes/postfix.rb +105 -0
- data/lib/deprec/recipes/rails.rb +288 -0
- data/lib/deprec/recipes/ruby.rb +66 -0
- data/lib/deprec/recipes/sphinx.rb +83 -0
- data/lib/deprec/recipes/ssh.rb +93 -0
- data/lib/deprec/recipes/svn.rb +171 -0
- data/lib/deprec/recipes/trac.rb +277 -0
- data/lib/deprec/recipes/ubuntu.rb +20 -0
- data/lib/deprec/recipes/users.rb +90 -0
- data/lib/deprec/recipes/utils.rb +39 -0
- data/lib/deprec/recipes/vnstat.rb +85 -0
- data/lib/deprec/recipes/xen.rb +262 -0
- data/lib/deprec/recipes.rb +37 -0
- data/lib/deprec/templates/aoe/aoe-init +55 -0
- data/lib/deprec/templates/aoe/fence_aoemask +351 -0
- data/lib/deprec/templates/apache/httpd-vhost-app.conf.erb +144 -0
- data/lib/deprec/templates/apache/httpd.conf +465 -0
- data/lib/deprec/templates/apache/index.html.erb +37 -0
- data/lib/deprec/templates/apache/master.css +72 -0
- data/lib/deprec/templates/ar_sendmail/logrotate.conf.erb +9 -0
- data/lib/deprec/templates/ar_sendmail/monit.conf.erb +5 -0
- data/lib/deprec/templates/deprec/caprc.erb +14 -0
- data/lib/deprec/templates/heartbeat/authkeys.erb +2 -0
- data/lib/deprec/templates/heartbeat/ha.cf.erb +15 -0
- data/lib/deprec/templates/heartbeat/haresources.erb +1 -0
- data/lib/deprec/templates/logrotate/logrotate.conf.erb +32 -0
- data/lib/deprec/templates/mongrel/logrotate.conf.erb +11 -0
- data/lib/deprec/templates/mongrel/mongrel_cluster-init-script +54 -0
- data/lib/deprec/templates/mongrel/mongrel_cluster.logrotate.d +14 -0
- data/lib/deprec/templates/mongrel/mongrel_cluster.yml.erb +10 -0
- data/lib/deprec/templates/mongrel/monit.conf.erb +17 -0
- data/lib/deprec/templates/monit/monit-init-script +104 -0
- data/lib/deprec/templates/monit/monitrc.erb +227 -0
- data/lib/deprec/templates/monit/nothing +0 -0
- data/lib/deprec/templates/mysql/create_databases.sql +20 -0
- data/lib/deprec/templates/mysql/database.yml.prod +6 -0
- data/lib/deprec/templates/mysql/database.yml.stage +6 -0
- data/lib/deprec/templates/mysql/my.cnf.erb +140 -0
- data/lib/deprec/templates/mysql/sphinx.conf.prod +542 -0
- data/lib/deprec/templates/mysql/sphinx.conf.stage +542 -0
- data/lib/deprec/templates/nagios/cgi.cfg.erb +321 -0
- data/lib/deprec/templates/nagios/check_linux_free_memory.pl +118 -0
- data/lib/deprec/templates/nagios/check_mongrel_cluster.rb +82 -0
- data/lib/deprec/templates/nagios/commands.cfg.erb +240 -0
- data/lib/deprec/templates/nagios/contacts.cfg.erb +57 -0
- data/lib/deprec/templates/nagios/hosts.cfg.erb +143 -0
- data/lib/deprec/templates/nagios/htpasswd.users +1 -0
- data/lib/deprec/templates/nagios/localhost.cfg.erb +157 -0
- data/lib/deprec/templates/nagios/nagios.cfg.erb +1274 -0
- data/lib/deprec/templates/nagios/nagios_apache_vhost.conf.erb +45 -0
- data/lib/deprec/templates/nagios/nrpe.cfg.erb +210 -0
- data/lib/deprec/templates/nagios/nrpe.xinetd.erb +16 -0
- data/lib/deprec/templates/nagios/resource.cfg.erb +34 -0
- data/lib/deprec/templates/nagios/services.cfg.erb +79 -0
- data/lib/deprec/templates/nagios/templates.cfg.erb +9 -0
- data/lib/deprec/templates/nagios/timeperiods.cfg.erb +94 -0
- data/lib/deprec/templates/network/hostname.erb +1 -0
- data/lib/deprec/templates/network/hosts.erb +2 -0
- data/lib/deprec/templates/network/interfaces.erb +18 -0
- data/lib/deprec/templates/nginx/logrotate.conf.erb +13 -0
- data/lib/deprec/templates/nginx/mime.types.erb +70 -0
- data/lib/deprec/templates/nginx/nginx-init-script +62 -0
- data/lib/deprec/templates/nginx/nginx.conf.erb +125 -0
- data/lib/deprec/templates/nginx/nginx.logrotate.d +12 -0
- data/lib/deprec/templates/nginx/nothing.conf +1 -0
- data/lib/deprec/templates/nginx/rails_nginx_vhost.conf.erb +41 -0
- data/lib/deprec/templates/ntp/ntp.conf.erb +42 -0
- data/lib/deprec/templates/postfix/aliases.erb +3 -0
- data/lib/deprec/templates/postfix/dynamicmaps.cf.erb +8 -0
- data/lib/deprec/templates/postfix/main.cf.erb +41 -0
- data/lib/deprec/templates/postfix/master.cf.erb +77 -0
- data/lib/deprec/templates/sphinx/monit.conf.erb +5 -0
- data/lib/deprec/templates/ssh/ssh_config.erb +50 -0
- data/lib/deprec/templates/ssh/sshd_config.erb +78 -0
- data/lib/deprec/templates/subversion/svn.apache.vhost.erb +43 -0
- data/lib/deprec/templates/trac/apache_vhost.conf.erb +24 -0
- data/lib/deprec/templates/trac/nginx_vhost.conf.erb +26 -0
- data/lib/deprec/templates/trac/trac.ini.erb +169 -0
- data/lib/deprec/templates/trac/trac_deprec.png +0 -0
- data/lib/deprec/templates/trac/tracd-init.erb +43 -0
- data/lib/deprec/templates/trac/users.htdigest.erb +0 -0
- data/lib/deprec/templates/vnstat/config.php +57 -0
- data/lib/deprec/templates/xen/15-disable-hwclock +40 -0
- data/lib/deprec/templates/xen/network-bridge-wrapper +3 -0
- data/lib/deprec/templates/xen/xen-tools.conf.erb +220 -0
- data/lib/deprec/templates/xen/xend-config.sxp.erb +195 -0
- data/lib/deprec/templates/xen/xend-init.erb +69 -0
- data/lib/deprec/templates/xen/xendomains.erb +137 -0
- data/lib/deprec/templates/xen/xm.tmpl.erb +85 -0
- data/lib/deprec.rb +8 -0
- data/lib/deprec_cmd_completion.sh +26 -0
- data/lib/vmbuilder_plugins/all.rb +20 -0
- data/lib/vmbuilder_plugins/apt.rb +93 -0
- data/lib/vmbuilder_plugins/emerge.rb +76 -0
- data/lib/vmbuilder_plugins/gem.rb +90 -0
- data/lib/vmbuilder_plugins/std.rb +203 -0
- metadata +224 -0
@@ -0,0 +1,391 @@
|
|
1
|
+
# Copyright 2006-2008 by Mike Bailey. All rights reserved.
|
2
|
+
require 'capistrano'
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
module Deprec2
|
6
|
+
|
7
|
+
# Temporarly set ROLES to something different
|
8
|
+
def for_roles(roles)
|
9
|
+
old_roles = ENV['ROLES']
|
10
|
+
ENV['ROLES'] = roles
|
11
|
+
yield
|
12
|
+
ENV['ROLES'] = old_roles
|
13
|
+
end
|
14
|
+
|
15
|
+
DEPREC_TEMPLATES_BASE = File.join(File.dirname(__FILE__), 'templates')
|
16
|
+
|
17
|
+
# Render template (usually a config file)
|
18
|
+
#
|
19
|
+
# Usually we render it to a file on the local filesystem.
|
20
|
+
# This way, we keep a copy of the config file under source control.
|
21
|
+
# We can make manual changes if required and push to new hosts.
|
22
|
+
#
|
23
|
+
# If the options hash contains :path then it's written to that path.
|
24
|
+
# If it contains :remote => true, the file will instead be written to remote targets
|
25
|
+
# If options[:path] and options[:remote] are missing, it just returns the rendered
|
26
|
+
# template as a string (good for debugging).
|
27
|
+
#
|
28
|
+
# XXX I would like to get rid of :render_template_to_file
|
29
|
+
# XXX Perhaps pass an option to this function to write to remote
|
30
|
+
#
|
31
|
+
def render_template(app, options={})
|
32
|
+
template = options[:template]
|
33
|
+
path = options[:path] || nil
|
34
|
+
remote = options[:remote] || false
|
35
|
+
mode = options[:mode] || 0755
|
36
|
+
owner = options[:owner] || nil
|
37
|
+
|
38
|
+
# replace this with a check for the file
|
39
|
+
if ! template
|
40
|
+
puts "render_template() requires a value for the template!"
|
41
|
+
return false
|
42
|
+
end
|
43
|
+
|
44
|
+
# If local copies of deprec templates exist they will be used
|
45
|
+
# If you don't specify the location with the local_template_dir option
|
46
|
+
# it defaults to config/templates.
|
47
|
+
# e.g. config/templates/nginx/nginx.conf.erb
|
48
|
+
local_template = File.join(local_template_dir, app.to_s, template)
|
49
|
+
if File.exists?(local_template)
|
50
|
+
puts
|
51
|
+
puts "Using local template (#{local_template})"
|
52
|
+
template = ERB.new(IO.read(local_template), nil, '-')
|
53
|
+
else
|
54
|
+
template = ERB.new(IO.read(File.join(DEPREC_TEMPLATES_BASE, app.to_s, template)), nil, '-')
|
55
|
+
end
|
56
|
+
rendered_template = template.result(binding)
|
57
|
+
|
58
|
+
if remote
|
59
|
+
# render to remote machine
|
60
|
+
puts 'You need to specify a path to render the template to!' unless path
|
61
|
+
exit unless path
|
62
|
+
sudo "test -d #{File.dirname(path)} || sudo mkdir -p #{File.dirname(path)}"
|
63
|
+
std.su_put rendered_template, path, '/tmp/', :mode => mode
|
64
|
+
sudo "chown #{owner} #{path}" if defined?(owner)
|
65
|
+
elsif path
|
66
|
+
# render to local file
|
67
|
+
full_path = File.join('config', app.to_s, path)
|
68
|
+
path_dir = File.dirname(full_path)
|
69
|
+
if File.exists?(full_path)
|
70
|
+
if IO.read(full_path) == rendered_template
|
71
|
+
puts "[skip] File exists and is identical (#{full_path})."
|
72
|
+
return false
|
73
|
+
elsif overwrite?(full_path, rendered_template)
|
74
|
+
File.delete(full_path)
|
75
|
+
else
|
76
|
+
puts "[skip] Not overwriting #{full_path}"
|
77
|
+
return false
|
78
|
+
end
|
79
|
+
end
|
80
|
+
FileUtils.mkdir_p "#{path_dir}" if ! File.directory?(path_dir)
|
81
|
+
# added line above to make windows compatible
|
82
|
+
# system "mkdir -p #{path_dir}" if ! File.directory?(path_dir)
|
83
|
+
File.open(full_path, 'w'){|f| f.write rendered_template }
|
84
|
+
puts "[done] #{full_path} written"
|
85
|
+
else
|
86
|
+
# render to string
|
87
|
+
return rendered_template
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def overwrite?(full_path, rendered_template)
|
92
|
+
if defined?(overwrite_all)
|
93
|
+
if overwrite_all == true
|
94
|
+
return true
|
95
|
+
else
|
96
|
+
return false
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
# XXX add :always and :never later - not sure how to set persistent value from here
|
101
|
+
# response = Capistrano::CLI.ui.ask "File exists. Overwrite? ([y]es, [n]o, [a]lways, n[e]ver)" do |q|
|
102
|
+
puts
|
103
|
+
response = Capistrano::CLI.ui.ask "File exists (#{full_path}).
|
104
|
+
Overwrite? ([y]es, [n]o, [d]iff)" do |q|
|
105
|
+
q.default = 'n'
|
106
|
+
end
|
107
|
+
|
108
|
+
case response
|
109
|
+
when 'y'
|
110
|
+
return true
|
111
|
+
when 'n'
|
112
|
+
return false
|
113
|
+
when 'd'
|
114
|
+
require 'tempfile'
|
115
|
+
tf = Tempfile.new("deprec_diff")
|
116
|
+
tf.puts(rendered_template)
|
117
|
+
tf.close
|
118
|
+
puts
|
119
|
+
puts "Running diff -u current_file new_file_if_you_overwrite"
|
120
|
+
puts
|
121
|
+
system "diff -u #{full_path} #{tf.path} | less"
|
122
|
+
puts
|
123
|
+
overwrite?(full_path, rendered_template)
|
124
|
+
# XXX add :always and :never later - not sure how to set persistent value from here
|
125
|
+
# when 'a'
|
126
|
+
# set :overwrite_all, true
|
127
|
+
# when 'e'
|
128
|
+
# set :overwrite_all, false
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
def render_template_to_file(template_name, destination_file_name, templates_dir = DEPREC_TEMPLATES_BASE)
|
134
|
+
template_name += '.conf' if File.extname(template_name) == '' # XXX this to be removed
|
135
|
+
|
136
|
+
file = File.join(templates_dir, template_name)
|
137
|
+
buffer = render :template => File.read(file)
|
138
|
+
|
139
|
+
temporary_location = "/tmp/#{template_name}"
|
140
|
+
put buffer, temporary_location
|
141
|
+
sudo "cp #{temporary_location} #{destination_file_name}"
|
142
|
+
delete temporary_location
|
143
|
+
end
|
144
|
+
|
145
|
+
# Copy configs to server(s). Note there is no :pull task. No changes should
|
146
|
+
# be made to configs on the servers so why would you need to pull them back?
|
147
|
+
def push_configs(app, files)
|
148
|
+
app = app.to_s
|
149
|
+
files.each do |file|
|
150
|
+
# If the file path is relative we will prepend a path to this projects
|
151
|
+
# own config directory for this service.
|
152
|
+
if file[:path][0,1] != '/'
|
153
|
+
full_remote_path = File.join(deploy_to, app, file[:path])
|
154
|
+
else
|
155
|
+
full_remote_path = file[:path]
|
156
|
+
end
|
157
|
+
full_local_path = File.join('config', app, file[:path])
|
158
|
+
sudo "test -d #{File.dirname(full_remote_path)} || sudo mkdir -p #{File.dirname(full_remote_path)}"
|
159
|
+
#
|
160
|
+
# XXX work this in to check for per-host variants of config files
|
161
|
+
#
|
162
|
+
# if any variants of this file exist for this host (they have -hostname at end)
|
163
|
+
# servers = find_servers_for_task(current_task)
|
164
|
+
# servers.each do |server|
|
165
|
+
# puts server(..., :hosts => server) # XXX find a way to restrict su_put to one host
|
166
|
+
# end
|
167
|
+
# else
|
168
|
+
# # just send them the normal way, it's quicker in parallel
|
169
|
+
std.su_put File.read(full_local_path), full_remote_path, '/tmp/', :mode=>file[:mode]
|
170
|
+
# end
|
171
|
+
#
|
172
|
+
sudo "chown #{file[:owner]} #{full_remote_path}"
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
def teardown_connections
|
177
|
+
sessions.keys.each do |server|
|
178
|
+
sessions[server].close
|
179
|
+
sessions.delete(server)
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
def append_to_file_if_missing(filename, value, options={})
|
184
|
+
# XXX sort out single quotes in 'value' - they'l break command!
|
185
|
+
# XXX if options[:requires_sudo] and :use_sudo then use sudo
|
186
|
+
sudo <<-END
|
187
|
+
sh -c '
|
188
|
+
grep -F "#{value}" #{filename} > /dev/null 2>&1 ||
|
189
|
+
echo "#{value}" >> #{filename}
|
190
|
+
'
|
191
|
+
END
|
192
|
+
end
|
193
|
+
|
194
|
+
# create new user account on target system
|
195
|
+
def useradd(user, options={})
|
196
|
+
options[:shell] ||= '/bin/bash' # new accounts on ubuntu 6.06.1 have been getting /bin/sh
|
197
|
+
switches = ''
|
198
|
+
switches += " --shell=#{options[:shell]} " if options[:shell]
|
199
|
+
switches += ' --create-home ' unless options[:homedir] == false
|
200
|
+
switches += " --gid #{options[:group]} " unless options[:group].nil?
|
201
|
+
invoke_command "grep '^#{user}:' /etc/passwd || sudo /usr/sbin/useradd #{switches} #{user}",
|
202
|
+
:via => run_method
|
203
|
+
end
|
204
|
+
|
205
|
+
# create a new group on target system
|
206
|
+
def groupadd(group, options={})
|
207
|
+
via = options.delete(:via) || run_method
|
208
|
+
# XXX I don't like specifying the path to groupadd - need to sort out paths before long
|
209
|
+
invoke_command "grep '#{group}:' /etc/group || sudo /usr/sbin/groupadd #{group}", :via => via
|
210
|
+
end
|
211
|
+
|
212
|
+
# add group to the list of groups this user belongs to
|
213
|
+
def add_user_to_group(user, group)
|
214
|
+
invoke_command "groups #{user} | grep ' #{group} ' || sudo /usr/sbin/usermod -G #{group} -a #{user}",
|
215
|
+
:via => run_method
|
216
|
+
end
|
217
|
+
|
218
|
+
# create directory if it doesn't already exist
|
219
|
+
# set permissions and ownership
|
220
|
+
# XXX move mode, path and
|
221
|
+
def mkdir(path, options={})
|
222
|
+
via = options.delete(:via) || :run
|
223
|
+
# XXX need to make sudo commands wrap the whole command (sh -c ?)
|
224
|
+
# XXX removed the extra 'sudo' from after the '||' - need something else
|
225
|
+
invoke_command "test -d #{path} || #{sudo if via == :sudo} mkdir -p #{path}"
|
226
|
+
invoke_command "chmod #{sprintf("%3o",options[:mode]||0755)} #{path}", :via => via if options[:mode]
|
227
|
+
invoke_command "chown -R #{options[:owner]} #{path}", :via => via if options[:owner]
|
228
|
+
groupadd(options[:group], :via => via) if options[:group]
|
229
|
+
invoke_command "chgrp -R #{options[:group]} #{path}", :via => via if options[:group]
|
230
|
+
end
|
231
|
+
|
232
|
+
def create_src_dir
|
233
|
+
mkdir(src_dir, :mode => 0775, :group => group_src, :via => :sudo)
|
234
|
+
end
|
235
|
+
|
236
|
+
# download source package if we don't already have it
|
237
|
+
def download_src(src_package, src_dir)
|
238
|
+
set_package_defaults(src_package)
|
239
|
+
create_src_dir
|
240
|
+
# check if file exists and if we have an MD5 hash or bytecount to compare
|
241
|
+
# against if so, compare and decide if we need to download again
|
242
|
+
if defined?(src_package[:md5sum])
|
243
|
+
md5_clause = " && echo '#{src_package[:md5sum]}' | md5sum -c - "
|
244
|
+
end
|
245
|
+
apt.install( {:base => %w(wget)}, :stable )
|
246
|
+
# XXX replace with invoke_command
|
247
|
+
run "cd #{src_dir} && test -f #{src_package[:filename]} #{md5_clause} || #{sudo} wget --quiet --timestamping #{src_package[:url]}"
|
248
|
+
end
|
249
|
+
|
250
|
+
# unpack src and make it writable by the group
|
251
|
+
def unpack_src(src_package, src_dir)
|
252
|
+
set_package_defaults(src_package)
|
253
|
+
package_dir = File.join(src_dir, src_package[:dir])
|
254
|
+
# XXX replace with invoke_command
|
255
|
+
sudo <<-EOF
|
256
|
+
bash -c '
|
257
|
+
cd #{src_dir};
|
258
|
+
test -d #{package_dir}.old && rm -fr #{package_dir}.old;
|
259
|
+
test -d #{package_dir} && mv #{package_dir} #{package_dir}.old;
|
260
|
+
#{src_package[:unpack]}
|
261
|
+
chgrp -R #{group} #{package_dir};
|
262
|
+
chmod -R g+w #{package_dir};
|
263
|
+
'
|
264
|
+
EOF
|
265
|
+
end
|
266
|
+
|
267
|
+
def set_package_defaults(pkg)
|
268
|
+
pkg[:filename] ||= File.basename(pkg[:url])
|
269
|
+
pkg[:dir] ||= pkg[:filename].sub(/(\.tgz|\.tar\.gz)/,'')
|
270
|
+
pkg[:unpack] ||= "tar zxf #{pkg[:filename]};"
|
271
|
+
pkg[:configure] ||= './configure ;'
|
272
|
+
pkg[:make] ||= 'make;'
|
273
|
+
pkg[:install] ||= 'make install;'
|
274
|
+
end
|
275
|
+
|
276
|
+
# install package from source
|
277
|
+
def install_from_src(src_package, src_dir)
|
278
|
+
package_dir = File.join(src_dir, src_package[:dir])
|
279
|
+
unpack_src(src_package, src_dir)
|
280
|
+
apt.install( {:base => %w(build-essential)}, :stable )
|
281
|
+
# XXX replace with invoke_command
|
282
|
+
sudo <<-SUDO
|
283
|
+
sh -c '
|
284
|
+
cd #{package_dir};
|
285
|
+
#{src_package[:configure]}
|
286
|
+
#{src_package[:make]}
|
287
|
+
#{src_package[:install]}
|
288
|
+
#{src_package[:post_install]}
|
289
|
+
'
|
290
|
+
SUDO
|
291
|
+
end
|
292
|
+
|
293
|
+
|
294
|
+
##
|
295
|
+
# Run a command and ask for input when input_query is seen.
|
296
|
+
# Sends the response back to the server.
|
297
|
+
#
|
298
|
+
# +input_query+ is a regular expression that defaults to /^Password/.
|
299
|
+
#
|
300
|
+
# Can be used where +run+ would otherwise be used.
|
301
|
+
#
|
302
|
+
# run_with_input 'ssh-keygen ...', /^Are you sure you want to overwrite\?/
|
303
|
+
|
304
|
+
def run_with_input(shell_command, input_query=/^Password/, response=nil)
|
305
|
+
handle_command_with_input(:run, shell_command, input_query, response)
|
306
|
+
end
|
307
|
+
|
308
|
+
##
|
309
|
+
# Run a command using sudo and ask for input when a regular expression is seen.
|
310
|
+
# Sends the response back to the server.
|
311
|
+
#
|
312
|
+
# See also +run_with_input+
|
313
|
+
#
|
314
|
+
# +input_query+ is a regular expression
|
315
|
+
|
316
|
+
def sudo_with_input(shell_command, input_query=/^Password/, response=nil)
|
317
|
+
handle_command_with_input(:sudo, shell_command, input_query, response)
|
318
|
+
end
|
319
|
+
|
320
|
+
def invoke_with_input(shell_command, input_query=/^Password/, response=nil)
|
321
|
+
handle_command_with_input(run_method, shell_command, input_query, response)
|
322
|
+
end
|
323
|
+
|
324
|
+
##
|
325
|
+
# Run a command using sudo and continuously pipe the results back to the console.
|
326
|
+
#
|
327
|
+
# Similar to the built-in +stream+, but for privileged users.
|
328
|
+
|
329
|
+
def sudo_stream(command)
|
330
|
+
sudo(command) do |ch, stream, out|
|
331
|
+
puts out if stream == :out
|
332
|
+
if stream == :err
|
333
|
+
puts "[err : #{ch[:host]}] #{out}"
|
334
|
+
break
|
335
|
+
end
|
336
|
+
end
|
337
|
+
end
|
338
|
+
|
339
|
+
# We don't need this. Put 'USER=root' on the command line instead.
|
340
|
+
#
|
341
|
+
# XXX Not working in deprec2
|
342
|
+
# ##
|
343
|
+
# # Run a command using the root account.
|
344
|
+
# #
|
345
|
+
# # Some linux distros/VPS providers only give you a root login when you install.
|
346
|
+
#
|
347
|
+
# def run_as_root(shell_command)
|
348
|
+
# std.connect_as_root do |tempuser|
|
349
|
+
# run shell_command
|
350
|
+
# end
|
351
|
+
# end
|
352
|
+
#
|
353
|
+
# ##
|
354
|
+
# # Run a task using root account.
|
355
|
+
# #
|
356
|
+
# # Some linux distros/VPS providers only give you a root login when you install.
|
357
|
+
# #
|
358
|
+
# # tempuser: contains the value replaced by 'root' for the duration of this call
|
359
|
+
#
|
360
|
+
# def as_root()
|
361
|
+
# std.connect_as_root do |tempuser|
|
362
|
+
# yield tempuser
|
363
|
+
# end
|
364
|
+
# end
|
365
|
+
|
366
|
+
private
|
367
|
+
|
368
|
+
##
|
369
|
+
# Does the actual capturing of the input and streaming of the output.
|
370
|
+
#
|
371
|
+
# local_run_method: run or sudo
|
372
|
+
# shell_command: The command to run
|
373
|
+
# input_query: A regular expression matching a request for input: /^Please enter your password/
|
374
|
+
|
375
|
+
def handle_command_with_input(local_run_method, shell_command, input_query, response=nil)
|
376
|
+
send(local_run_method, shell_command) do |channel, stream, data|
|
377
|
+
logger.info data, channel[:host]
|
378
|
+
if data =~ input_query
|
379
|
+
if response
|
380
|
+
channel.send_data "#{response}\n"
|
381
|
+
else
|
382
|
+
response = ::Capistrano::CLI.password_prompt "#{data}"
|
383
|
+
channel.send_data "#{response}\n"
|
384
|
+
end
|
385
|
+
end
|
386
|
+
end
|
387
|
+
end
|
388
|
+
|
389
|
+
end
|
390
|
+
|
391
|
+
Capistrano.plugin :deprec2, Deprec2
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# Copyright 2006-2008 by Mike Bailey. All rights reserved.
|
2
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
3
|
+
|
4
|
+
SRC_PACKAGES[:aoe] = {
|
5
|
+
:filename => 'aoe6-56.tar.gz',
|
6
|
+
:md5sum => "93689aaad32f647a788c15c82bd0158e aoe6-56.tar.gz",
|
7
|
+
:dir => 'aoe6-56',
|
8
|
+
:url => "http://www.coraid.com/support/linux/aoe6-56.tar.gz",
|
9
|
+
:unpack => "tar zxf aoe6-56.tar.gz;",
|
10
|
+
:make => 'make;',
|
11
|
+
:install => 'make install;'
|
12
|
+
}
|
13
|
+
|
14
|
+
namespace :deprec do
|
15
|
+
namespace :aoe do
|
16
|
+
|
17
|
+
desc "Install aoe drivers required to mount Coraid block devices"
|
18
|
+
task :install do
|
19
|
+
install_deps
|
20
|
+
deprec2.download_src(SRC_PACKAGES[:aoe], src_dir)
|
21
|
+
deprec2.install_from_src(SRC_PACKAGES[:aoe], src_dir)
|
22
|
+
end
|
23
|
+
|
24
|
+
task :install_deps do
|
25
|
+
apt.install( {:base => %w(build-essential linux-headers-$(uname -r) vblade aoetools)}, :stable )
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
SRC_PACKAGES[:cec] = {
|
32
|
+
:url => "http://easynews.dl.sourceforge.net/sourceforge/aoetools/cec-8.tgz",
|
33
|
+
:md5sum => "7899dc549f9a368e532f9c39ed819f71 cec-8.tgz"
|
34
|
+
}
|
35
|
+
|
36
|
+
namespace :cec do
|
37
|
+
|
38
|
+
desc "install CEC (Coraid Ethernet Console)"
|
39
|
+
task :install do
|
40
|
+
deprec2.download_src(SRC_PACKAGES[:cec], src_dir)
|
41
|
+
deprec2.install_from_src(SRC_PACKAGES[:cec], src_dir)
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
SRC_PACKAGES[:ddt] = {
|
47
|
+
:url => "http://support.coraid.com/support/sr/ddt-6.tgz",
|
48
|
+
:md5sum => "5e1e8a58a8621b93440be605113f7bc0 ddt-6.tgz"
|
49
|
+
}
|
50
|
+
|
51
|
+
namespace :ddt do
|
52
|
+
|
53
|
+
desc "install DDT (tool for testing performance)"
|
54
|
+
task :install do
|
55
|
+
deprec2.download_src(SRC_PACKAGES[:ddt], src_dir)
|
56
|
+
deprec2.install_from_src(SRC_PACKAGES[:ddt], src_dir)
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
SRC_PACKAGES[:aoemask] = {
|
62
|
+
:url => "http://support.coraid.com/support/sr/aoemask-1.tgz",
|
63
|
+
:md5sum => "379461a28d511e269f4593b846bd1288 aoemask-1.tgz"
|
64
|
+
}
|
65
|
+
|
66
|
+
namespace :aoemask do
|
67
|
+
|
68
|
+
desc "install aoemask"
|
69
|
+
task :install do
|
70
|
+
deprec2.download_src(SRC_PACKAGES[:aoemask], src_dir)
|
71
|
+
deprec2.install_from_src(SRC_PACKAGES[:aoemask], src_dir)
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
|
@@ -0,0 +1,179 @@
|
|
1
|
+
# Copyright 2006-2008 by Mike Bailey. All rights reserved.
|
2
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
3
|
+
namespace :deprec do
|
4
|
+
namespace :apache do
|
5
|
+
|
6
|
+
# put apache config for site in shared/config/apache2 dir
|
7
|
+
# link it into apps to enable, unlink to disable?
|
8
|
+
# http://times.usefulinc.com/2006/09/15-rails-debian-apache
|
9
|
+
|
10
|
+
# XXX Check this over after a nice sleep
|
11
|
+
#
|
12
|
+
# def set_apache_conf
|
13
|
+
# if apache_default_vhost
|
14
|
+
# set :apache_conf, "/usr/local/apache2/conf/default.conf" unless apache_default_vhost_conf
|
15
|
+
# else
|
16
|
+
# set :apache_conf, "/usr/local/apache2/conf/apps/#{application}.conf" unless apache_conf
|
17
|
+
# end
|
18
|
+
# end
|
19
|
+
|
20
|
+
set(:apache_server_name) { domain }
|
21
|
+
set :apache_user, 'daemon' # XXX this is not yet being inserted into httpd.conf!
|
22
|
+
# I've added it for deprec:nagios:install
|
23
|
+
set :apache_conf, nil
|
24
|
+
set :apache_default_vhost, false
|
25
|
+
set :apache_default_vhost_conf, nil
|
26
|
+
set :apache_ctl, "/usr/local/apache2/bin/apachectl"
|
27
|
+
set(:apache_server_aliases) { web_server_aliases }
|
28
|
+
set :apache_proxy_port, 8000
|
29
|
+
set :apache_proxy_servers, 2
|
30
|
+
set :apache_proxy_address, "127.0.0.1"
|
31
|
+
set :apache_ssl_enabled, false
|
32
|
+
set :apache_ssl_ip, nil
|
33
|
+
set :apache_ssl_forward_all, false
|
34
|
+
set :apache_ssl_chainfile, false
|
35
|
+
set :apache_docroot, '/usr/local/apache2/htdocs'
|
36
|
+
set :apache_vhost_dir, '/usr/local/apache2/conf/apps'
|
37
|
+
set :apache_config_file, '/usr/local/apache2/conf/httpd.conf'
|
38
|
+
|
39
|
+
SRC_PACKAGES[:apache] = {
|
40
|
+
:md5sum => "80d3754fc278338033296f0d41ef2c04 httpd-2.2.9.tar.gz",
|
41
|
+
:url => "http://www.apache.org/dist/httpd/httpd-2.2.9.tar.gz",
|
42
|
+
:configure => %w(
|
43
|
+
./configure
|
44
|
+
--enable-mods-shared=all
|
45
|
+
--enable-proxy
|
46
|
+
--enable-proxy-balancer
|
47
|
+
--enable-proxy-http
|
48
|
+
--enable-rewrite
|
49
|
+
--enable-cache
|
50
|
+
--enable-headers
|
51
|
+
--enable-ssl
|
52
|
+
--enable-deflate
|
53
|
+
--with-included-apr #_so_this_recipe_doesn't_break_when_rerun
|
54
|
+
--enable-dav #_for_subversion_
|
55
|
+
--enable-so #_for_subversion_
|
56
|
+
;
|
57
|
+
).reject{|arg| arg.match '#'}.join(' '),
|
58
|
+
:make => 'make;',
|
59
|
+
:post_install => 'install -b support/apachectl /etc/init.d/httpd;'
|
60
|
+
}
|
61
|
+
|
62
|
+
desc "Install apache"
|
63
|
+
task :install do
|
64
|
+
install_deps
|
65
|
+
deprec2.download_src(SRC_PACKAGES[:apache], src_dir)
|
66
|
+
deprec2.install_from_src(SRC_PACKAGES[:apache], src_dir)
|
67
|
+
setup_vhost_dir
|
68
|
+
# install_index_page
|
69
|
+
activate
|
70
|
+
SYSTEM_CONFIG_FILES[:apache].each do |file|
|
71
|
+
deprec2.render_template(:apache, file.merge(:remote => true))
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# install dependencies for apache
|
76
|
+
task :install_deps do
|
77
|
+
apt.install( {:base => %w(zlib1g-dev zlib1g openssl libssl-dev)}, :stable )
|
78
|
+
end
|
79
|
+
|
80
|
+
# Create dir for vhost config files
|
81
|
+
task :setup_vhost_dir do
|
82
|
+
deprec2.mkdir(apache_vhost_dir, :owner => 'root', :group => group, :mode => 0775, :via => :sudo)
|
83
|
+
deprec2.append_to_file_if_missing(apache_config_file, 'Include conf/apps/')
|
84
|
+
end
|
85
|
+
|
86
|
+
SYSTEM_CONFIG_FILES[:apache] = [
|
87
|
+
# They're generated and put in place during install
|
88
|
+
# I may put them in here at some point
|
89
|
+
]
|
90
|
+
|
91
|
+
PROJECT_CONFIG_FILES[:apache] = [
|
92
|
+
|
93
|
+
{:template => "httpd-vhost-app.conf.erb",
|
94
|
+
:path => 'conf/httpd-vhost-app.conf',
|
95
|
+
:mode => 0755,
|
96
|
+
:owner => 'root:root'}
|
97
|
+
]
|
98
|
+
|
99
|
+
desc "Generate configuration file(s) for apache from template(s)"
|
100
|
+
task :config_gen do
|
101
|
+
config_gen_system
|
102
|
+
config_gen_project
|
103
|
+
end
|
104
|
+
|
105
|
+
task :config_gen_system do
|
106
|
+
SYSTEM_CONFIG_FILES[:apache].each do |file|
|
107
|
+
deprec2.render_template(:apache, file)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
task :config_gen_project do
|
112
|
+
PROJECT_CONFIG_FILES[:apache].each do |file|
|
113
|
+
deprec2.render_template(:apache, file)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
desc "Push apache config files to server"
|
118
|
+
task :config, :roles => :web do
|
119
|
+
config_system
|
120
|
+
config_project
|
121
|
+
end
|
122
|
+
|
123
|
+
task :config_system, :roles => :web do
|
124
|
+
deprec2.push_configs(:apache, SYSTEM_CONFIG_FILES[:apache])
|
125
|
+
end
|
126
|
+
|
127
|
+
task :config_project, :roles => :web do
|
128
|
+
deprec2.push_configs(:apache, PROJECT_CONFIG_FILES[:apache])
|
129
|
+
sudo "ln -sf #{deploy_to}/apache/conf/httpd-vhost-app.conf /usr/local/apache2/conf/apps/#{application}.conf"
|
130
|
+
end
|
131
|
+
|
132
|
+
desc "Start Apache"
|
133
|
+
task :start, :roles => :web do
|
134
|
+
send(run_method, "#{apache_ctl} start")
|
135
|
+
end
|
136
|
+
|
137
|
+
desc "Stop Apache"
|
138
|
+
task :stop, :roles => :web do
|
139
|
+
send(run_method, "#{apache_ctl} stop")
|
140
|
+
end
|
141
|
+
|
142
|
+
desc "Restart Apache"
|
143
|
+
task :restart, :roles => :web do
|
144
|
+
send(run_method, "#{apache_ctl} restart")
|
145
|
+
end
|
146
|
+
|
147
|
+
desc "Reload Apache"
|
148
|
+
task :reload, :roles => :web do
|
149
|
+
send(run_method, "#{apache_ctl} reload")
|
150
|
+
end
|
151
|
+
|
152
|
+
desc "Set apache to start on boot"
|
153
|
+
task :activate do
|
154
|
+
send(run_method, "update-rc.d httpd defaults")
|
155
|
+
end
|
156
|
+
|
157
|
+
desc "Set apache to not start on boot"
|
158
|
+
task :deactivate, :roles => :web do
|
159
|
+
send(run_method, "update-rc.d -f httpd remove")
|
160
|
+
end
|
161
|
+
|
162
|
+
task :backup, :roles => :web do
|
163
|
+
# not yet implemented
|
164
|
+
end
|
165
|
+
|
166
|
+
task :restore, :roles => :web do
|
167
|
+
# not yet implemented
|
168
|
+
end
|
169
|
+
|
170
|
+
# Generate an index.html page
|
171
|
+
task :install_index_page do
|
172
|
+
deprec2.mkdir(apache_docroot, :owner => :root, :group => :deploy, :mode => 0775, :via => :sudo)
|
173
|
+
std.su_put deprec2.render_template(:apache, :template => 'index.html.erb'), File.join(apache_docroot, 'index.html')
|
174
|
+
std.su_put deprec2.render_template(:apache, :template => 'master.css'), File.join(apache_docroot, 'master.css')
|
175
|
+
end
|
176
|
+
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|