<commit_before>#
# Cookbook Name:: cubrid
# Recipes:: ha
#
# Copyright 2012, <NAME> <<EMAIL>>
#
# Distributed under MIT license
#

require 'chef/util/file_edit'

include_recipe "cubrid"

if !node['cubrid']['ha_hosts'].empty?
	CUBRID_CONF = "#{node['cubrid']['conf']}"
	HA_CONF = "#{node['cubrid']['ha_conf']}"
	DATABASES_TXT = "#{node['cubrid']['databases_dir']}/databases.txt"

	# create HA databases
	node['cubrid']['ha_db_list'].each do |db|
		cubrid_database db do
			action :create
			autostart false
		end

		ruby_block "add hosts to databases.txt for #{db} database" do
      block do
        databases_txt = Chef::Util::FileEdit.new("#{DATABASES_TXT}")
				databases_txt.search_file_replace(/#{db}[\t\s]+localhost/, "#{db}	#{node['cubrid']['ha_hosts_list']}")
				databases_txt.write_file
      end
      only_if "egrep '#{db}[\t\s]+localhost' #{DATABASES_TXT}"
    end
	end

	node['cubrid']['ha_hosts'].each do |host, ip|
		execute "sudo sed -i '$a #{ip} #{host}' /etc/hosts" do
			not_if "egrep '\b#{host}\b' /etc/hosts"
		end
	end

	# update cubrid_ha.conf
	template HA_CONF do
	  source "cubrid_ha.conf.erb"
	  user "vagrant"
	  not_if "cat #{HA_CONF} | grep 'Cookbook Name:: cubrid'"
	end

	# update cubrid.conf
	template CUBRID_CONF do
	  source "cubrid.conf.erb"
	  user "vagrant"
	  not_if "cat #{CUBRID_CONF} | grep 'Cookbook Name:: cubrid'"
	end

	# restart cubrid service<commit_msg>Fix: remove "sudo" as it breaks on CentOS.<commit_after>#
# Cookbook Name:: cubrid
# Recipes:: ha
#
# Copyright 2012, <NAME> <<EMAIL>>
#
# Distributed under MIT license
#

require 'chef/util/file_edit'

include_recipe "cubrid"

if !node['cubrid']['ha_hosts'].empty?
	CUBRID_CONF = "#{node['cubrid']['conf']}"
	HA_CONF = "#{node['cubrid']['ha_conf']}"
	DATABASES_TXT = "#{node['cubrid']['databases_dir']}/databases.txt"

	# create HA databases
	node['cubrid']['ha_db_list'].each do |db|
		cubrid_database db do
			action :create
			autostart false
		end

		ruby_block "add hosts to databases.txt for #{db} database" do
      block do
        databases_txt = Chef::Util::FileEdit.new("#{DATABASES_TXT}")
				databases_txt.search_file_replace(/#{db}[\t\s]+localhost/, "#{db}	#{node['cubrid']['ha_hosts_list']}")
				databases_txt.write_file
      end
      only_if "egrep '#{db}[\t\s]+localhost' #{DATABASES_TXT}"
    end
	end

	# Add host and IP information to /etc/hosts file.
	node['cubrid']['ha_hosts'].each do |host, ip|
		execute "sed -i '$a #{ip} #{host}' /etc/hosts" do
			not_if "egrep '\b#{host}\b' /etc/hosts"
		end
	end

	# update cubrid_ha.conf
	template HA_CONF do
	  source "cubrid_ha.conf.erb"
	  user "vagrant"
	  not_if "cat #{HA_CONF} | grep 'Cookbook Name:: cubrid'"
	end

	# update cubrid.conf
	template CUBRID_CONF do
	  source "cubrid.conf.erb"
	  user "vagrant"
	  not_if "cat #{CUBRID_CONF} | grep 'Cookbook Name:: cubrid'"
	end

	# restart cubrid service
{'fraction_non_alphanumeric': 0.16602987148315387, 'fraction_numerical': 0.0027787426189649182, 'mean_word_length': 4.226860254083484, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2302048', 'n_tokens_mistral': 1215, 'n_tokens_neox': 1117, 'n_words': 253}