<commit_before>#
# Cookbook Name:: percona
# Recipe:: configure_server
#

percona = node["percona"]
server  = percona["server"]
conf    = percona["conf"]
mysqld  = (conf && conf["mysqld"]) || {}

# setup SELinux if needed
semodule_filename = node["percona"]["selinux_module_url"].split("/")[-1]
semodule_filepath = "#{Chef::Config[:file_cache_path]}/#{semodule_filename}"
remote_file semodule_filepath do
  source node["percona"]["selinux_module_url"]
  only_if { semodule_filename && node["platform_family"] == "rhel" }
end

execute "semodule-install-#{semodule_filename}" do
  command "/usr/sbin/semodule -i #{semodule_filepath}"
  only_if { semodule_filename && node["platform_family"] == "rhel" }
  only_if { shell_out("/usr/sbin/semodule -l | grep '^#{semodule_filename.split(".")[0..-2]}\\s'").stdout == "" } # rubocop:disable LineLength
end

# install chef-vault if needed
include_recipe "chef-vault" if node["percona"]["use_chef_vault"]

# construct an encrypted passwords helper -- giving it the node and bag name
passwords = EncryptedPasswords.new(node, percona["encrypted_data_bag"])

if node["percona"]["server"]["jemalloc"]
  package_name = value_for_platform_family(
    "debian" => "libjemalloc1",
    "rhel" => "jemalloc"
  )

  package package_name
end

template "/root/.my.cnf" do
  variables(root_password: <PASSWORD>)
  owner "root"
  group "root"
  mode "0600"
  source "my.cnf.root.erb"
  sensitive true<commit_msg>fix selinux cfg, replacing nil by empty string<commit_after>#
# Cookbook Name:: percona
# Recipe:: configure_server
#

percona = node["percona"]
server  = percona["server"]
conf    = percona["conf"]
mysqld  = (conf && conf["mysqld"]) || {}

# setup SELinux if needed
unless node["percona"]["selinux_module_url"].nil? || node["percona"]["selinux_module_url"] == ""
  semodule_filename = node["percona"]["selinux_module_url"].split("/")[-1]
  semodule_filepath = "#{Chef::Config[:file_cache_path]}/#{semodule_filename}"
  remote_file semodule_filepath do
    source node["percona"]["selinux_module_url"]
    only_if { semodule_filename && node["platform_family"] == "rhel" }
  end

  execute "semodule-install-#{semodule_filename}" do
    command "/usr/sbin/semodule -i #{semodule_filepath}"
    only_if { semodule_filename && node["platform_family"] == "rhel" }
    only_if { shell_out("/usr/sbin/semodule -l | grep '^#{semodule_filename.split(".")[0..-2]}\\s'").stdout == "" } # rubocop:disable LineLength
  end
end

# install chef-vault if needed
include_recipe "chef-vault" if node["percona"]["use_chef_vault"]

# construct an encrypted passwords helper -- giving it the node and bag name
passwords = EncryptedPasswords.new(node, percona["encrypted_data_bag"])

if node["percona"]["server"]["jemalloc"]
  package_name = value_for_platform_family(
    "debian" => "libjemalloc1",
    "rhel" => "jemalloc"
  )

  package package_name
end

template "/root/.my.cnf" do
  variables(root_password: <PASSWORD>)
  owner "root"
  group "root"
  mode "0600"
  source "my.cnf.root.erb"
  sensitive true
{'fraction_non_alphanumeric': 0.16204620462046204, 'fraction_numerical': 0.005280528052805281, 'mean_word_length': 5.394514767932489, 'pattern_counts': {'":': 0, '<': 5, '<?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': '6616835', 'n_tokens_mistral': 1091, 'n_tokens_neox': 1093, 'n_words': 212}