diff --git a/cookbooks/ey-mysql/recipes/install.rb b/cookbooks/ey-mysql/recipes/install.rb index d2791ea..067ef9c 100644 --- a/cookbooks/ey-mysql/recipes/install.rb +++ b/cookbooks/ey-mysql/recipes/install.rb @@ -1,5 +1,5 @@ ey_cloud_report "mysql installation" do - message "installation of mysql packages and dependencies started" + message "Installation of MySQL packages and dependencies started." # AI-GEN - chatgpt end apt_repository "mysql57" do @@ -20,17 +20,29 @@ known_versions = [] install_version = node["mysql"]["latest_version"] - -`apt-cache madison percona-server-server-#{node["mysql"]["short_version"]} |awk '{print $3'} && apt-cache madison percona-server-server |awk '{print $3}'`.split(/\n+/).each { |v| known_versions.append(v.split("-")[0]) } +# AI-GEN START - chatgpt +short_version = node["mysql"]["short_version"] +instance_role = node["dna"]["instance_role"] +# AI-GEN END + +# AI-GEN START - chatgpt +`apt-cache madison percona-server-server-#{short_version} | awk '{print $3}' && apt-cache madison percona-server-server | awk '{print $3}'`.split(/\n+/).each do |v| + known_versions.append(v.split("-")[0]) +end +# AI-GEN END package_version = known_versions.detect { |v| v =~ /^#{install_version}/ } -lock_db_version = node.engineyard.environment.components.find_all { |e| e["key"] == "lock_db_version" }.first["value"] if node.engineyard.environment.lock_db_version? +# AI-GEN START - chatgpt +if node.engineyard.environment.lock_db_version? + lock_db_version = node.engineyard.environment.components.find_all { |e| e["key"] == "lock_db_version" }.first["value"] +end +# AI-GEN END lock_version_file = "/db/.lock_db_version" db_running = `mysql -N -e "select 1;" 2> /dev/null`.strip == "1" -# create or delete /db/.lock_db_version -if node["dna"]["instance_role"][/^(db|solo)/] +# Create or delete /db/.lock_db_version - AI-GEN - chatgpt +if instance_role[/^(db|solo)/] # AI-GEN - chatgpt execute "dropping lock version file" do command "echo $(mysql --version | grep -E -o '(Distrib|Ver) [0-9]+\.[0-9]+\.[0-9]+' | awk '{print $NF}') > #{lock_version_file}" action :run @@ -43,27 +55,53 @@ end end -# install the dependencies of the Percona packages +# AI-GEN START - chatgpt +# Install the dependencies of the Percona packages ["debsums", "libaio1", "libmecab2"].each do |package| - package package + package package do + action :install + end +end +# AI-GEN END + +# AI-GEN START - chatgpt +package "libmysqlclient-dev" do + action :install end +# AI-GEN END -package "libmysqlclient-dev" -# installs mysql client to all instnaces. +# Installs MySQL client to all instances - AI-GEN - chatgpt if node.engineyard.instance.arch_type == "arm64" - package "mysql-client" + # AI-GEN START - chatgpt + package "mysql-client" do + action :install + end + # AI-GEN END else - package "percona-server-client" +# AI-GEN START - cursor + case short_version + when "5.7" + package "percona-server-client-5.7" do + action :install + end + when "8.0" + package "percona-server-client" do + action :install + end + end +# AI-GEN END end -case node["mysql"]["short_version"] -when "5.7" - packages = ["percona-server-common-5.7", "libperconaserverclient20", "percona-server-client-5.7", "percona-server-server-5.7"] -when "8.0" - packages = ["percona-server-common", "libperconaserverclient21", "percona-server-client", "percona-server-server"] -end +# AI-GEN START - chatgpt +packages = case short_version + when "5.7" + ["percona-server-common-5.7", "libperconaserverclient20", "percona-server-server-5.7"] + when "8.0" + ["percona-server-common", "libperconaserverclient21", "percona-server-server"] + end +# AI-GEN END -if node["dna"]["instance_role"][/db|solo/] +if instance_role[/db|solo/] # AI-GEN - chatgpt directory "/etc/systemd/system/mysql.service.d" do owner "root" group "root" @@ -80,43 +118,44 @@ end end -install_version = if ::File.exist?(node["lock_version_file"]) - `cat #{node["lock_version_file"]}`.strip +install_version = if ::File.exist?(lock_version_file) # AI-GEN - chatgpt + `cat #{lock_version_file}`.strip # AI-GEN - chatgpt else node["mysql"]["latest_version"] end + if package_version.nil? && node.engineyard.instance.arch_type == "amd64" - raise "Chef does not know about MySQL version #{install_version} the current known versions of MySQL #{known_versions}. Please use them or contact support for more assistance" + raise "Chef does not know about MySQL version #{install_version}. The current known versions of MySQL are #{known_versions.join(', ')}. Please use them or contact support for more assistance." # AI-GEN - chatgpt end -package_version = `apt-cache madison #{packages.last} |awk '{print $3}' |grep #{install_version}`.split(/\n/).last +package_version = `apt-cache madison #{packages.last} | awk '{print $3}' | grep #{install_version}`.split(/\n/).last # AI-GEN - chatgpt execute "set-deb-confs" do - command %(echo "#{packages.last} #{packages.last}/root-pass password #{node.engineyard.environment['db_admin_password']}" |debconf-set-selections && echo "#{packages.last} #{packages.last}/re-root-pass password #{node.engineyard.environment['db_admin_password']}" |debconf-set-selections) + command %(echo "#{packages.last} #{packages.last}/root-pass password #{node.engineyard.environment['db_admin_password']}" | debconf-set-selections && echo "#{packages.last} #{packages.last}/re-root-pass password #{node.engineyard.environment['db_admin_password']}" | debconf-set-selections) # AI-GEN - chatgpt end -# Loop the packages because chef doesn't understand, you install the dependency before even in the array... -if node["dna"]["instance_role"][/^(db|solo)/] -packages.each do |package| - apt_package package do - version "#{package_version}" - action :install - options ["--yes", "--fix-missing"] - ignore_failure true - only_if { node.engineyard.instance.arch_type == "amd64" } +# Loop through the packages because chef doesn't understand you install the dependency before even in the array... AI-GEN - chatgpt +if instance_role[/^(db|solo)/] # AI-GEN - chatgpt + packages.each do |package| + apt_package package do + version package_version # AI-GEN - chatgpt + action :install + options "--yes --fix-missing" # AI-GEN - chatgpt + ignore_failure true + only_if { node.engineyard.instance.arch_type == "amd64" } + end end end -end ey_cloud_report "mysql installation" do - message "installation of mysql packages and dependencies finished" + message "Installation of MySQL packages and dependencies finished." # AI-GEN - chatgpt end -if node["dna"]["instance_role"][/^(db|solo)/] && node["mysql"]["short_version"] == "8.0" +if instance_role[/^(db|solo)/] && short_version == "8.0" # AI-GEN - chatgpt bash "Set my.cnf alternatives for MySQL 8.0" do code <<-EOS - update-alternatives --install /etc/mysql/my.cnf my.cnf /etc/mysql/percona-server.cnf 1000 - update-alternatives --set my.cnf /etc/mysql/percona-server.cnf - EOS + update-alternatives --install /etc/mysql/my.cnf my.cnf /etc/mysql/percona-server.cnf 1000 + update-alternatives --set my.cnf /etc/mysql/percona-server.cnf + EOS end end