generators/vulcanize/templates/mysql/config/rubber/deploy-mysql.rb in sml-rubber-0.9.9 vs generators/vulcanize/templates/mysql/config/rubber/deploy-mysql.rb in sml-rubber-0.9.10

- old
+ new

@@ -3,39 +3,21 @@ namespace :mysql do rubber.allow_optional_tasks(self) - after "rubber:create", "rubber:mysql:set_db_role" - - # Capistrano needs db:primary role for migrate to work - task :set_db_role do - db_instances = rubber_cfg.instance.for_role("mysql_master") + after "rubber:create", "rubber:mysql:validate_db_roles" + + task :validate_db_roles do + db_instances = rubber_instances.for_role("mysql_slave") db_instances.each do |instance| - if ! instance.role_names.find {|n| n == 'db'} - role = Rubber::Configuration::RoleItem.new('db') - primary_exists = rubber_cfg.instance.for_role("db", "primary" => true).size > 0 - role.options["primary"] = true unless primary_exists - instance.roles << role - end - end - db_instances = rubber_cfg.instance.for_role("mysql_slave") - db_instances.each do |instance| if instance.role_names.find {|n| n == 'mysql_master'} - logger.info "Cannot have a mysql slave and master on the same instance, removing slave role" - instance.roles.delete_if {|r| r.name == 'mysql_slave'} - next + fatal "Cannot have a mysql slave and master on the same instance, please removing slave role for #{instance.name}" end - if ! instance.role_names.find {|n| n == 'db'} - role = Rubber::Configuration::RoleItem.new('db') - instance.roles << role - end end - rubber_cfg.instance.save() - load_roles() unless rubber_cfg.environment.bind().disable_auto_roles end - + after "rubber:bootstrap", "rubber:mysql:bootstrap" # Bootstrap the production database config. Db bootstrap is special - the # user could be requiring the rails env inside some of their config @@ -44,11 +26,11 @@ task :bootstrap, :roles => [:mysql_master, :mysql_slave] do # Conditionaly bootstrap for each node/role only if that node has not # been boostrapped for that role before - master_instances = rubber_cfg.instance.for_role("mysql_master") & rubber_cfg.instance.filtered + master_instances = rubber_instances.for_role("mysql_master") & rubber_instances.filtered master_instances.each do |ic| task_name = "_bootstrap_mysql_master_#{ic.full_name}".to_sym() task task_name, :hosts => ic.full_name do env = rubber_cfg.environment.bind("mysql_master", ic.name) exists = capture("echo $(ls #{env.db_data_dir}/ 2> /dev/null)") @@ -65,28 +47,28 @@ end end send task_name end - slave_instances = rubber_cfg.instance.for_role("mysql_slave") & rubber_cfg.instance.filtered + slave_instances = rubber_instances.for_role("mysql_slave") & rubber_instances.filtered slave_instances.each do |ic| task_name = "_bootstrap_mysql_slave_#{ic.full_name}".to_sym() task task_name, :hosts => ic.full_name do env = rubber_cfg.environment.bind("mysql_slave", ic.name) exists = capture("echo $(ls #{env.db_data_dir}/ 2> /dev/null)") if exists.strip.size == 0 common_bootstrap("mysql_slave") sudo "dpkg-reconfigure --frontend=noninteractive mysql-server-5.0" sleep 5 - master = rubber_cfg.instance.for_role("mysql_master").first + master = rubber_instances.for_role("mysql_master").first # Doing a mysqldump locks the db, so ideally we'd do it against a slave replica thats # not serving traffic (mysql_util role), but if thats not available try a regular # slave (mysql_slave role), and finally default dumping from master (mysql_master role) # TODO: handle simultaneous creating of multi slaves/utils - slaves = rubber_cfg.instance.for_role("mysql_slave") + slaves = rubber_instances.for_role("mysql_slave") slaves.delete(ic) # don't want to try and dump from self source = slaves.find {|sc| sc.role_names.include?("mysql_util")} source = slaves.first unless source source = master unless source @@ -132,23 +114,19 @@ # Gen just the conf for the given mysql role rubber.run_config(:RUBBER_ENV => RUBBER_ENV, :FILE => "role/#{role}|role/db/my.cnf", :deploy_path => release_path) end - after "rubber:install_packages", "rubber:mysql:custom_install" + before "rubber:munin:custom_install", "rubber:mysql:custom_install_munin" desc <<-DESC Installs some extra munin graphs DESC - task :custom_install, :roles => [:mysql_master, :mysql_slave] do + task :custom_install_munin, :roles => [:mysql_master, :mysql_slave] do rubber.run_script 'install_munin_mysql', <<-ENDSCRIPT - if [ ! -f /etc/munin/plugins/mysql_ ]; then - wget -q -O /etc/munin/plugins/mysql_ http://github.com/kjellm/munin-mysql/raw/master/mysql_ + if [ ! -f /usr/share/munin/plugins/mysql_ ]; then + wget -q -O /usr/share/munin/plugins/mysql_ http://github.com/kjellm/munin-mysql/raw/master/mysql_ wget -q -O /etc/munin/plugin-conf.d/mysql_.conf http://github.com/kjellm/munin-mysql/raw/master/mysql_.conf - - cd /etc/munin/plugins - chmod +x mysql_ - ./mysql_ suggest | while read x; do ln -sf mysql_ $x; done fi ENDSCRIPT end desc <<-DESC