sml-rubber 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +339 -0
- data/README +6 -0
- data/TODO +9 -0
- data/VERSION +1 -0
- data/generators/vulcanize/USAGE +6 -0
- data/generators/vulcanize/templates/apache/config/rubber/deploy-apache.rb +45 -0
- data/generators/vulcanize/templates/apache/config/rubber/role/web/deflate.conf +10 -0
- data/generators/vulcanize/templates/apache/config/rubber/role/web/expires.conf +9 -0
- data/generators/vulcanize/templates/apache/config/rubber/role/web/headers.conf +6 -0
- data/generators/vulcanize/templates/apache/config/rubber/role/web/setenvif.conf +52 -0
- data/generators/vulcanize/templates/apache/config/rubber/role/web/vhost.conf +27 -0
- data/generators/vulcanize/templates/apache/config/rubber/rubber-apache.yml +15 -0
- data/generators/vulcanize/templates/apache/templates.yml +1 -0
- data/generators/vulcanize/templates/base/Capfile +17 -0
- data/generators/vulcanize/templates/base/config/deploy.rb +77 -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 +56 -0
- data/generators/vulcanize/templates/base/config/rubber/rubber.yml +221 -0
- data/generators/vulcanize/templates/base/lib/tasks/rubber.rake +18 -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_mysql/templates.yml +6 -0
- data/generators/vulcanize/templates/complete_passenger_mysql/templates.yml +8 -0
- data/generators/vulcanize/templates/cruise/config/rubber/deploy-cruise.rb +74 -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-default.conf +8 -0
- data/generators/vulcanize/templates/haproxy/config/rubber/role/haproxy/haproxy.conf +44 -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 +12 -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/app/mongrel_cluster.yml +12 -0
- data/generators/vulcanize/templates/mongrel/config/rubber/role/app/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 +30 -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 +178 -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 +38 -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/web/crontab +9 -0
- data/generators/vulcanize/templates/nginx/config/rubber/role/web/monit-nginx.conf +9 -0
- data/generators/vulcanize/templates/nginx/config/rubber/role/web/nginx.conf +133 -0
- data/generators/vulcanize/templates/nginx/config/rubber/role/web_tools/index.html +23 -0
- data/generators/vulcanize/templates/nginx/config/rubber/role/web_tools/nginx-tools.conf +74 -0
- data/generators/vulcanize/templates/nginx/config/rubber/rubber-nginx.yml +33 -0
- data/generators/vulcanize/templates/nginx/templates.yml +1 -0
- data/generators/vulcanize/templates/passenger/config/rubber/deploy-passenger.rb +27 -0
- data/generators/vulcanize/templates/passenger/config/rubber/role/web/passenger.conf +8 -0
- data/generators/vulcanize/templates/passenger/config/rubber/rubber-passenger.yml +4 -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 +37 -0
- data/lib/rubber/capistrano.rb +1 -0
- data/lib/rubber/cloud.rb +13 -0
- data/lib/rubber/cloud/aws.rb +261 -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 +56 -0
- data/lib/rubber/dns/zerigo.rb +121 -0
- data/lib/rubber/environment.rb +161 -0
- data/lib/rubber/generator.rb +197 -0
- data/lib/rubber/instance.rb +113 -0
- data/lib/rubber/recipes/rubber.rb +88 -0
- data/lib/rubber/recipes/rubber/bundles.rb +28 -0
- data/lib/rubber/recipes/rubber/deploy.rb +66 -0
- data/lib/rubber/recipes/rubber/instances.rb +298 -0
- data/lib/rubber/recipes/rubber/security_groups.rb +149 -0
- data/lib/rubber/recipes/rubber/setup.rb +285 -0
- data/lib/rubber/recipes/rubber/static_ips.rb +107 -0
- data/lib/rubber/recipes/rubber/utils.rb +195 -0
- data/lib/rubber/recipes/rubber/volumes.rb +263 -0
- data/lib/rubber/tasks/rubber.rb +218 -0
- data/lib/rubber/util.rb +33 -0
- data/test/environment_test.rb +118 -0
- data/test/generator_test.rb +323 -0
- data/test/instance_test.rb +38 -0
- data/test/test_helper.rb +4 -0
- data/test/util_test.rb +16 -0
- metadata +246 -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,30 @@
|
|
1
|
+
|
2
|
+
namespace :rubber do
|
3
|
+
|
4
|
+
namespace :munin do
|
5
|
+
|
6
|
+
rubber.allow_optional_tasks(self)
|
7
|
+
|
8
|
+
# after "deploy:stop", "rubber:munin:stop"
|
9
|
+
# before "deploy:start", "rubber:munin:start"
|
10
|
+
# after "deploy:restart", "rubber:munin:restart"
|
11
|
+
|
12
|
+
desc "Start munin system monitoring"
|
13
|
+
task :start do
|
14
|
+
run "/etc/init.d/munin-node start"
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "Stop munin system monitoring"
|
18
|
+
task :stop, :on_error => :continue do
|
19
|
+
run "/etc/init.d/munin-node stop"
|
20
|
+
end
|
21
|
+
|
22
|
+
desc "Restart munin system monitoring"
|
23
|
+
task :restart do
|
24
|
+
stop
|
25
|
+
start
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
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,178 @@
|
|
1
|
+
|
2
|
+
namespace :rubber do
|
3
|
+
|
4
|
+
namespace :mysql do
|
5
|
+
|
6
|
+
rubber.allow_optional_tasks(self)
|
7
|
+
|
8
|
+
after "rubber:create", "rubber:mysql:set_db_role"
|
9
|
+
|
10
|
+
# Capistrano needs db:primary role for migrate to work
|
11
|
+
task :set_db_role do
|
12
|
+
db_instances = rubber_cfg.instance.for_role("mysql_master")
|
13
|
+
db_instances.each do |instance|
|
14
|
+
if ! instance.role_names.find {|n| n == 'db'}
|
15
|
+
role = Rubber::Configuration::RoleItem.new('db')
|
16
|
+
primary_exists = rubber_cfg.instance.for_role("db", "primary" => true).size > 0
|
17
|
+
role.options["primary"] = true unless primary_exists
|
18
|
+
instance.roles << role
|
19
|
+
end
|
20
|
+
end
|
21
|
+
db_instances = rubber_cfg.instance.for_role("mysql_slave")
|
22
|
+
db_instances.each do |instance|
|
23
|
+
if instance.role_names.find {|n| n == 'mysql_master'}
|
24
|
+
logger.info "Cannot have a mysql slave and master on the same instance, removing slave role"
|
25
|
+
instance.roles.delete_if {|r| r.name == 'mysql_slave'}
|
26
|
+
next
|
27
|
+
end
|
28
|
+
if ! instance.role_names.find {|n| n == 'db'}
|
29
|
+
role = Rubber::Configuration::RoleItem.new('db')
|
30
|
+
instance.roles << role
|
31
|
+
end
|
32
|
+
end
|
33
|
+
rubber_cfg.instance.save()
|
34
|
+
load_roles() unless rubber_cfg.environment.bind().disable_auto_roles
|
35
|
+
end
|
36
|
+
|
37
|
+
after "rubber:bootstrap", "rubber:mysql:bootstrap"
|
38
|
+
|
39
|
+
|
40
|
+
# Bootstrap the production database config. Db bootstrap is special - the
|
41
|
+
# user could be requiring the rails env inside some of their config
|
42
|
+
# templates, which creates a catch 22 situation with the db, so we try and
|
43
|
+
# bootstrap the db separate from the rest of the config
|
44
|
+
task :bootstrap, :roles => [:mysql_master, :mysql_slave] do
|
45
|
+
|
46
|
+
# Conditionaly bootstrap for each node/role only if that node has not
|
47
|
+
# been boostrapped for that role before
|
48
|
+
|
49
|
+
master_instances = rubber_cfg.instance.for_role("mysql_master") & rubber_cfg.instance.filtered
|
50
|
+
master_instances.each do |ic|
|
51
|
+
task_name = "_bootstrap_mysql_master_#{ic.full_name}".to_sym()
|
52
|
+
task task_name, :hosts => ic.full_name do
|
53
|
+
env = rubber_cfg.environment.bind("mysql_master", ic.name)
|
54
|
+
exists = capture("echo $(ls #{env.db_data_dir}/ 2> /dev/null)")
|
55
|
+
if exists.strip.size == 0
|
56
|
+
common_bootstrap("mysql_master")
|
57
|
+
sudo "dpkg-reconfigure --frontend=noninteractive mysql-server-5.0"
|
58
|
+
sleep 5
|
59
|
+
pass = "identified by '#{env.db_pass}'" if env.db_pass
|
60
|
+
sudo "mysql -u root -e 'create database #{env.db_name};'"
|
61
|
+
sudo "mysql -u root -e \"grant all on *.* to '#{env.db_user}'@'%' #{pass};\""
|
62
|
+
sudo "mysql -u root -e \"grant select on *.* to '#{env.db_slave_user}'@'%' #{pass};\""
|
63
|
+
sudo "mysql -u root -e \"grant replication slave on *.* to '#{env.db_replicator_user}'@'%' #{pass};\""
|
64
|
+
sudo "mysql -u root -e \"flush privileges;\""
|
65
|
+
end
|
66
|
+
end
|
67
|
+
send task_name
|
68
|
+
end
|
69
|
+
|
70
|
+
slave_instances = rubber_cfg.instance.for_role("mysql_slave") & rubber_cfg.instance.filtered
|
71
|
+
slave_instances.each do |ic|
|
72
|
+
task_name = "_bootstrap_mysql_slave_#{ic.full_name}".to_sym()
|
73
|
+
task task_name, :hosts => ic.full_name do
|
74
|
+
env = rubber_cfg.environment.bind("mysql_slave", ic.name)
|
75
|
+
exists = capture("echo $(ls #{env.db_data_dir}/ 2> /dev/null)")
|
76
|
+
if exists.strip.size == 0
|
77
|
+
common_bootstrap("mysql_slave")
|
78
|
+
sudo "dpkg-reconfigure --frontend=noninteractive mysql-server-5.0"
|
79
|
+
sleep 5
|
80
|
+
|
81
|
+
master = rubber_cfg.instance.for_role("mysql_master").first
|
82
|
+
|
83
|
+
# Doing a mysqldump locks the db, so ideally we'd do it against a slave replica thats
|
84
|
+
# not serving traffic (mysql_util role), but if thats not available try a regular
|
85
|
+
# slave (mysql_slave role), and finally default dumping from master (mysql_master role)
|
86
|
+
# TODO: handle simultaneous creating of multi slaves/utils
|
87
|
+
slaves = rubber_cfg.instance.for_role("mysql_slave")
|
88
|
+
slaves.delete(ic) # don't want to try and dump from self
|
89
|
+
source = slaves.find {|sc| sc.role_names.include?("mysql_util")}
|
90
|
+
source = slaves.first unless source
|
91
|
+
source = master unless source
|
92
|
+
|
93
|
+
pass = "identified by '#{env.db_pass}'" if env.db_pass
|
94
|
+
master_pass = ", master_password='#{env.db_pass}'" if env.db_pass
|
95
|
+
master_host = master.full_name
|
96
|
+
source_host = source.full_name
|
97
|
+
|
98
|
+
if source == master
|
99
|
+
logger.info "Creating slave from a dump of master #{source_host}"
|
100
|
+
sudo "mysql -u root -e \"change master to master_host='#{master_host}', master_user='#{env.db_replicator_user}' #{master_pass}\""
|
101
|
+
sudo "mysqldump -u #{env.db_user} #{pass} -h #{source_host} --all-databases --master-data=1 | mysql -u root"
|
102
|
+
else
|
103
|
+
logger.info "Creating slave from a dump of slave #{source_host}"
|
104
|
+
sudo "mysql -u #{env.db_user} #{pass} -h #{source_host} -e \"stop slave;\""
|
105
|
+
slave_status = capture("mysql -u #{env.db_user} #{pass} -h #{source_host} -e \"show slave status\\G\"")
|
106
|
+
slave_config = Hash[*slave_status.scan(/([^\s:]+): ([^\s]*)/).flatten]
|
107
|
+
log_file = slave_config['Master_Log_File']
|
108
|
+
log_pos = slave_config['Read_Master_Log_Pos']
|
109
|
+
sudo "mysqldump -u #{env.db_user} #{pass} -h #{source_host} --all-databases --master-data=1 | mysql -u root"
|
110
|
+
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}\""
|
111
|
+
sudo "mysql -u #{env.db_user} #{pass} -h #{source_host} -e \"start slave;\""
|
112
|
+
end
|
113
|
+
|
114
|
+
sudo "mysql -u root -e \"flush privileges;\""
|
115
|
+
sudo "mysql -u root -e \"start slave;\""
|
116
|
+
end
|
117
|
+
end
|
118
|
+
send task_name
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
# TODO: Make the setup/update happen just once per host
|
124
|
+
def common_bootstrap(role)
|
125
|
+
# mysql package install starts mysql, so stop it
|
126
|
+
sudo "/etc/init.d/mysql stop" rescue nil
|
127
|
+
|
128
|
+
# After everything installed on machines, we need the source tree
|
129
|
+
# on hosts in order to run rubber:config for bootstrapping the db
|
130
|
+
deploy.setup
|
131
|
+
deploy.update_code
|
132
|
+
|
133
|
+
# Gen just the conf for the given mysql role
|
134
|
+
rubber.run_config(:RUBBER_ENV => rails_env, :FILE => "role/#{role}|role/db/my.cnf", :deploy_path => release_path)
|
135
|
+
end
|
136
|
+
|
137
|
+
after "rubber:install_packages", "rubber:mysql:custom_install"
|
138
|
+
|
139
|
+
desc <<-DESC
|
140
|
+
Installs some extra munin graphs
|
141
|
+
DESC
|
142
|
+
task :custom_install, :roles => [:mysql_master, :mysql_slave] do
|
143
|
+
rubber.run_script 'install_munin_mysql', <<-ENDSCRIPT
|
144
|
+
if [ ! -f /etc/munin/plugins/mysql_ ]; then
|
145
|
+
wget -q -O /etc/munin/plugins/mysql_ http://github.com/kjellm/munin-mysql/raw/master/mysql_
|
146
|
+
wget -q -O /etc/munin/plugin-conf.d/mysql_.conf http://github.com/kjellm/munin-mysql/raw/master/mysql_.conf
|
147
|
+
|
148
|
+
cd /etc/munin/plugins
|
149
|
+
chmod +x mysql_
|
150
|
+
./mysql_ suggest | while read x; do ln -sf mysql_ $x; done
|
151
|
+
fi
|
152
|
+
ENDSCRIPT
|
153
|
+
end
|
154
|
+
|
155
|
+
desc <<-DESC
|
156
|
+
Starts the mysql daemons
|
157
|
+
DESC
|
158
|
+
task :start, :roles => [:mysql_master, :mysql_slave] do
|
159
|
+
sudo "/etc/init.d/mysql start"
|
160
|
+
end
|
161
|
+
|
162
|
+
desc <<-DESC
|
163
|
+
Stops the mysql daemons
|
164
|
+
DESC
|
165
|
+
task :stop, :roles => [:mysql_master, :mysql_slave] do
|
166
|
+
sudo "/etc/init.d/mysql stop"
|
167
|
+
end
|
168
|
+
|
169
|
+
desc <<-DESC
|
170
|
+
Restarts the mysql daemons
|
171
|
+
DESC
|
172
|
+
task :restart, :roles => [:mysql_master, :mysql_slave] do
|
173
|
+
sudo "/etc/init.d/mysql restart"
|
174
|
+
end
|
175
|
+
|
176
|
+
end
|
177
|
+
|
178
|
+
end
|