Skip to content

Commit

Permalink
cleanup crosscutting templates (monit, munin, collectd) to be self co…
Browse files Browse the repository at this point in the history
…ntained
  • Loading branch information
Matt Conway committed Jan 20, 2012
1 parent ab42c82 commit 46993e2
Show file tree
Hide file tree
Showing 38 changed files with 53 additions and 20 deletions.
26 changes: 26 additions & 0 deletions lib/rubber/commands/vulcanize.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,22 @@ def vulcanize(template_names)

protected

def project_roles
return @project_roles if @project_roles

@project_roles = Dir["#{destination_root}/config/rubber/role/*"].collect {|f| File.basename(f) }
@template_dependencies.each do |name|
template_dir = File.join(self.class.source_root, name, '')
Dir["#{template_dir}/config/rubber/rubber*.yml"].each do |yml|
rubber_yml = YAML.load(File.read(yml)) rescue {}
@project_roles.concat(rubber_yml['roles'].keys) rescue nil
@project_roles.concat(rubber_yml['role_dependencies'].keys) rescue nil
@project_roles.concat(rubber_yml['role_dependencies'].values) rescue nil
end
end
@project_roles = @project_roles.flatten.uniq
end

def find_dependencies(name)
template_dir = File.join(self.class.source_root, name, '')
unless File.directory?(template_dir)
Expand Down Expand Up @@ -124,6 +140,16 @@ def apply_template(name)
source_rel = f.gsub(/#{self.class.source_root}\//, '')
dest_rel = source_rel.gsub(/^#{name}\//, '')

if template_conf['skip_unknown_roles']
if f =~ /config\/rubber\/role\/([^\/]*)/
role = $1
if ! project_roles.include?(role)
say_status :skipping, dest_rel, :yellow
Find.prune
end
end
end

# Only include optional files when their conditions eval to true
optional = template_conf['optional'][template_rel] rescue nil
Find.prune if optional && ! eval(optional)
Expand Down
1 change: 1 addition & 0 deletions templates/collectd/templates.yml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
description: The collectd monitoring module
skip_unknown_roles: true
6 changes: 3 additions & 3 deletions templates/monit/config/rubber/deploy-monit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
after "rubber:post_restart", "rubber:monit:start"

desc "Start monit daemon monitoring"
task :start do
task :start, :roles => :monit do
rsudo "service monit start"
end

desc "Stop monit daemon monitoring"
task :stop do
task :stop, :roles => :monit do
rsudo "service monit stop; exit 0"
end

desc "Restart monit daemon monitoring"
task :restart do
task :restart, :roles => :monit do
stop
start
end
Expand Down
7 changes: 6 additions & 1 deletion templates/monit/config/rubber/rubber-monit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@

monit_admin_port: 2812

packages: [monit]
role_dependencies:
common: [monit]

roles:
monit:
packages: [monit]

1 change: 1 addition & 0 deletions templates/monit/templates.yml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
description: The monit module
skip_unknown_roles: true
8 changes: 4 additions & 4 deletions templates/munin/config/rubber/deploy-munin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
desc <<-DESC
Reconfigures munin
DESC
task :install do
task :install, :roles => [:munin] do
rubber.sudo_script 'setup_munin_plugins', <<-ENDSCRIPT
munin-node-configure --shell --remove-also > /tmp/setup-munin-plugins 2> /dev/null || true
sh /tmp/setup-munin-plugins
Expand Down Expand Up @@ -61,17 +61,17 @@
# after "deploy:restart", "rubber:munin:restart"

desc "Start munin system monitoring"
task :start do
task :start, :roles => :munin do
rsudo "service munin-node start"
end

desc "Stop munin system monitoring"
task :stop do
task :stop, :roles => :munin do
rsudo "service munin-node stop; exit 0"
end

desc "Restart munin system monitoring"
task :restart do
task :restart, :roles => :munin do
stop
start
end
Expand Down
5 changes: 4 additions & 1 deletion templates/munin/config/rubber/rubber-munin.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# Uses admin_email from base

packages: [munin-node, munin-plugins-extra, heirloom-mailx]
role_dependencies:
common: [munin]

roles:
munin:
packages: [munin-node, munin-plugins-extra, heirloom-mailx]
web_tools:
packages: [munin]
mysql:
Expand Down
1 change: 1 addition & 0 deletions templates/munin/templates.yml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
description: The munin module
skip_unknown_roles: true

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ db_restore_cmd: "zcat - | mysql -h %host% -u %user% --password=%pass% %name%"
#
db_data_dir: /mnt/mysql_cluster_data

role_dependencies:
mysql_sql: [mysql]

packages: [mysql-client, libmysql-ruby]


Expand Down
3 changes: 3 additions & 0 deletions templates/mysql_proxy/config/rubber/rubber-mysql_proxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@
# or 'mysql_master' for just master
mysql_proxy_role: mysql_sql

role_dependencies:
common: [mysql_proxy]

packages: [mysql-proxy]
2 changes: 1 addition & 1 deletion templates/resque/config/rubber/deploy-resque.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
end

# pauses deploy until all workers up so monit doesn't try and start them
before "rubber:monit:start", "rubber:resque:worker:wait_start"
before "rubber:post_start", "rubber:resque:worker:wait_start"
task :wait_start, :roles => :resque_worker do
logger.info "Waiting for resque worker pid files to show up"

Expand Down

0 comments on commit 46993e2

Please sign in to comment.