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 @@
|
|
1
|
+
description: The monit module
|
@@ -0,0 +1,48 @@
|
|
1
|
+
<%
|
2
|
+
@path = '/etc/munin/munin-node.conf'
|
3
|
+
@post = '/etc/init.d/munin-node restart'
|
4
|
+
%>
|
5
|
+
|
6
|
+
#
|
7
|
+
# Example config-file for munin-node
|
8
|
+
#
|
9
|
+
|
10
|
+
log_level 4
|
11
|
+
log_file /var/log/munin/munin-node.log
|
12
|
+
port 4949
|
13
|
+
pid_file /var/run/munin/munin-node.pid
|
14
|
+
background 1
|
15
|
+
setseid 1
|
16
|
+
|
17
|
+
# Which port to bind to;
|
18
|
+
host *
|
19
|
+
user root
|
20
|
+
group root
|
21
|
+
setsid yes
|
22
|
+
|
23
|
+
# Regexps for files to ignore
|
24
|
+
|
25
|
+
ignore_file ~$
|
26
|
+
ignore_file \.bak$
|
27
|
+
ignore_file %$
|
28
|
+
ignore_file \.dpkg-(tmp|new|old|dist)$
|
29
|
+
ignore_file \.rpm(save|new)$
|
30
|
+
|
31
|
+
# Set this if the client doesn't report the correct hostname when
|
32
|
+
# telnetting to localhost, port 4949
|
33
|
+
#
|
34
|
+
#host_name localhost.localdomain
|
35
|
+
|
36
|
+
# A list of addresses that are allowed to connect. This must be a
|
37
|
+
# regular expression, due to brain damage in Net::Server, which
|
38
|
+
# doesn't understand CIDR-style network notation. You may repeat
|
39
|
+
# the allow line as many times as you'd like
|
40
|
+
|
41
|
+
allow ^127\.0\.0\.1$
|
42
|
+
|
43
|
+
<%
|
44
|
+
munin_server = rubber_instances.for_role('web_tools').first.internal_ip rescue "127.0.0.1"
|
45
|
+
munin_server = munin_server.gsub(/\./, "\\.")
|
46
|
+
%>
|
47
|
+
allow ^<%= munin_server %>$
|
48
|
+
|
@@ -0,0 +1,46 @@
|
|
1
|
+
|
2
|
+
namespace :rubber do
|
3
|
+
|
4
|
+
namespace :munin do
|
5
|
+
|
6
|
+
rubber.allow_optional_tasks(self)
|
7
|
+
|
8
|
+
after "rubber:install_packages", "rubber:munin:custom_install"
|
9
|
+
|
10
|
+
# sometimes apt-get install of munin doesn't end up configuring
|
11
|
+
# plugins (e.g. installing postfix at same time, postfix plugin
|
12
|
+
# configure barfs as postfix not configured yet)
|
13
|
+
desc <<-DESC
|
14
|
+
Reconfigures munin
|
15
|
+
DESC
|
16
|
+
task :custom_install do
|
17
|
+
rubber.run_script 'setup_munin_plugins', <<-ENDSCRIPT
|
18
|
+
munin-node-configure --shell --remove-also > /tmp/setup-munin-plugins
|
19
|
+
sh /tmp/setup-munin-plugins
|
20
|
+
ENDSCRIPT
|
21
|
+
restart
|
22
|
+
end
|
23
|
+
|
24
|
+
# after "deploy:stop", "rubber:munin:stop"
|
25
|
+
# before "deploy:start", "rubber:munin:start"
|
26
|
+
# after "deploy:restart", "rubber:munin:restart"
|
27
|
+
|
28
|
+
desc "Start munin system monitoring"
|
29
|
+
task :start do
|
30
|
+
run "/etc/init.d/munin-node start"
|
31
|
+
end
|
32
|
+
|
33
|
+
desc "Stop munin system monitoring"
|
34
|
+
task :stop, :on_error => :continue do
|
35
|
+
run "/etc/init.d/munin-node stop"
|
36
|
+
end
|
37
|
+
|
38
|
+
desc "Restart munin system monitoring"
|
39
|
+
task :restart do
|
40
|
+
stop
|
41
|
+
start
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
<%
|
2
|
+
@path = "/etc/munin/plugin-conf.d/munin-node"
|
3
|
+
@additive = ["# rubber-munin-plugins-start", "# rubber-munin-plugins-end"]
|
4
|
+
@post = <<-POST
|
5
|
+
/etc/init.d/munin-node restart
|
6
|
+
POST
|
7
|
+
|
8
|
+
root = RUBBER_ENV == 'development' ? "#{RUBBER_ROOT}/tmp/rubber" : ""
|
9
|
+
script_dir = "#{RUBBER_ROOT}/script/munin"
|
10
|
+
plugin_dir = "#{root}/etc/munin/plugins"
|
11
|
+
plugin_prefix = "rubber_"
|
12
|
+
%>
|
13
|
+
|
14
|
+
<%
|
15
|
+
# cleanup old plugins
|
16
|
+
File.delete(*Dir["#{plugin_dir}/#{plugin_prefix}*"])
|
17
|
+
|
18
|
+
# for each script in our source tree, create a wrapper in
|
19
|
+
# munin plgin dir so that we can set rails env
|
20
|
+
Dir["#{script_dir}/*"].each do |script|
|
21
|
+
plugin_name = plugin_prefix + File.basename(script)
|
22
|
+
File.open("#{plugin_dir}/#{plugin_name}", 'w') do |p|
|
23
|
+
p.chmod(0755)
|
24
|
+
p.puts('#!/bin/sh')
|
25
|
+
p.puts("RUBBER_ENV=#{RUBBER_ENV} #{script} $*")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
%>
|
29
|
+
|
30
|
+
# Active rubber plugins: <%= Dir["#{plugin_dir}/#{plugin_prefix}*"].collect {|f| File.basename(f) }.join(", ") %>
|
31
|
+
|
@@ -0,0 +1,80 @@
|
|
1
|
+
<%
|
2
|
+
@path = '/etc/munin/munin.conf'
|
3
|
+
%>
|
4
|
+
|
5
|
+
# Example configuration file for Munin, generated by 'make build'
|
6
|
+
|
7
|
+
# The next three variables specifies where the location of the RRD
|
8
|
+
# databases, the HTML output, and the logs, severally. They all
|
9
|
+
# must be writable by the user running munin-cron.
|
10
|
+
dbdir /var/lib/munin
|
11
|
+
htmldir /var/www/munin
|
12
|
+
logdir /var/log/munin
|
13
|
+
rundir /var/run/munin
|
14
|
+
|
15
|
+
# Where to look for the HTML templates
|
16
|
+
tmpldir /etc/munin/templates
|
17
|
+
|
18
|
+
# Make graphs show values per minute instead of per second
|
19
|
+
#graph_period minute
|
20
|
+
|
21
|
+
# Drop somejuser@fnord.comm and anotheruser@blibb.comm an email everytime
|
22
|
+
# something changes (OK -> WARNING, CRITICAL -> OK, etc)
|
23
|
+
#contact.someuser.command mail -s "Munin notification" somejuser@fnord.comm
|
24
|
+
#contact.anotheruser.command mail -s "Munin notification" anotheruser@blibb.comm
|
25
|
+
#
|
26
|
+
# For those with Nagios, the following might come in handy. In addition,
|
27
|
+
# the services must be defined in the Nagios server as well.
|
28
|
+
#contact.nagios.command /usr/sbin/send_nsca -H nagios.host.com -c /etc/send_nsca.cfg
|
29
|
+
|
30
|
+
contacts dev
|
31
|
+
contact.dev.command mail -s "Munin notification ${var:host} : ${var:group}" <%= rubber_env.admin_email %>
|
32
|
+
contact.dev.always_send warning critical
|
33
|
+
|
34
|
+
|
35
|
+
<% rubber_instances.each do |i| %>
|
36
|
+
[<%= i.full_name %>]
|
37
|
+
address <%= i.internal_ip %>
|
38
|
+
use_node_name yes
|
39
|
+
<% end %>
|
40
|
+
|
41
|
+
#
|
42
|
+
# A more complex example of a host tree
|
43
|
+
#
|
44
|
+
## First our "normal" host.
|
45
|
+
# [fii.foo.com]
|
46
|
+
# address foo
|
47
|
+
#
|
48
|
+
## Then our other host...
|
49
|
+
# [fay.foo.com]
|
50
|
+
# address fay
|
51
|
+
#
|
52
|
+
## Then we want totals...
|
53
|
+
# [foo.com;Totals] #Force it into the "foo.com"-domain...
|
54
|
+
# update no # Turn off data-fetching for this "host".
|
55
|
+
#
|
56
|
+
# # The graph "load1". We want to see the loads of both machines...
|
57
|
+
# # "fii=fii.foo.com:load.load" means "label=machine:graph.field"
|
58
|
+
# load1.graph_title Loads side by side
|
59
|
+
# load1.graph_order fii=fii.foo.com:load.load fay=fay.foo.com:load.load
|
60
|
+
#
|
61
|
+
# # The graph "load2". Now we want them stacked on top of each other.
|
62
|
+
# load2.graph_title Loads on top of each other
|
63
|
+
# load2.dummy_field.stack fii=fii.foo.com:load.load fay=fay.foo.com:load.load
|
64
|
+
# load2.dummy_field.draw AREA # We want area instead the default LINE2.
|
65
|
+
# load2.dummy_field.label dummy # This is needed. Silly, really.
|
66
|
+
#
|
67
|
+
# # The graph "load3". Now we want them summarised into one field
|
68
|
+
# load3.graph_title Loads summarised
|
69
|
+
# load3.combined_loads.sum fii.foo.com:load.load fay.foo.com:load.load
|
70
|
+
# load3.combined_loads.label Combined loads # Must be set, as this is
|
71
|
+
# # not a dummy field!
|
72
|
+
#
|
73
|
+
## ...and on a side note, I want them listen in another order (default is
|
74
|
+
## alphabetically)
|
75
|
+
#
|
76
|
+
# # Since [foo.com] would be interpreted as a host in the domain "com", we
|
77
|
+
# # specify that this is a domain by adding a semicolon.
|
78
|
+
# [foo.com;]
|
79
|
+
# node_order Totals fii.foo.com fay.foo.com
|
80
|
+
#
|
@@ -0,0 +1,57 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Example munin plugin for querying stats out of db
|
4
|
+
# See munin plugin docs http://munin.projects.linpro.no/wiki/Documentation#Plugins
|
5
|
+
#
|
6
|
+
# Scripts added to RUBBER_ROOT/script/munin automatically
|
7
|
+
# get installed as munin plugins by rubber
|
8
|
+
|
9
|
+
# remove this line to enable
|
10
|
+
exit 0
|
11
|
+
|
12
|
+
# load just rubber config without loading rails (you can load rails
|
13
|
+
# if you want, but may be slow if your app loads a lot of plugins)
|
14
|
+
|
15
|
+
require "rubber"
|
16
|
+
env = ENV["RUBBER_ENV"] ||= "development"
|
17
|
+
root = File.join(File.dirname(__FILE__), '../..')
|
18
|
+
Rubber::initialize(root, env)
|
19
|
+
RUBBER_CONFIG = Rubber::Configuration.rubber_env
|
20
|
+
RUBBER_INSTANCES = Rubber::Configuration.rubber_instances
|
21
|
+
|
22
|
+
# Print config info need by munin for generating graphs
|
23
|
+
if ARGV[0] == "config"
|
24
|
+
puts 'graph_title User Count'
|
25
|
+
puts 'graph_vlabel Users'
|
26
|
+
puts 'graph_category Examples'
|
27
|
+
puts 'graph_scale no'
|
28
|
+
puts 'tusers.label total users'
|
29
|
+
puts 'tusers.type GAUGE'
|
30
|
+
puts 'nusers.label user delta'
|
31
|
+
puts 'nusers.type COUNTER'
|
32
|
+
exit 0
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
query = <<-EOF
|
37
|
+
select count(id) from users;
|
38
|
+
EOF
|
39
|
+
|
40
|
+
# pick a non-critical db if possible
|
41
|
+
source = RUBBER_INSTANCES.for_role("mysql_util").first
|
42
|
+
source ||= RUBBER_INSTANCES.for_role("mysql_slave").first
|
43
|
+
source ||= RUBBER_INSTANCES.for_role("mysql_master").first
|
44
|
+
db_host = source ? source.full_name : 'localhost'
|
45
|
+
|
46
|
+
command = "mysql -u #{RUBBER_ENV.db_slave_user}"
|
47
|
+
command << " --password=#{RUBBER_ENV.db_pass}"
|
48
|
+
command << " -h #{db_host}"
|
49
|
+
command << " #{RUBBER_ENV.db_name} --skip-column-names"
|
50
|
+
|
51
|
+
# execute a sql query to get some data
|
52
|
+
data = `echo "#{query}" | #{command}`
|
53
|
+
fail "Couldn't execute command" if $?.exitstatus > 0
|
54
|
+
|
55
|
+
# print graph data values
|
56
|
+
puts "tusers.value #{data}"
|
57
|
+
puts "nusers.value #{data}"
|
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Example munin plugin.
|
4
|
+
# See munin plugin docs http://munin.projects.linpro.no/wiki/Documentation#Plugins
|
5
|
+
#
|
6
|
+
# Scripts added to RUBBER_ROOT/script/munin automatically
|
7
|
+
# get installed as munin plugins by rubber
|
8
|
+
|
9
|
+
# remove this line to enable
|
10
|
+
exit 0
|
11
|
+
|
12
|
+
# Print config info need by munin for generating graphs
|
13
|
+
if ARGV[0] == "config"
|
14
|
+
puts 'graph_title Example Stats'
|
15
|
+
puts 'graph_vlabel random 1-100'
|
16
|
+
puts 'graph_category Examples'
|
17
|
+
puts 'graph_scale no'
|
18
|
+
puts 'rand.label random'
|
19
|
+
|
20
|
+
exit 0
|
21
|
+
end
|
22
|
+
|
23
|
+
# print graph data values
|
24
|
+
puts "rand.value #{rand(100)}"
|
@@ -0,0 +1 @@
|
|
1
|
+
description: The munin module
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<%
|
2
|
+
@path = "#{RUBBER_ROOT}/config/database.yml"
|
3
|
+
%>
|
4
|
+
|
5
|
+
<%= RUBBER_ENV %>:
|
6
|
+
adapter: mysql
|
7
|
+
encoding: utf8
|
8
|
+
database: <%= rubber_env.db_name %>
|
9
|
+
username: <%= rubber_env.db_user %>
|
10
|
+
password: <%= rubber_env.db_pass %>
|
11
|
+
host: <%= rubber_instances.for_role('db', 'primary' => true).first.full_name %>
|
@@ -0,0 +1,156 @@
|
|
1
|
+
|
2
|
+
namespace :rubber do
|
3
|
+
|
4
|
+
namespace :mysql do
|
5
|
+
|
6
|
+
rubber.allow_optional_tasks(self)
|
7
|
+
|
8
|
+
after "rubber:create", "rubber:mysql:validate_db_roles"
|
9
|
+
|
10
|
+
task :validate_db_roles do
|
11
|
+
db_instances = rubber_instances.for_role("mysql_slave")
|
12
|
+
db_instances.each do |instance|
|
13
|
+
if instance.role_names.find {|n| n == 'mysql_master'}
|
14
|
+
fatal "Cannot have a mysql slave and master on the same instance, please removing slave role for #{instance.name}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
after "rubber:bootstrap", "rubber:mysql:bootstrap"
|
20
|
+
|
21
|
+
|
22
|
+
# Bootstrap the production database config. Db bootstrap is special - the
|
23
|
+
# user could be requiring the rails env inside some of their config
|
24
|
+
# templates, which creates a catch 22 situation with the db, so we try and
|
25
|
+
# bootstrap the db separate from the rest of the config
|
26
|
+
task :bootstrap, :roles => [:mysql_master, :mysql_slave] do
|
27
|
+
|
28
|
+
# Conditionaly bootstrap for each node/role only if that node has not
|
29
|
+
# been boostrapped for that role before
|
30
|
+
|
31
|
+
master_instances = rubber_instances.for_role("mysql_master") & rubber_instances.filtered
|
32
|
+
master_instances.each do |ic|
|
33
|
+
task_name = "_bootstrap_mysql_master_#{ic.full_name}".to_sym()
|
34
|
+
task task_name, :hosts => ic.full_name do
|
35
|
+
env = rubber_cfg.environment.bind("mysql_master", ic.name)
|
36
|
+
exists = capture("echo $(ls #{env.db_data_dir}/ 2> /dev/null)")
|
37
|
+
if exists.strip.size == 0
|
38
|
+
common_bootstrap("mysql_master")
|
39
|
+
sudo "dpkg-reconfigure --frontend=noninteractive mysql-server-5.0"
|
40
|
+
sleep 5
|
41
|
+
pass = "identified by '#{env.db_pass}'" if env.db_pass
|
42
|
+
sudo "mysql -u root -e 'create database #{env.db_name};'"
|
43
|
+
sudo "mysql -u root -e \"grant all on *.* to '#{env.db_user}'@'%' #{pass};\""
|
44
|
+
sudo "mysql -u root -e \"grant select on *.* to '#{env.db_slave_user}'@'%' #{pass};\""
|
45
|
+
sudo "mysql -u root -e \"grant replication slave on *.* to '#{env.db_replicator_user}'@'%' #{pass};\""
|
46
|
+
sudo "mysql -u root -e \"flush privileges;\""
|
47
|
+
end
|
48
|
+
end
|
49
|
+
send task_name
|
50
|
+
end
|
51
|
+
|
52
|
+
slave_instances = rubber_instances.for_role("mysql_slave") & rubber_instances.filtered
|
53
|
+
slave_instances.each do |ic|
|
54
|
+
task_name = "_bootstrap_mysql_slave_#{ic.full_name}".to_sym()
|
55
|
+
task task_name, :hosts => ic.full_name do
|
56
|
+
env = rubber_cfg.environment.bind("mysql_slave", ic.name)
|
57
|
+
exists = capture("echo $(ls #{env.db_data_dir}/ 2> /dev/null)")
|
58
|
+
if exists.strip.size == 0
|
59
|
+
common_bootstrap("mysql_slave")
|
60
|
+
sudo "dpkg-reconfigure --frontend=noninteractive mysql-server-5.0"
|
61
|
+
sleep 5
|
62
|
+
|
63
|
+
master = rubber_instances.for_role("mysql_master").first
|
64
|
+
|
65
|
+
# Doing a mysqldump locks the db, so ideally we'd do it against a slave replica thats
|
66
|
+
# not serving traffic (mysql_util role), but if thats not available try a regular
|
67
|
+
# slave (mysql_slave role), and finally default dumping from master (mysql_master role)
|
68
|
+
# TODO: handle simultaneous creating of multi slaves/utils
|
69
|
+
slaves = rubber_instances.for_role("mysql_slave")
|
70
|
+
slaves.delete(ic) # don't want to try and dump from self
|
71
|
+
source = slaves.find {|sc| sc.role_names.include?("mysql_util")}
|
72
|
+
source = slaves.first unless source
|
73
|
+
source = master unless source
|
74
|
+
|
75
|
+
pass = "identified by '#{env.db_pass}'" if env.db_pass
|
76
|
+
master_pass = ", master_password='#{env.db_pass}'" if env.db_pass
|
77
|
+
master_host = master.full_name
|
78
|
+
source_host = source.full_name
|
79
|
+
|
80
|
+
if source == master
|
81
|
+
logger.info "Creating slave from a dump of master #{source_host}"
|
82
|
+
sudo "mysql -u root -e \"change master to master_host='#{master_host}', master_user='#{env.db_replicator_user}' #{master_pass}\""
|
83
|
+
sudo "mysqldump -u #{env.db_user} #{pass} -h #{source_host} --all-databases --master-data=1 | mysql -u root"
|
84
|
+
else
|
85
|
+
logger.info "Creating slave from a dump of slave #{source_host}"
|
86
|
+
sudo "mysql -u #{env.db_user} #{pass} -h #{source_host} -e \"stop slave;\""
|
87
|
+
slave_status = capture("mysql -u #{env.db_user} #{pass} -h #{source_host} -e \"show slave status\\G\"")
|
88
|
+
slave_config = Hash[*slave_status.scan(/([^\s:]+): ([^\s]*)/).flatten]
|
89
|
+
log_file = slave_config['Master_Log_File']
|
90
|
+
log_pos = slave_config['Read_Master_Log_Pos']
|
91
|
+
sudo "mysqldump -u #{env.db_user} #{pass} -h #{source_host} --all-databases --master-data=1 | mysql -u root"
|
92
|
+
sudo "mysql -u root -e \"change master to master_host='#{master_host}', master_user='#{env.db_replicator_user}', master_log_file='#{log_file}', master_log_pos=#{log_pos} #{master_pass}\""
|
93
|
+
sudo "mysql -u #{env.db_user} #{pass} -h #{source_host} -e \"start slave;\""
|
94
|
+
end
|
95
|
+
|
96
|
+
sudo "mysql -u root -e \"flush privileges;\""
|
97
|
+
sudo "mysql -u root -e \"start slave;\""
|
98
|
+
end
|
99
|
+
end
|
100
|
+
send task_name
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
# TODO: Make the setup/update happen just once per host
|
106
|
+
def common_bootstrap(role)
|
107
|
+
# mysql package install starts mysql, so stop it
|
108
|
+
sudo "/etc/init.d/mysql stop" rescue nil
|
109
|
+
|
110
|
+
# After everything installed on machines, we need the source tree
|
111
|
+
# on hosts in order to run rubber:config for bootstrapping the db
|
112
|
+
deploy.setup
|
113
|
+
deploy.update_code
|
114
|
+
|
115
|
+
# Gen just the conf for the given mysql role
|
116
|
+
rubber.run_config(:RUBBER_ENV => RUBBER_ENV, :FILE => "role/#{role}|role/db/my.cnf", :deploy_path => release_path)
|
117
|
+
end
|
118
|
+
|
119
|
+
before "rubber:munin:custom_install", "rubber:mysql:custom_install_munin"
|
120
|
+
|
121
|
+
desc <<-DESC
|
122
|
+
Installs some extra munin graphs
|
123
|
+
DESC
|
124
|
+
task :custom_install_munin, :roles => [:mysql_master, :mysql_slave] do
|
125
|
+
rubber.run_script 'install_munin_mysql', <<-ENDSCRIPT
|
126
|
+
if [ ! -f /usr/share/munin/plugins/mysql_ ]; then
|
127
|
+
wget -q -O /usr/share/munin/plugins/mysql_ http://github.com/kjellm/munin-mysql/raw/master/mysql_
|
128
|
+
wget -q -O /etc/munin/plugin-conf.d/mysql_.conf http://github.com/kjellm/munin-mysql/raw/master/mysql_.conf
|
129
|
+
fi
|
130
|
+
ENDSCRIPT
|
131
|
+
end
|
132
|
+
|
133
|
+
desc <<-DESC
|
134
|
+
Starts the mysql daemons
|
135
|
+
DESC
|
136
|
+
task :start, :roles => [:mysql_master, :mysql_slave] do
|
137
|
+
sudo "/etc/init.d/mysql start"
|
138
|
+
end
|
139
|
+
|
140
|
+
desc <<-DESC
|
141
|
+
Stops the mysql daemons
|
142
|
+
DESC
|
143
|
+
task :stop, :roles => [:mysql_master, :mysql_slave] do
|
144
|
+
sudo "/etc/init.d/mysql stop"
|
145
|
+
end
|
146
|
+
|
147
|
+
desc <<-DESC
|
148
|
+
Restarts the mysql daemons
|
149
|
+
DESC
|
150
|
+
task :restart, :roles => [:mysql_master, :mysql_slave] do
|
151
|
+
sudo "/etc/init.d/mysql restart"
|
152
|
+
end
|
153
|
+
|
154
|
+
end
|
155
|
+
|
156
|
+
end
|