From 962d50996f4ba0815aa0b1fa53fa7a8c5a351566 Mon Sep 17 00:00:00 2001 From: Dan Webb Date: Thu, 2 May 2024 10:36:04 +0100 Subject: [PATCH 01/16] chore: Update platforms Signed-off-by: Dan Webb --- .envrc | 1 + .github/workflows/ci.yml | 2 - kitchen.dokken.yml | 29 +------------- kitchen.global.yml | 6 +-- kitchen.yml | 83 +--------------------------------------- 5 files changed, 6 insertions(+), 115 deletions(-) diff --git a/.envrc b/.envrc index 6ed589ea8..484ad2666 100644 --- a/.envrc +++ b/.envrc @@ -1 +1,2 @@ use chefworkstation +export KITCHEN_GLOBAL_YAML=kitchen.global.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 05cc49d2e..727b71b28 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,10 +24,8 @@ jobs: matrix: os: - "almalinux-8" - - "centos-7" - "centos-stream-8" - "rockylinux-8" - - "ubuntu-1804" - "ubuntu-2004" - "ubuntu-2204" suite: diff --git a/kitchen.dokken.yml b/kitchen.dokken.yml index 47eff95d8..1dfe62c8f 100644 --- a/kitchen.dokken.yml +++ b/kitchen.dokken.yml @@ -22,11 +22,6 @@ platforms: image: dokken/amazonlinux-2023 pid_one_command: /usr/lib/systemd/systemd - - name: centos-7 - driver: - image: dokken/centos-7 - pid_one_command: /usr/lib/systemd/systemd - - name: centos-stream-8 driver: image: dokken/centos-stream-8 @@ -37,16 +32,6 @@ platforms: image: dokken/centos-stream-9 pid_one_command: /usr/lib/systemd/systemd - - name: debian-9 - driver: - image: dokken/debian-9 - pid_one_command: /bin/systemd - - - name: debian-10 - driver: - image: dokken/debian-10 - pid_one_command: /bin/systemd - - name: debian-11 driver: image: dokken/debian-11 @@ -67,11 +52,6 @@ platforms: image: dokken/opensuse-leap-15 pid_one_command: /usr/lib/systemd/systemd - - name: oraclelinux-7 - driver: - image: dokken/oraclelinux-7 - pid_one_command: /usr/lib/systemd/systemd - - name: oraclelinux-8 driver: image: dokken/oraclelinux-8 @@ -92,11 +72,6 @@ platforms: image: dokken/rockylinux-9 pid_one_command: /usr/lib/systemd/systemd - - name: ubuntu-18.04 - driver: - image: dokken/ubuntu-18.04 - pid_one_command: /bin/systemd - - name: ubuntu-20.04 driver: image: dokken/ubuntu-20.04 @@ -107,7 +82,7 @@ platforms: image: dokken/ubuntu-22.04 pid_one_command: /bin/systemd - - name: ubuntu-23.04 + - name: ubuntu-24.04 driver: - image: dokken/ubuntu-23.04 + image: dokken/ubuntu-24.04 pid_one_command: /bin/systemd diff --git a/kitchen.global.yml b/kitchen.global.yml index a382fcd0d..3967ff51e 100644 --- a/kitchen.global.yml +++ b/kitchen.global.yml @@ -18,16 +18,12 @@ platforms: - name: almalinux-8 - name: almalinux-9 - name: amazonlinux-2023 - - name: centos-7 - name: centos-stream-8 - name: centos-stream-9 - - name: debian-9 - - name: debian-10 - name: debian-11 - name: debian-12 - name: fedora-latest - name: opensuse-leap-15 - - name: oraclelinux-7 - name: oraclelinux-8 - name: oraclelinux-9 - name: rockylinux-8 @@ -35,4 +31,4 @@ platforms: - name: ubuntu-18.04 - name: ubuntu-20.04 - name: ubuntu-22.04 - - name: ubuntu-23.04 + - name: ubuntu-24.04 diff --git a/kitchen.yml b/kitchen.yml index 7c3440ad6..7522e99ca 100644 --- a/kitchen.yml +++ b/kitchen.yml @@ -1,9 +1,7 @@ <% -yum_dists_with_56 = %w(centos-7 amazon-linux-2) -suse_dists_with_56 = %w(opensuse-leap-15) -yum_dists_with_57 = %w(centos-7 fedora-latest) +yum_dists_with_57 = %w(fedora-latest) apt_dists_with_57 = %w(ubuntu-18.04) -yum_dists_with_80 = %w(centos-7 centos-stream-8 almalinux-8 rockylinux-8 fedora-latest) +yum_dists_with_80 = %w(centos-stream-8 almalinux-8 rockylinux-8 fedora-latest) apt_dists_with_80 = %w(ubuntu-20.04) %> --- @@ -12,49 +10,10 @@ driver: customize: memory: 1024 -provisioner: - name: chef_zero - deprecations_as_errors: true - -verifier: - name: inspec - -platforms: - - name: almalinux-8 - - name: amazonlinux-2 - - name: centos-7 - - name: centos-stream-8 - - name: debian-10 - - name: debian-11 - - name: fedora-latest - - name: opensuse-leap-15 - - name: rockylinux-8 - - name: ubuntu-18.04 - - name: ubuntu-20.04 - suites: # # client # - - name: yum-client-install-56 - run_list: - - recipe[selinux::disabled] - - recipe[test::yum_repo] - - recipe[test::installation_client] - attributes: - mysql_test: - version: '5.6' - includes: <%= yum_dists_with_56 %> - - - name: suse-client-install-56 - run_list: - - recipe[test::yum_repo] - - recipe[test::installation_client] - attributes: - mysql_test: - version: '5.6' - includes: <%= suse_dists_with_56 %> - - name: client-install-57 run_list: - recipe[test::installation_client] @@ -94,19 +53,6 @@ suites: # # server smoke # - - name: yum-smoke56 - run_list: - - recipe[selinux::disabled] - - recipe[test::yum_repo] - - recipe[test::smoke] - attributes: - mysql_test: - version: '5.6' - includes: <%= yum_dists_with_56 %> - verifier: - inspec_tests: - - path: test/integration/smoke56 - - name: smoke57 run_list: - recipe[test::smoke] @@ -115,15 +61,6 @@ suites: version: '5.7' includes: <%= apt_dists_with_57 %> - - name: suse-smoke56 - run_list: - - recipe[test::yum_repo] - - recipe[test::smoke] - attributes: - mysql_test: - version: '5.6' - includes: <%= suse_dists_with_56 %> - - name: yum-smoke57 run_list: - recipe[selinux::disabled] @@ -158,22 +95,6 @@ suites: # # resource tests # - - name: resources-56 - run_list: - - recipe[test::user_database] - attributes: - mysql_test: - version: '5.6' - includes: <%= yum_dists_with_56 %> - verifier: - controls: - - mysql_database - - mysql_user - inputs: - version: '5.6' - inspec_tests: - - path: test/integration/resources - - name: resources-57 run_list: - recipe[test::user_database] From 8d7d2bed16f1ab9d972f04fcd9d092f5b8f1b3d6 Mon Sep 17 00:00:00 2001 From: Dan Webb Date: Thu, 2 May 2024 10:36:04 +0100 Subject: [PATCH 02/16] chore: Update platforms Signed-off-by: Dan Webb --- kitchen.yml | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/kitchen.yml b/kitchen.yml index 7522e99ca..66d506444 100644 --- a/kitchen.yml +++ b/kitchen.yml @@ -1,8 +1,7 @@ <% yum_dists_with_57 = %w(fedora-latest) -apt_dists_with_57 = %w(ubuntu-18.04) yum_dists_with_80 = %w(centos-stream-8 almalinux-8 rockylinux-8 fedora-latest) -apt_dists_with_80 = %w(ubuntu-20.04) +apt_dists_with_80 = %w(ubuntu-20.04 ubuntu-22.04 ubuntu-24.04) %> --- driver: @@ -14,14 +13,6 @@ suites: # # client # - - name: client-install-57 - run_list: - - recipe[test::installation_client] - attributes: - mysql_test: - version: '5.7' - includes: <%= apt_dists_with_57 %> - - name: yum-client-install-57 run_list: - recipe[selinux::disabled] @@ -53,14 +44,6 @@ suites: # # server smoke # - - name: smoke57 - run_list: - - recipe[test::smoke] - attributes: - mysql_test: - version: '5.7' - includes: <%= apt_dists_with_57 %> - - name: yum-smoke57 run_list: - recipe[selinux::disabled] @@ -109,7 +92,7 @@ suites: version: '5.8' inspec_tests: - path: test/integration/resources - includes: <%= yum_dists_with_57 + apt_dists_with_57 %> + includes: <%= yum_dists_with_57 %> - name: resources-80 run_list: From 557e575fc2d8dabdb27c21d3491c1b62ee38574f Mon Sep 17 00:00:00 2001 From: Dan Webb Date: Thu, 2 May 2024 11:32:57 +0100 Subject: [PATCH 03/16] Remove EOL MySQL 5.7 testing Signed-off-by: Dan Webb --- kitchen.yml | 39 +-------------------------------------- 1 file changed, 1 insertion(+), 38 deletions(-) diff --git a/kitchen.yml b/kitchen.yml index 66d506444..762af2764 100644 --- a/kitchen.yml +++ b/kitchen.yml @@ -1,6 +1,5 @@ <% -yum_dists_with_57 = %w(fedora-latest) -yum_dists_with_80 = %w(centos-stream-8 almalinux-8 rockylinux-8 fedora-latest) +yum_dists_with_80 = %w(centos-stream-9 almalinux-9 rockylinux-9 fedora-latest) apt_dists_with_80 = %w(ubuntu-20.04 ubuntu-22.04 ubuntu-24.04) %> --- @@ -13,16 +12,6 @@ suites: # # client # - - name: yum-client-install-57 - run_list: - - recipe[selinux::disabled] - - recipe[test::yum_repo] - - recipe[test::installation_client] - attributes: - mysql_test: - version: '5.7' - includes: <%= yum_dists_with_57 %> - - name: yum-client-install-80 run_list: - recipe[test::yum_repo] @@ -44,16 +33,6 @@ suites: # # server smoke # - - name: yum-smoke57 - run_list: - - recipe[selinux::disabled] - - recipe[test::yum_repo] - - recipe[test::smoke] - attributes: - mysql_test: - version: '5.7' - includes: <%= yum_dists_with_57 %> - - name: smoke80 run_list: - recipe[test::smoke] @@ -78,22 +57,6 @@ suites: # # resource tests # - - name: resources-57 - run_list: - - recipe[test::user_database] - attributes: - mysql_test: - version: '5.7' - verifier: - controls: - - mysql_database - - mysql_user - inputs: - version: '5.8' - inspec_tests: - - path: test/integration/resources - includes: <%= yum_dists_with_57 %> - - name: resources-80 run_list: - recipe[test::user_database] From 383af7ad00f026b8cbc01cb3cabbdf292f032925 Mon Sep 17 00:00:00 2001 From: Dan Webb Date: Thu, 2 May 2024 11:50:23 +0100 Subject: [PATCH 04/16] Update platforms Signed-off-by: Dan Webb --- .github/workflows/ci.yml | 46 +++------------------------------------- 1 file changed, 3 insertions(+), 43 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0641368ee..99e6278b4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,55 +23,15 @@ jobs: strategy: matrix: os: - - "almalinux-8" - - "centos-stream-8" - - "rockylinux-8" + - "almalinux-9" + - "centos-stream-9" + - "rockylinux-9" - "ubuntu-2004" - "ubuntu-2204" suite: - - "client-install-57" - "client-install-80" - - "smoke57" - "smoke80" - - "resources-57" - "resources-80" - exclude: - - os: almalinux-8 - suite: client-install-57 - - os: almalinux-8 - suite: smoke57 - - os: almalinux-8 - suite: resources-57 - - os: centos-stream-8 - suite: client-install-57 - - os: centos-stream-8 - suite: smoke57 - - os: centos-stream-8 - suite: resources-57 - - os: ubuntu-1804 - suite: client-install-80 - - os: ubuntu-1804 - suite: smoke80 - - os: ubuntu-1804 - suite: resources-80 - - os: ubuntu-2004 - suite: client-install-57 - - os: ubuntu-2004 - suite: smoke57 - - os: ubuntu-2004 - suite: resources-57 - - os: ubuntu-2204 - suite: client-install-57 - - os: ubuntu-2204 - suite: smoke57 - - os: ubuntu-2204 - suite: resources-57 - - os: rockylinux-8 - suite: client-install-57 - - os: rockylinux-8 - suite: smoke57 - - os: rockylinux-8 - suite: resources-57 fail-fast: false steps: From 5ad521bd0e48b1481f2bf1dbdda3ebbc0785f319 Mon Sep 17 00:00:00 2001 From: Dan Webb Date: Thu, 2 May 2024 11:54:41 +0100 Subject: [PATCH 05/16] Remove selinux cookbook dep Signed-off-by: Dan Webb --- kitchen.yml | 2 -- test/cookbooks/test/metadata.rb | 1 - 2 files changed, 3 deletions(-) diff --git a/kitchen.yml b/kitchen.yml index 762af2764..9fe928bb5 100644 --- a/kitchen.yml +++ b/kitchen.yml @@ -15,7 +15,6 @@ suites: - name: yum-client-install-80 run_list: - recipe[test::yum_repo] - - recipe[selinux::disabled] - recipe[test::installation_client] attributes: mysql_test: @@ -44,7 +43,6 @@ suites: - name: yum-smoke80 run_list: - recipe[test::yum_repo] - - recipe[selinux::disabled] - recipe[test::smoke] attributes: mysql_test: diff --git a/test/cookbooks/test/metadata.rb b/test/cookbooks/test/metadata.rb index 55a87dd7c..79dedf361 100644 --- a/test/cookbooks/test/metadata.rb +++ b/test/cookbooks/test/metadata.rb @@ -3,5 +3,4 @@ depends 'apparmor' depends 'mysql' -depends 'selinux' depends 'yum-mysql-community' From fbf3b5b14d1656bc1f0ffec06cde0ccfffb7517b Mon Sep 17 00:00:00 2001 From: Dan Webb Date: Thu, 2 May 2024 11:57:28 +0100 Subject: [PATCH 06/16] Update wording Signed-off-by: Dan Webb --- test/cookbooks/test/metadata.rb | 2 +- .../test/recipes/installation_server.rb | 13 -- test/cookbooks/test/recipes/smoke.rb | 118 +++++++++--------- 3 files changed, 60 insertions(+), 73 deletions(-) diff --git a/test/cookbooks/test/metadata.rb b/test/cookbooks/test/metadata.rb index 79dedf361..3d65e182a 100644 --- a/test/cookbooks/test/metadata.rb +++ b/test/cookbooks/test/metadata.rb @@ -3,4 +3,4 @@ depends 'apparmor' depends 'mysql' -depends 'yum-mysql-community' +# depends 'yum-mysql-community' diff --git a/test/cookbooks/test/recipes/installation_server.rb b/test/cookbooks/test/recipes/installation_server.rb index d94f72874..6a742bc89 100644 --- a/test/cookbooks/test/recipes/installation_server.rb +++ b/test/cookbooks/test/recipes/installation_server.rb @@ -1,18 +1,5 @@ apt_update 'update' -def configure_package_repositories - # we need to enable the yum-mysql-community repository to get packages - return unless platform_family?('rhel', 'fedora') - case node['mysql_test']['version'] - when '5.6' - include_recipe 'yum-mysql-community::mysql56' - when '5.7' - include_recipe 'yum-mysql-community::mysql57' - end -end - -configure_package_repositories - mysql_server_installation_package 'default' do version node['mysql_test']['version'] action :install diff --git a/test/cookbooks/test/recipes/smoke.rb b/test/cookbooks/test/recipes/smoke.rb index 254c93368..8e4605a9f 100644 --- a/test/cookbooks/test/recipes/smoke.rb +++ b/test/cookbooks/test/recipes/smoke.rb @@ -3,9 +3,9 @@ apt_update 'update' # variables -root_pass_master = 'MyPa$$word\Has_"Special\'Chars%!' -root_pass_slave = 'An0th3r_Pa%%w0rd!' -source_data = node['mysql_test']['version'].to_i >= 8 ? '--source-data' : '--master-data' +root_pass_primary = 'MyPa$$word\Has_"Special\'Chars%!' +root_pass_replica = 'An0th3r_Pa%%w0rd!' +source_data = node['mysql_test']['version'].to_i >= 8 ? '--source-data' : '--primary-data' # We're not able to use apparmor with how this test is setup so disable it for now node.default['apparmor']['disable'] = true @@ -14,65 +14,65 @@ # Debug message Chef::Log.error "\n\n" + '=' * 80 + "\n\nTesting MySQL version '#{node['mysql_test']['version']}'\n\n" + '=' * 80 -# master -mysql_service 'master' do +# primary +mysql_service 'primary' do port '3306' version node['mysql_test']['version'] - initial_root_password root_pass_master + initial_root_password root_pass_primary action [:create, :start] end -mysql_config 'master replication' do +mysql_config 'primary replication' do config_name 'replication' - instance 'master' - source 'replication-master.erb' - variables(server_id: '1', mysql_instance: 'master') - notifies :restart, 'mysql_service[master]', :immediately + instance 'primary' + source 'replication-primary.erb' + variables(server_id: '1', mysql_instance: 'primary') + notifies :restart, 'mysql_service[primary]', :immediately action :create end # MySQL client -mysql_client 'master' do +mysql_client 'primary' do action :create end -# slave-1 -mysql_service 'slave-1' do +# replica-1 +mysql_service 'replica-1' do port '3307' version node['mysql_test']['version'] - initial_root_password root_pass_slave + initial_root_password root_pass_replica action [:create, :start] end -mysql_config 'replication-slave-1' do - instance 'slave-1' - source 'replication-slave.erb' - variables(server_id: '2', mysql_instance: 'slave-1') - notifies :restart, 'mysql_service[slave-1]', :immediately +mysql_config 'replication-replica-1' do + instance 'replica-1' + source 'replication-replica.erb' + variables(server_id: '2', mysql_instance: 'replica-1') + notifies :restart, 'mysql_service[replica-1]', :immediately action :create end -# slave-2 -mysql_service 'slave-2' do +# replica-2 +mysql_service 'replica-2' do port '3308' version node['mysql_test']['version'] - initial_root_password root_pass_slave + initial_root_password root_pass_replica action [:create, :start] end -mysql_config 'replication-slave-2' do - instance 'slave-2' - source 'replication-slave.erb' - variables(server_id: '3', mysql_instance: 'slave-2') - notifies :restart, 'mysql_service[slave-2]', :immediately +mysql_config 'replication-replica-2' do + instance 'replica-2' + source 'replication-replica.erb' + variables(server_id: '3', mysql_instance: 'replica-2') + notifies :restart, 'mysql_service[replica-2]', :immediately action :create end -wait_for_command = "/usr/bin/mysql -u root -h 127.0.0.1 -P 3308 -p#{Shellwords.escape(root_pass_slave)} -e 'SELECT 0' >/dev/null 2>&1" -# Wait for slave-2 to start up, the sql below may not run properly if it isn't started, +wait_for_command = "/usr/bin/mysql -u root -h 127.0.0.1 -P 3308 -p#{Shellwords.escape(root_pass_replica)} -e 'SELECT 0' >/dev/null 2>&1" +# Wait for replica-2 to start up, the sql below may not run properly if it isn't started, # even if it will start properly eventually. -# Not worrying about master or slave-1 as starting slave-2 should provide enough buffer -ruby_block 'wait for slave-2' do +# Not worrying about primary or replica-1 as starting replica-2 should provide enough buffer +ruby_block 'wait for replica-2' do block do require 'English' times = 0 @@ -86,13 +86,13 @@ not_if wait_for_command end -# Create user repl on master +# Create user repl on primary bash 'create replication user' do code <<-EOF - /usr/bin/mysql -u root -h 127.0.0.1 -P 3306 -p#{Shellwords.escape(root_pass_master)} -D mysql -e "CREATE USER 'repl'@'127.0.0.1' IDENTIFIED BY 'REPLICAAATE';" - /usr/bin/mysql -u root -h 127.0.0.1 -P 3306 -p#{Shellwords.escape(root_pass_master)} -D mysql -e "GRANT REPLICATION SLAVE ON *.* TO 'repl'@'127.0.0.1';" + /usr/bin/mysql -u root -h 127.0.0.1 -P 3306 -p#{Shellwords.escape(root_pass_primary)} -D mysql -e "CREATE USER 'repl'@'127.0.0.1' IDENTIFIED BY 'REPLICAAATE';" + /usr/bin/mysql -u root -h 127.0.0.1 -P 3306 -p#{Shellwords.escape(root_pass_primary)} -D mysql -e "GRANT REPLICATION replica ON *.* TO 'repl'@'127.0.0.1';" EOF - not_if "/usr/bin/mysql -u root -h 127.0.0.1 -P 3306 -p#{Shellwords.escape(root_pass_master)} -e 'select User,Host from mysql.user' | grep repl" + not_if "/usr/bin/mysql -u root -h 127.0.0.1 -P 3306 -p#{Shellwords.escape(root_pass_primary)} -e 'select User,Host from mysql.user' | grep repl" action :run end @@ -101,10 +101,10 @@ user 'root' code <<-EOF mysqldump \ - --defaults-file=/etc/mysql-master/my.cnf \ + --defaults-file=/etc/mysql-primary/my.cnf \ -u root \ --protocol=tcp \ - -p#{Shellwords.escape(root_pass_master)} \ + -p#{Shellwords.escape(root_pass_primary)} \ --skip-lock-tables \ --single-transaction \ --flush-logs \ @@ -121,7 +121,7 @@ user 'root' code <<-EOF head /root/dump.sql -n80 \ - | grep 'MASTER_LOG_POS' \ + | grep 'primary_LOG_POS' \ | awk '{ print $6 }' \ | cut -f2 -d '=' \ | cut -f1 -d';' \ @@ -131,42 +131,42 @@ action :run end -# import dump into slaves -bash 'slave-1 import' do +# import dump into replicas +bash 'replica-1 import' do user 'root' - code "/usr/bin/mysql -u root -h 127.0.0.1 -P 3307 -p#{Shellwords.escape(root_pass_slave)} < /root/dump.sql" - not_if "/usr/bin/mysql -u root -h 127.0.0.1 -P 3307 -p#{Shellwords.escape(root_pass_slave)} -e 'select User,Host from mysql.user' | grep repl" + code "/usr/bin/mysql -u root -h 127.0.0.1 -P 3307 -p#{Shellwords.escape(root_pass_replica)} < /root/dump.sql" + not_if "/usr/bin/mysql -u root -h 127.0.0.1 -P 3307 -p#{Shellwords.escape(root_pass_replica)} -e 'select User,Host from mysql.user' | grep repl" action :run end -bash 'slave-2 import' do +bash 'replica-2 import' do user 'root' - code "/usr/bin/mysql -u root -h 127.0.0.1 -P 3308 -p#{Shellwords.escape(root_pass_slave)} < /root/dump.sql" - not_if "/usr/bin/mysql -u root -h 127.0.0.1 -P 3308 -p#{Shellwords.escape(root_pass_slave)} -e 'select User,Host from mysql.user' | grep repl" + code "/usr/bin/mysql -u root -h 127.0.0.1 -P 3308 -p#{Shellwords.escape(root_pass_replica)} < /root/dump.sql" + not_if "/usr/bin/mysql -u root -h 127.0.0.1 -P 3308 -p#{Shellwords.escape(root_pass_replica)} -e 'select User,Host from mysql.user' | grep repl" action :run end -# start replication on slave-1 -ruby_block 'start_slave_1' do - block { start_slave_1(root_pass_slave) } # libraries/helpers.rb - not_if "/usr/bin/mysql -u root -h 127.0.0.1 -P 3307 -p#{Shellwords.escape(root_pass_slave)} -e 'SHOW SLAVE STATUS\\G' | grep Slave_IO_State" +# start replication on replica-1 +ruby_block 'start_replica_1' do + block { start_replica_1(root_pass_replica) } # libraries/helpers.rb + not_if "/usr/bin/mysql -u root -h 127.0.0.1 -P 3307 -p#{Shellwords.escape(root_pass_replica)} -e 'SHOW replica STATUS\\G' | grep replica_IO_State" action :run end -# start replication on slave-2 -ruby_block 'start_slave_2' do - block { start_slave_2(root_pass_slave) } # libraries/helpers.rb - not_if "/usr/bin/mysql -u root -h 127.0.0.1 -P 3308 -p#{Shellwords.escape(root_pass_slave)} -e 'SHOW SLAVE STATUS\\G' | grep Slave_IO_State" +# start replication on replica-2 +ruby_block 'start_replica_2' do + block { start_replica_2(root_pass_replica) } # libraries/helpers.rb + not_if "/usr/bin/mysql -u root -h 127.0.0.1 -P 3308 -p#{Shellwords.escape(root_pass_replica)} -e 'SHOW replica STATUS\\G' | grep replica_IO_State" action :run end -# create databass on master +# create databass on primary bash 'create databass' do code <<-EOF - /usr/bin/mysql -u root -h 127.0.0.1 -P 3306 -p#{Shellwords.escape(root_pass_master)} -e 'CREATE DATABASE databass'; - /usr/bin/mysql -u root -h 127.0.0.1 -P 3306 -p#{Shellwords.escape(root_pass_master)} -e 'CREATE TABLE databass.table1 (name VARCHAR(20), userRank VARCHAR(20))'; - /usr/bin/mysql -u root -h 127.0.0.1 -P 3306 -p#{Shellwords.escape(root_pass_master)} -e "INSERT INTO databass.table1 (name,userRank) VALUES ('captain','awesome')"; + /usr/bin/mysql -u root -h 127.0.0.1 -P 3306 -p#{Shellwords.escape(root_pass_primary)} -e 'CREATE DATABASE databass'; + /usr/bin/mysql -u root -h 127.0.0.1 -P 3306 -p#{Shellwords.escape(root_pass_primary)} -e 'CREATE TABLE databass.table1 (name VARCHAR(20), userRank VARCHAR(20))'; + /usr/bin/mysql -u root -h 127.0.0.1 -P 3306 -p#{Shellwords.escape(root_pass_primary)} -e "INSERT INTO databass.table1 (name,userRank) VALUES ('captain','awesome')"; EOF - not_if "/usr/bin/mysql -u root -h 127.0.0.1 -P 3306 -p#{Shellwords.escape(root_pass_master)} -e 'show databases' | grep databass" + not_if "/usr/bin/mysql -u root -h 127.0.0.1 -P 3306 -p#{Shellwords.escape(root_pass_primary)} -e 'show databases' | grep databass" action :run end From b8fdc29d54164aaa4dadb243da4ca05b8acbd5ec Mon Sep 17 00:00:00 2001 From: Dan Webb Date: Thu, 2 May 2024 12:00:34 +0100 Subject: [PATCH 07/16] Remove more references to 5.6 5.7 Signed-off-by: Dan Webb --- README.md | 16 --------------- libraries/helpers.rb | 41 -------------------------------------- libraries/mysql_base.rb | 2 +- libraries/mysql_config.rb | 2 +- libraries/mysql_service.rb | 2 +- 5 files changed, 3 insertions(+), 60 deletions(-) diff --git a/README.md b/README.md index e527d5c24..50924b2bb 100644 --- a/README.md +++ b/README.md @@ -23,22 +23,6 @@ This cookbook is maintained by the Sous Chefs. The Sous Chefs are a community of - Network accessible package repositories - 'recipe[selinux::disabled]' on RHEL platforms -## Platform Support - -The following platforms have been tested with Test Kitchen: - -| OS | 5.6 | 5.7 | 8.0 | -|----------------|-----|-----|-----| -| centos-7 | X | X | X | -| centos-8 | | X | X | -| debian-9 | | X | | -| debian-10 | | | X | -| fedora | X | X | X | -| openSUSE Leap | X | | | -| ubuntu-18.04 | | X | | -| ubuntu-20.04 | | | X | -| ubuntu-22.04 | | | X | - ## Cookbook Dependencies There are no hard coupled dependencies. However, there is a loose dependency on `yum-mysql-community` for RHEL/CentOS platforms. As of the 8.0 version of this cookbook, configuration of the package repos is now the responsibility of the user. diff --git a/libraries/helpers.rb b/libraries/helpers.rb index ad96fee62..9f68e93fd 100644 --- a/libraries/helpers.rb +++ b/libraries/helpers.rb @@ -70,28 +70,6 @@ def default_pid_file "#{run_dir}/mysqld.pid" end - def default_major_version - # rhelish - return '5.6' if el7? - return '8.0' if el8? - return '5.6' if platform?('amazon') - - # debian - return '5.7' if stretch? - return '8.0' if buster? - - # ubuntu - return '5.7' if xenial? - return '5.7' if bionic? - return '8.0' if focal? - return '8.0' if jammy? - - # misc - return '5.6' if platform?('freebsd') - return '5.7' if fedora? - return '5.6' if suse? - end - def major_from_full(v) v.split('.').shift(2).join('.') end @@ -109,23 +87,12 @@ def default_socket_file end def default_client_package_name - return %w(mysql mysql-devel) if el7? - return ['mysql56', 'mysql56-devel.x86_64'] if major_version == '5.6' && platform?('amazon') - return ['mysql57', 'mysql57-devel.x86_64'] if major_version == '5.7' && platform?('amazon') - return ['mysql-client-5.6', 'libmysqlclient-dev'] if major_version == '5.6' && platform_family?('debian') - return ['mysql-client-5.7', 'libmysqlclient-dev'] if major_version == '5.7' && platform_family?('debian') return ['mysql-client-8.0', 'libmysqlclient-dev'] if major_version == '8.0' && platform_family?('debian') - return 'mysql-community-server-client' if major_version == '5.6' && platform_family?('suse') %w(mysql-community-client mysql-community-devel) end def default_server_package_name - return 'mysql56-server' if major_version == '5.6' && platform?('amazon') - return 'mysql57-server' if major_version == '5.7' && platform?('amazon') - return 'mysql-server-5.6' if major_version == '5.6' && platform_family?('debian') - return 'mysql-server-5.7' if major_version == '5.7' && platform_family?('debian') return 'mysql-server-8.0' if major_version == '8.0' && platform_family?('debian') - return 'mysql-community-server' if major_version == '5.6' && platform_family?('suse') 'mysql-community-server' end @@ -171,14 +138,6 @@ def system_service_name 'mysql' # not one of the above end - def v56plus - Gem::Version.new(version) >= Gem::Version.new('5.6') - end - - def v57plus - Gem::Version.new(version) >= Gem::Version.new('5.7') - end - def v80plus Gem::Version.new(version) >= Gem::Version.new('8.0') end diff --git a/libraries/mysql_base.rb b/libraries/mysql_base.rb index 0e1d6754e..08a233794 100644 --- a/libraries/mysql_base.rb +++ b/libraries/mysql_base.rb @@ -18,7 +18,7 @@ class MysqlBase < Chef::Resource ################### property :run_group, String, default: 'mysql', desired_state: false property :run_user, String, default: 'mysql', desired_state: false - property :version, String, default: lazy { default_major_version }, desired_state: false + property :version, String, default: '8.0', desired_state: false property :include_dir, String, default: lazy { default_include_dir }, desired_state: false property :major_version, String, default: lazy { major_from_full(version) }, desired_state: false diff --git a/libraries/mysql_config.rb b/libraries/mysql_config.rb index 27409fec8..c40d30c94 100644 --- a/libraries/mysql_config.rb +++ b/libraries/mysql_config.rb @@ -10,7 +10,7 @@ class MysqlConfig < MysqlBase property :owner, String, default: 'mysql', desired_state: false property :source, String, desired_state: false property :variables, [Hash], desired_state: false - property :version, String, default: lazy { default_major_version }, desired_state: false + property :version, String, default: '8.0', desired_state: false require_relative 'helpers' include MysqlCookbook::HelpersBase diff --git a/libraries/mysql_service.rb b/libraries/mysql_service.rb index 2880ab393..fdd151794 100644 --- a/libraries/mysql_service.rb +++ b/libraries/mysql_service.rb @@ -9,7 +9,7 @@ class MysqlService < MysqlServiceBase property :service_manager, %w(sysvinit upstart systemd auto), default: 'auto', desired_state: false # mysql_server_installation - property :version, String, default: lazy { default_major_version }, desired_state: false + property :version, String, default: '8.0', desired_state: false property :major_version, String, default: lazy { major_from_full(version) }, desired_state: false property :package_name, String, default: lazy { default_package_name }, desired_state: false property :package_options, [String, nil], desired_state: false From 3e8c0521a6ffd6d0e5edec7b5a5c0cda1be8c889 Mon Sep 17 00:00:00 2001 From: Dan Webb Date: Thu, 2 May 2024 13:21:27 +0100 Subject: [PATCH 08/16] Update specs Signed-off-by: Dan Webb --- .../mysql_client_installation_package_spec.rb | 57 +++------------- .../mysql_server_installation_package_spec.rb | 66 +++---------------- 2 files changed, 16 insertions(+), 107 deletions(-) diff --git a/spec/mysql_client_installation_package_spec.rb b/spec/mysql_client_installation_package_spec.rb index aa08cc6dd..64e388640 100644 --- a/spec/mysql_client_installation_package_spec.rb +++ b/spec/mysql_client_installation_package_spec.rb @@ -1,41 +1,11 @@ require 'spec_helper' describe 'test::installation_client' do - let(:installation_client_package_centos_7) { ChefSpec::ServerRunner.new(platform: 'centos', version: '7') } let(:installation_client_package_centos_8) { ChefSpec::ServerRunner.new(platform: 'centos', version: '8') } let(:installation_client_package_fedora) { ChefSpec::ServerRunner.new(platform: 'fedora') } - let(:installation_client_package_ubuntu_1804) { ChefSpec::ServerRunner.new(platform: 'ubuntu', version: '18.04') } - - context 'using el7' do - it 'installs mysql_client_installation_package[default] when version is 5.6' do - installation_client_package_centos_7.node.default['mysql_test']['version'] = '5.6' - installation_client_package_centos_7.converge(described_recipe) - expect(installation_client_package_centos_7).to create_mysql_client_installation_package('default').with( - version: '5.6', - package_name: %w(mysql mysql-devel) - ) - end - - it 'installs mysql_client_installation_package[default] when version is 5.7' do - installation_client_package_centos_7.node.default['mysql_test']['version'] = '5.7' - installation_client_package_centos_7.converge(described_recipe) - expect(installation_client_package_centos_7).to create_mysql_client_installation_package('default').with( - version: '5.7', - package_name: %w(mysql mysql-devel) - ) - end - end + let(:installation_client_package_ubuntu_2204) { ChefSpec::ServerRunner.new(platform: 'ubuntu', version: '18.04') } context 'using el8' do - it 'installs mysql_client_installation_package[default] when version is 5.7' do - installation_client_package_centos_8.node.default['mysql_test']['version'] = '5.7' - installation_client_package_centos_8.converge(described_recipe) - expect(installation_client_package_centos_8).to create_mysql_client_installation_package('default').with( - version: '5.7', - package_name: %w(mysql-community-client mysql-community-devel) - ) - end - it 'installs mysql_client_installation_package[default] when version is 8.0' do installation_client_package_centos_8.node.default['mysql_test']['version'] = '8.0' installation_client_package_centos_8.converge(described_recipe) @@ -46,24 +16,13 @@ end end - context 'using fedora' do - it 'installs mysql_client_installation_package[default] when version is 5.7' do - installation_client_package_fedora.node.default['mysql_test']['version'] = '5.7' - installation_client_package_fedora.converge(described_recipe) - expect(installation_client_package_fedora).to create_mysql_client_installation_package('default').with( - version: '5.7', - package_name: %w(mysql-community-client mysql-community-devel) - ) - end - end - - context 'using ubuntu 18.04' do - it 'installs mysql_client_installation_package[default] when version is 5.7' do - installation_client_package_ubuntu_1804.node.default['mysql_test']['version'] = '5.7' - installation_client_package_ubuntu_1804.converge(described_recipe) - expect(installation_client_package_ubuntu_1804).to create_mysql_client_installation_package('default').with( - version: '5.7', - package_name: ['mysql-client-5.7', 'libmysqlclient-dev'] + context 'using ubuntu 22.04' do + it 'installs mysql_client_installation_package[default] when version is 8.0' do + installation_client_package_ubuntu_2204.node.default['mysql_test']['version'] = '8.0' + installation_client_package_ubuntu_2204.converge(described_recipe) + expect(installation_client_package_ubuntu_2204).to create_mysql_client_installation_package('default').with( + version: '8.0', + package_name: ['mysql-client-8.0', 'libmysqlclient-dev'] ) end end diff --git a/spec/mysql_server_installation_package_spec.rb b/spec/mysql_server_installation_package_spec.rb index 4d4f4f0d2..50f8ab20c 100644 --- a/spec/mysql_server_installation_package_spec.rb +++ b/spec/mysql_server_installation_package_spec.rb @@ -1,41 +1,11 @@ require 'spec_helper' describe 'test::installation_server' do - let(:installation_server_package_centos_7) { ChefSpec::ServerRunner.new(platform: 'centos', version: '7') } let(:installation_server_package_centos_8) { ChefSpec::ServerRunner.new(platform: 'centos', version: '8') } let(:installation_server_package_fedora) { ChefSpec::ServerRunner.new(platform: 'fedora') } - let(:installation_server_package_ubuntu_1804) { ChefSpec::ServerRunner.new(platform: 'ubuntu', version: '18.04') } - - context 'using el7' do - it 'installs mysql_server_installation_package[default] when version is 5.6' do - installation_server_package_centos_7.node.default['mysql_test']['version'] = '5.6' - installation_server_package_centos_7.converge(described_recipe) - expect(installation_server_package_centos_7).to install_mysql_server_installation_package('default').with( - version: '5.6', - package_name: 'mysql-community-server' - ) - end - - it 'installs mysql_server_installation_package[default] when version is 5.7' do - installation_server_package_centos_7.node.default['mysql_test']['version'] = '5.7' - installation_server_package_centos_7.converge(described_recipe) - expect(installation_server_package_centos_7).to install_mysql_server_installation_package('default').with( - version: '5.7', - package_name: 'mysql-community-server' - ) - end - end + let(:installation_server_package_ubuntu_2204) { ChefSpec::ServerRunner.new(platform: 'ubuntu', version: '18.04') } context 'using el8' do - it 'installs mysql_server_installation_package[default] when version is 5.7' do - installation_server_package_centos_8.node.default['mysql_test']['version'] = '5.7' - installation_server_package_centos_8.converge(described_recipe) - expect(installation_server_package_centos_8).to install_mysql_server_installation_package('default').with( - version: '5.7', - package_name: 'mysql-community-server' - ) - end - it 'installs mysql_server_installation_package[default] when version is 8.0' do installation_server_package_centos_8.node.default['mysql_test']['version'] = '8.0' installation_server_package_centos_8.converge(described_recipe) @@ -46,33 +16,13 @@ end end - context 'using fedora' do - it 'installs mysql_server_installation_package[default] when version is 5.6' do - installation_server_package_fedora.node.default['mysql_test']['version'] = '5.6' - installation_server_package_fedora.converge(described_recipe) - expect(installation_server_package_fedora).to install_mysql_server_installation_package('default').with( - version: '5.6', - package_name: 'mysql-community-server' - ) - end - - it 'installs mysql_server_installation_package[default] when version is 5.7' do - installation_server_package_fedora.node.default['mysql_test']['version'] = '5.7' - installation_server_package_fedora.converge(described_recipe) - expect(installation_server_package_fedora).to install_mysql_server_installation_package('default').with( - version: '5.7', - package_name: 'mysql-community-server' - ) - end - end - - context 'using ubuntu 18.04' do - it 'installs mysql_server_installation_package[default] when version is 5.7' do - installation_server_package_ubuntu_1804.node.default['mysql_test']['version'] = '5.7' - installation_server_package_ubuntu_1804.converge(described_recipe) - expect(installation_server_package_ubuntu_1804).to install_mysql_server_installation_package('default').with( - version: '5.7', - package_name: 'mysql-server-5.7' + context 'using ubuntu 22.04' do + it 'installs mysql_server_installation_package[default] when version is 8.0' do + installation_server_package_ubuntu_2204.node.default['mysql_test']['version'] = '8.0' + installation_server_package_ubuntu_2204.converge(described_recipe) + expect(installation_server_package_ubuntu_2204).to install_mysql_server_installation_package('default').with( + version: '8.0', + package_name: 'mysql-server-8.0' ) end end From 7a00b08933a01858fe2c6741f367e7851f18db0e Mon Sep 17 00:00:00 2001 From: Dan Webb Date: Thu, 2 May 2024 13:59:36 +0100 Subject: [PATCH 09/16] Remove 57plus method Signed-off-by: Dan Webb --- libraries/helpers.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/libraries/helpers.rb b/libraries/helpers.rb index 9f68e93fd..782c3dd97 100644 --- a/libraries/helpers.rb +++ b/libraries/helpers.rb @@ -158,7 +158,7 @@ def init_records_script # mysql will read \& as &, but \% as \%. Just escape bare-minimum \ and ' sql_escaped_password = root_password.gsub('\\') { '\\\\' }.gsub("'") { '\\\'' } cmd = "UPDATE mysql.user SET #{password_column_name}=PASSWORD('#{sql_escaped_password}')#{password_expired} WHERE user = 'root';" - cmd = "ALTER USER 'root'@'localhost' IDENTIFIED BY '#{sql_escaped_password}';" if v57plus + cmd = "ALTER USER 'root'@'localhost' IDENTIFIED BY '#{sql_escaped_password}';" <<-EOS set -e @@ -188,12 +188,12 @@ def wait_for_init while [ -f #{pid_file} ] ; do sleep 1 ; done rm -rf /tmp/#{mysql_name} EOS - cmd = '' if v57plus + cmd = '' cmd end def password_column_name - return 'authentication_string' if v57plus + return 'authentication_string' 'password' end @@ -206,12 +206,12 @@ def root_password end def password_expired - return ", password_expired='N'" if v57plus + return ", password_expired='N'" '' end def db_init - return mysqld_initialize_cmd if v57plus + return mysqld_initialize_cmd mysql_install_db_cmd end @@ -254,16 +254,16 @@ def mysqld_bin end def mysql_systemd_start_pre - return '/usr/bin/mysqld_pre_systemd' if v57plus && (el7? || el8? || fedora?) + return '/usr/bin/mysqld_pre_systemd' if el7? || el8? || fedora? return '/usr/bin/mysql-systemd-start pre' if platform_family?('rhel') return '/usr/lib/mysql/mysql-systemd-helper install' if suse? '/usr/share/mysql/mysql-systemd-start pre' end def mysql_systemd - return "/usr/libexec/#{mysql_name}-wait-ready $MAINPID" if v57plus && (el7? || el8? || fedora?) + return "/usr/libexec/#{mysql_name}-wait-ready $MAINPID" if el7? || el8? || fedora? return '/usr/bin/mysql-systemd-start' if platform_family?('rhel') - return '/usr/share/mysql/mysql-systemd-start' if v57plus + return '/usr/share/mysql/mysql-systemd-start' "/usr/libexec/#{mysql_name}-wait-ready $MAINPID" end From 056c8495d956f3c87b2004f79d03756636c2fac6 Mon Sep 17 00:00:00 2001 From: Dan Webb Date: Thu, 2 May 2024 14:20:05 +0100 Subject: [PATCH 10/16] SQUASHME Signed-off-by: Dan Webb --- libraries/helpers.rb | 64 ++++++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 29 deletions(-) diff --git a/libraries/helpers.rb b/libraries/helpers.rb index 782c3dd97..406b0479e 100644 --- a/libraries/helpers.rb +++ b/libraries/helpers.rb @@ -1,54 +1,59 @@ module MysqlCookbook + # rubocop:disable Metrics/ModuleLength, Style/Documentation module HelpersBase require 'shellwords' def el7? return true if platform_family?('rhel') && node['platform_version'].to_i == 7 + false end def el8? return true if platform_family?('rhel') && node['platform_version'].to_i == 8 + false end def fedora? return true if platform_family?('fedora') + false end def suse? return true if platform_family?('suse') - false - end - def stretch? - return true if platform?('debian') && node['platform_version'].to_i == 9 false end def buster? return true if platform?('debian') && node['platform_version'].to_i == 10 + false end def xenial? return true if platform?('ubuntu') && node['platform_version'] == '16.04' + false end def bionic? return true if platform?('ubuntu') && node['platform_version'] == '18.04' + false end def focal? return true if platform?('ubuntu') && node['platform_version'] == '20.04' + false end def jammy? return true if platform?('ubuntu') && node['platform_version'] == '22.04' + false end @@ -88,6 +93,7 @@ def default_socket_file def default_client_package_name return ['mysql-client-8.0', 'libmysqlclient-dev'] if major_version == '8.0' && platform_family?('debian') + %w(mysql-community-client mysql-community-devel) end @@ -157,8 +163,10 @@ def init_records_script # NOTE: shell-escaping passwords in a SQL file may cause corruption - eg # mysql will read \& as &, but \% as \%. Just escape bare-minimum \ and ' sql_escaped_password = root_password.gsub('\\') { '\\\\' }.gsub("'") { '\\\'' } + # rubocop:disable Lint/UselessAssignment cmd = "UPDATE mysql.user SET #{password_column_name}=PASSWORD('#{sql_escaped_password}')#{password_expired} WHERE user = 'root';" cmd = "ALTER USER 'root'@'localhost' IDENTIFIED BY '#{sql_escaped_password}';" + # rubocop:enable Lint/UselessAssignment <<-EOS set -e @@ -182,19 +190,16 @@ def init_records_script end def wait_for_init - cmd = <<-EOS - while [ ! -f #{pid_file} ] ; do sleep 1 ; done - kill `cat #{pid_file}` - while [ -f #{pid_file} ] ; do sleep 1 ; done - rm -rf /tmp/#{mysql_name} - EOS - cmd = '' - cmd + <<~SCRIPT + while [ ! -f #{pid_file} ] ; do sleep 1 ; done + kill `cat #{pid_file}` + while [ -f #{pid_file} ] ; do sleep 1 ; done + rm -rf /tmp/#{mysql_name} + SCRIPT end def password_column_name - return 'authentication_string' - 'password' + 'authentication_string' end def root_password @@ -206,21 +211,15 @@ def root_password end def password_expired - return ", password_expired='N'" - '' + ", password_expired='N'" end def db_init - return mysqld_initialize_cmd - mysql_install_db_cmd + mysqld_initialize_cmd end def db_initialized? - if v80plus - ::File.exist? "#{data_dir}/mysql.ibd" - else - ::File.exist? "#{data_dir}/mysql/user.frm" - end + ::File.exist? "#{data_dir}/mysql.ibd" end def mysql_install_db_bin @@ -233,7 +232,6 @@ def mysql_install_db_cmd cmd = mysql_install_db_bin cmd << " --defaults-file=#{etc_dir}/my.cnf" cmd << " --datadir=#{data_dir}" - cmd << ' --explicit_defaults_for_timestamp' if v56plus && !v57plus return "scl enable #{scl_name} \"#{cmd}\"" if scl_package? cmd end @@ -257,22 +255,24 @@ def mysql_systemd_start_pre return '/usr/bin/mysqld_pre_systemd' if el7? || el8? || fedora? return '/usr/bin/mysql-systemd-start pre' if platform_family?('rhel') return '/usr/lib/mysql/mysql-systemd-helper install' if suse? + '/usr/share/mysql/mysql-systemd-start pre' end def mysql_systemd return "/usr/libexec/#{mysql_name}-wait-ready $MAINPID" if el7? || el8? || fedora? return '/usr/bin/mysql-systemd-start' if platform_family?('rhel') - return '/usr/share/mysql/mysql-systemd-start' - "/usr/libexec/#{mysql_name}-wait-ready $MAINPID" + + '/usr/share/mysql/mysql-systemd-start' end def mysqld_initialize_cmd cmd = mysqld_bin cmd << " --defaults-file=#{etc_dir}/my.cnf" cmd << ' --initialize' - cmd << ' --explicit_defaults_for_timestamp' if v56plus + cmd << ' --explicit_defaults_for_timestamp' return "scl enable #{scl_name} \"#{cmd}\"" if scl_package? + cmd end @@ -280,6 +280,7 @@ def mysqld_safe_bin return "#{prefix_dir}/bin/mysqld_safe" if platform_family?('smartos') return "#{base_dir}/bin/mysqld_safe" if platform_family?('omnios') return 'mysqld_safe' if scl_package? + "#{prefix_dir}/usr/bin/mysqld_safe" end @@ -287,9 +288,10 @@ def record_init cmd = v56plus ? mysqld_bin : mysqld_safe_bin cmd << " --defaults-file=#{etc_dir}/my.cnf" cmd << " --init-file=/tmp/#{mysql_name}/my.sql" - cmd << ' --explicit_defaults_for_timestamp' if v56plus + cmd << ' --explicit_defaults_for_timestamp' cmd << ' &' return "scl enable #{scl_name} \"#{cmd}\"" if scl_package? + cmd end @@ -308,6 +310,7 @@ def record_init # - socket : String or nil # Output: A String with cmd to execute the query (but do not execute it!) # + # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength def sql_command_string(query, database, ctrl, grep_for = nil) raw_query = query.is_a?(String) ? query : query.join(";\n") Chef::Log.debug("Control Hash: [#{ctrl.to_json}]\n") @@ -322,6 +325,7 @@ def sql_command_string(query, database, ctrl, grep_for = nil) Chef::Log.debug("Executing this command: [#{cmd}]\n") cmd end + # rubocop:enable Metrics/AbcSize ####### # Function to execute an SQL statement in the default database. @@ -355,13 +359,14 @@ def parse_one_row(row, titles) return_hash end + # rubocop:disable Metrics/MethodLength def parse_mysql_batch_result(mysql_batch_result) results = mysql_batch_result.split("\n") titles = [] index = 0 return_array = [] results.each do |row| - if index == 0 + if index.zero? titles = row.split("\t") else return_array[index - 1] = parse_one_row(row, titles) @@ -370,5 +375,6 @@ def parse_mysql_batch_result(mysql_batch_result) end return_array end + # rubocop:enable Metrics/MethodLength end end From 7319bc4bb6caa4eae16013c6b5518c5d9403c1e8 Mon Sep 17 00:00:00 2001 From: Dan Webb Date: Thu, 2 May 2024 14:28:21 +0100 Subject: [PATCH 11/16] . Signed-off-by: Dan Webb --- libraries/helpers.rb | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/libraries/helpers.rb b/libraries/helpers.rb index 406b0479e..3de3ab20a 100644 --- a/libraries/helpers.rb +++ b/libraries/helpers.rb @@ -99,6 +99,7 @@ def default_client_package_name def default_server_package_name return 'mysql-server-8.0' if major_version == '8.0' && platform_family?('debian') + 'mysql-community-server' end @@ -110,6 +111,7 @@ def run_dir return "#{prefix_dir}/var/run/#{mysql_name}" if platform_family?('rhel') return '/run/mysqld' if platform_family?('debian') && mysql_name == 'mysql' return "/run/#{mysql_name}" if platform_family?('debian') + "/var/run/#{mysql_name}" end @@ -125,12 +127,14 @@ def scl_name def scl_package? return unless platform_family?('rhel') + false end def etc_dir return "/opt/mysql#{pkg_ver_string}/etc/#{mysql_name}" if platform_family?('omnios') return "#{prefix_dir}/etc/#{mysql_name}" if platform_family?('smartos') + "#{prefix_dir}/etc/#{mysql_name}" end @@ -139,9 +143,9 @@ def base_dir end def system_service_name - return 'mysqld' if platform_family?('rhel') - return 'mysqld' if platform_family?('fedora') - 'mysql' # not one of the above + return 'mysqld' if platform_family?('rhel') || platform_family?('fedora') + + 'mysql' end def v80plus @@ -154,6 +158,7 @@ def default_include_dir def log_dir return "/var/adm/log/#{mysql_name}" if platform_family?('omnios') + "#{prefix_dir}/var/log/#{mysql_name}" end @@ -225,6 +230,7 @@ def db_initialized? def mysql_install_db_bin return "#{base_dir}/scripts/mysql_install_db" if platform_family?('omnios') return "#{prefix_dir}/bin/mysql_install_db" if platform_family?('smartos') + 'mysql_install_db' end @@ -233,21 +239,23 @@ def mysql_install_db_cmd cmd << " --defaults-file=#{etc_dir}/my.cnf" cmd << " --datadir=#{data_dir}" return "scl enable #{scl_name} \"#{cmd}\"" if scl_package? + cmd end def mysqladmin_bin return "#{prefix_dir}/bin/mysqladmin" if platform_family?('smartos') return 'mysqladmin' if scl_package? + "#{prefix_dir}/usr/bin/mysqladmin" end def mysqld_bin return "#{prefix_dir}/libexec/mysqld" if platform_family?('smartos') return "#{base_dir}/bin/mysqld" if platform_family?('omnios') - return '/usr/sbin/mysqld' if fedora? && v56plus - return '/usr/libexec/mysqld' if fedora? + return '/usr/sbin/mysqld' if fedora? return 'mysqld' if scl_package? + "#{prefix_dir}/usr/sbin/mysqld" end @@ -285,7 +293,7 @@ def mysqld_safe_bin end def record_init - cmd = v56plus ? mysqld_bin : mysqld_safe_bin + cmd = mysqld_bin cmd << " --defaults-file=#{etc_dir}/my.cnf" cmd << " --init-file=/tmp/#{mysql_name}/my.sql" cmd << ' --explicit_defaults_for_timestamp' From 7e36523ed61609a0e4371d926632357d85d52c4b Mon Sep 17 00:00:00 2001 From: Dan Webb Date: Thu, 2 May 2024 14:29:32 +0100 Subject: [PATCH 12/16] Remove yum repo temporarily Signed-off-by: Dan Webb --- test/cookbooks/test/recipes/yum_repo.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/cookbooks/test/recipes/yum_repo.rb b/test/cookbooks/test/recipes/yum_repo.rb index 48f8ddd73..7c96c05ba 100644 --- a/test/cookbooks/test/recipes/yum_repo.rb +++ b/test/cookbooks/test/recipes/yum_repo.rb @@ -1,7 +1,7 @@ # Before that, we use "native" versions -unless node['mysql_test'].nil? || platform_family?('debian') - yum_mysql_community_repo 'mysql_repo' do - version node['mysql_test']['version'] - end -end +# unless node['mysql_test'].nil? || platform_family?('debian') +# yum_mysql_community_repo 'mysql_repo' do +# version node['mysql_test']['version'] +# end +# end From b32e4dbfd5158410b2e1df7522b2c05d7bc2978b Mon Sep 17 00:00:00 2001 From: Dan Webb Date: Thu, 2 May 2024 14:31:17 +0100 Subject: [PATCH 13/16] . Signed-off-by: Dan Webb --- libraries/helpers.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/helpers.rb b/libraries/helpers.rb index 3de3ab20a..6ccc8f237 100644 --- a/libraries/helpers.rb +++ b/libraries/helpers.rb @@ -99,7 +99,7 @@ def default_client_package_name def default_server_package_name return 'mysql-server-8.0' if major_version == '8.0' && platform_family?('debian') - + 'mysql-community-server' end @@ -143,7 +143,7 @@ def base_dir end def system_service_name - return 'mysqld' if platform_family?('rhel') || platform_family?('fedora') + return 'mysqld' if platform_family?('rhel', 'fedora') 'mysql' end From e7180a42794d7af12bf021d991e59b417cd4b759 Mon Sep 17 00:00:00 2001 From: Dan Webb Date: Thu, 2 May 2024 14:39:08 +0100 Subject: [PATCH 14/16] YOINK Signed-off-by: Dan Webb --- .../apparmor/ubuntu-14.04/usr.sbin.mysqld.erb | 47 ------------- .../apparmor/ubuntu-16.04/usr.sbin.mysqld.erb | 68 ------------------- .../apparmor/ubuntu-18.04/usr.sbin.mysqld.erb | 68 ------------------- ...ion-slave.erb => replication--replica.erb} | 0 ...ion-master.erb => replication-primary.erb} | 0 5 files changed, 183 deletions(-) delete mode 100644 templates/default/apparmor/ubuntu-14.04/usr.sbin.mysqld.erb delete mode 100644 templates/default/apparmor/ubuntu-16.04/usr.sbin.mysqld.erb delete mode 100644 templates/default/apparmor/ubuntu-18.04/usr.sbin.mysqld.erb rename test/cookbooks/test/templates/default/{replication-slave.erb => replication--replica.erb} (100%) rename test/cookbooks/test/templates/default/{replication-master.erb => replication-primary.erb} (100%) diff --git a/templates/default/apparmor/ubuntu-14.04/usr.sbin.mysqld.erb b/templates/default/apparmor/ubuntu-14.04/usr.sbin.mysqld.erb deleted file mode 100644 index 19ddbf59b..000000000 --- a/templates/default/apparmor/ubuntu-14.04/usr.sbin.mysqld.erb +++ /dev/null @@ -1,47 +0,0 @@ -# vim:syntax=apparmor -# Last Modified: Tue Jun 19 17:37:30 2007 -#include - -/usr/sbin/mysqld { - #include - #include - #include - #include - #include - - capability dac_override, - capability sys_resource, - capability setgid, - capability setuid, - - network tcp, - - /etc/hosts.allow r, - /etc/hosts.deny r, - - /etc/mysql/*.pem r, - /etc/mysql/conf.d/ r, - /etc/mysql/conf.d/* r, - /etc/mysql/*.cnf r, - /usr/lib/mysql/plugin/ r, - /usr/lib/mysql/plugin/*.so* mr, - /usr/sbin/mysqld mr, - /usr/share/mysql/** r, - /var/log/mysql.log rw, - /var/log/mysql.err rw, - /var/lib/mysql/ r, - /var/lib/mysql/** rwk, - /var/log/mysql/ r, - /var/log/mysql/* rw, - /var/run/mysqld/mysqld.pid rw, - /var/run/mysqld/mysqld.sock w, - /var/run/mysqld/mysqld.sock.lock rw, - /run/mysqld/mysqld.pid rw, - /run/mysqld/mysqld.sock w, - /run/mysqld/mysqld.sock.lock rw, - - /sys/devices/system/cpu/ r, - - # Site-specific additions and overrides. See local/README for details. - #include -} diff --git a/templates/default/apparmor/ubuntu-16.04/usr.sbin.mysqld.erb b/templates/default/apparmor/ubuntu-16.04/usr.sbin.mysqld.erb deleted file mode 100644 index 2619e7d39..000000000 --- a/templates/default/apparmor/ubuntu-16.04/usr.sbin.mysqld.erb +++ /dev/null @@ -1,68 +0,0 @@ -# vim:syntax=apparmor -# Last Modified: Tue Feb 09 15:28:30 2016 -#include - -/usr/sbin/mysqld { - #include - #include - #include - #include - #include - -# Allow system resource access - /sys/devices/system/cpu/ r, - capability sys_resource, - capability dac_override, - capability setuid, - capability setgid, - -# Allow network access - network tcp, - - /etc/hosts.allow r, - /etc/hosts.deny r, - -# Allow config access - /etc/mysql/** r, - -# Allow pid, socket, socket lock file access - /var/run/mysqld/mysqld.pid rw, - /var/run/mysqld/mysqld.sock rw, - /var/run/mysqld/mysqld.sock.lock rw, - /run/mysqld/mysqld.pid rw, - /run/mysqld/mysqld.sock rw, - /run/mysqld/mysqld.sock.lock rw, - -# Allow execution of server binary - /usr/sbin/mysqld mr, - /usr/sbin/mysqld-debug mr, - -# Allow plugin access - /usr/lib/mysql/plugin/ r, - /usr/lib/mysql/plugin/*.so* mr, - -# Allow error msg and charset access - /usr/share/mysql/ r, - /usr/share/mysql/** r, - -# Allow data dir access - /var/lib/mysql/ r, - /var/lib/mysql/** rwk, - -# Allow data files dir access - /var/lib/mysql-files/ r, - /var/lib/mysql-files/** rwk, - -# Allow keyring dir access - /var/lib/mysql-keyring/ r, - /var/lib/mysql-keyring/** rwk, - -# Allow log file access - /var/log/mysql.err rw, - /var/log/mysql.log rw, - /var/log/mysql/ r, - /var/log/mysql/** rw, - - # Site-specific additions and overrides. See local/README for details. - #include -} diff --git a/templates/default/apparmor/ubuntu-18.04/usr.sbin.mysqld.erb b/templates/default/apparmor/ubuntu-18.04/usr.sbin.mysqld.erb deleted file mode 100644 index 2619e7d39..000000000 --- a/templates/default/apparmor/ubuntu-18.04/usr.sbin.mysqld.erb +++ /dev/null @@ -1,68 +0,0 @@ -# vim:syntax=apparmor -# Last Modified: Tue Feb 09 15:28:30 2016 -#include - -/usr/sbin/mysqld { - #include - #include - #include - #include - #include - -# Allow system resource access - /sys/devices/system/cpu/ r, - capability sys_resource, - capability dac_override, - capability setuid, - capability setgid, - -# Allow network access - network tcp, - - /etc/hosts.allow r, - /etc/hosts.deny r, - -# Allow config access - /etc/mysql/** r, - -# Allow pid, socket, socket lock file access - /var/run/mysqld/mysqld.pid rw, - /var/run/mysqld/mysqld.sock rw, - /var/run/mysqld/mysqld.sock.lock rw, - /run/mysqld/mysqld.pid rw, - /run/mysqld/mysqld.sock rw, - /run/mysqld/mysqld.sock.lock rw, - -# Allow execution of server binary - /usr/sbin/mysqld mr, - /usr/sbin/mysqld-debug mr, - -# Allow plugin access - /usr/lib/mysql/plugin/ r, - /usr/lib/mysql/plugin/*.so* mr, - -# Allow error msg and charset access - /usr/share/mysql/ r, - /usr/share/mysql/** r, - -# Allow data dir access - /var/lib/mysql/ r, - /var/lib/mysql/** rwk, - -# Allow data files dir access - /var/lib/mysql-files/ r, - /var/lib/mysql-files/** rwk, - -# Allow keyring dir access - /var/lib/mysql-keyring/ r, - /var/lib/mysql-keyring/** rwk, - -# Allow log file access - /var/log/mysql.err rw, - /var/log/mysql.log rw, - /var/log/mysql/ r, - /var/log/mysql/** rw, - - # Site-specific additions and overrides. See local/README for details. - #include -} diff --git a/test/cookbooks/test/templates/default/replication-slave.erb b/test/cookbooks/test/templates/default/replication--replica.erb similarity index 100% rename from test/cookbooks/test/templates/default/replication-slave.erb rename to test/cookbooks/test/templates/default/replication--replica.erb diff --git a/test/cookbooks/test/templates/default/replication-master.erb b/test/cookbooks/test/templates/default/replication-primary.erb similarity index 100% rename from test/cookbooks/test/templates/default/replication-master.erb rename to test/cookbooks/test/templates/default/replication-primary.erb From 0b258d9ff810fc2247f8899df94734e681b643b7 Mon Sep 17 00:00:00 2001 From: Dan Webb Date: Thu, 2 May 2024 14:47:42 +0100 Subject: [PATCH 15/16] Fixup package name Signed-off-by: Dan Webb --- libraries/helpers.rb | 2 +- spec/mysql_server_installation_package_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/helpers.rb b/libraries/helpers.rb index 6ccc8f237..2d5588b8e 100644 --- a/libraries/helpers.rb +++ b/libraries/helpers.rb @@ -100,7 +100,7 @@ def default_client_package_name def default_server_package_name return 'mysql-server-8.0' if major_version == '8.0' && platform_family?('debian') - 'mysql-community-server' + 'mysql-server' end def socket_dir diff --git a/spec/mysql_server_installation_package_spec.rb b/spec/mysql_server_installation_package_spec.rb index 50f8ab20c..5cea265bf 100644 --- a/spec/mysql_server_installation_package_spec.rb +++ b/spec/mysql_server_installation_package_spec.rb @@ -11,7 +11,7 @@ installation_server_package_centos_8.converge(described_recipe) expect(installation_server_package_centos_8).to install_mysql_server_installation_package('default').with( version: '8.0', - package_name: 'mysql-community-server' + package_name: 'mysql-server' ) end end From 6fb5bb893f95f0f979fca246f93de633673c0538 Mon Sep 17 00:00:00 2001 From: Dan Webb Date: Thu, 2 May 2024 15:34:25 +0100 Subject: [PATCH 16/16] Push what I've got but we're looking at a table flip Signed-off-by: Dan Webb --- libraries/helpers.rb | 3 +- libraries/mysql_service.rb | 22 ++-- libraries/mysql_service_manager_systemd.rb | 33 +++--- libraries/mysql_service_manager_sysvinit.rb | 80 -------------- libraries/mysql_service_manager_upstart.rb | 104 ------------------- templates/default/systemd/mysqld.service.erb | 18 ---- test/cookbooks/test/recipes/user_database.rb | 2 - test/cookbooks/test/recipes/yum_repo.rb | 10 +- 8 files changed, 29 insertions(+), 243 deletions(-) delete mode 100644 libraries/mysql_service_manager_sysvinit.rb delete mode 100644 libraries/mysql_service_manager_upstart.rb diff --git a/libraries/helpers.rb b/libraries/helpers.rb index 2d5588b8e..b6e83e676 100644 --- a/libraries/helpers.rb +++ b/libraries/helpers.rb @@ -260,8 +260,7 @@ def mysqld_bin end def mysql_systemd_start_pre - return '/usr/bin/mysqld_pre_systemd' if el7? || el8? || fedora? - return '/usr/bin/mysql-systemd-start pre' if platform_family?('rhel') + return '/usr/bin/mysqld_pre_systemd' if el7? || el8? || fedora? || platform_family?('rhel') return '/usr/lib/mysql/mysql-systemd-helper install' if suse? '/usr/share/mysql/mysql-systemd-start pre' diff --git a/libraries/mysql_service.rb b/libraries/mysql_service.rb index fdd151794..68536e670 100644 --- a/libraries/mysql_service.rb +++ b/libraries/mysql_service.rb @@ -6,14 +6,13 @@ class MysqlService < MysqlServiceBase # installation type and service_manager property :install_method, %w(package auto none), default: 'auto', desired_state: false - property :service_manager, %w(sysvinit upstart systemd auto), default: 'auto', desired_state: false # mysql_server_installation property :version, String, default: '8.0', desired_state: false property :major_version, String, default: lazy { major_from_full(version) }, desired_state: false property :package_name, String, default: lazy { default_package_name }, desired_state: false - property :package_options, [String, nil], desired_state: false - property :package_version, [String, nil], desired_state: false + property :package_options, String, desired_state: false + property :package_version, String, desired_state: false ################ # Helper Methods @@ -24,13 +23,12 @@ def copy_properties_to(to, *properties) properties.each do |p| # If the property is set on from, and exists on to, set the # property on to - if to.class.properties.include?(p) && property_is_set?(p) - to.send(p, send(p)) - end + to.send(p, send(p)) if to.class.properties.include?(p) && property_is_set?(p) end end action_class do + # rubocop:disable Metrics/MethodLength def installation(&block) case new_resource.install_method when 'auto' @@ -44,18 +42,10 @@ def installation(&block) copy_properties_to(install) install end + # rubocop:enable Metrics/MethodLength def svc_manager(&block) - case new_resource.service_manager - when 'auto' - svc = mysql_service_manager(new_resource.name, &block) - when 'sysvinit' - svc = mysql_service_manager_sysvinit(new_resource.name, &block) - when 'upstart' - svc = mysql_service_manager_upstart(new_resource.name, &block) - when 'systemd' - svc = mysql_service_manager_systemd(new_resource.name, &block) - end + svc = mysql_service_manager_systemd(new_resource.name, &block) copy_properties_to(svc) svc end diff --git a/libraries/mysql_service_manager_systemd.rb b/libraries/mysql_service_manager_systemd.rb index acf46f1c4..1a9eb1c54 100644 --- a/libraries/mysql_service_manager_systemd.rb +++ b/libraries/mysql_service_manager_systemd.rb @@ -1,4 +1,6 @@ +# rubocop:disable Style/FrozenStringLiteralComment module MysqlCookbook + # rubocop:disable Metrics/ClassLength, Style/Documentation class MysqlServiceManagerSystemd < MysqlServiceBase resource_name :mysql_service_manager_systemd provides :mysql_service_manager_systemd @@ -16,6 +18,7 @@ class MysqlServiceManagerSystemd < MysqlServiceBase initialize_database end + # rubocop:disable Metrics/BlockLength action :start do # Needed for Debian / Ubuntu directory '/usr/libexec' do @@ -38,24 +41,19 @@ class MysqlServiceManagerSystemd < MysqlServiceBase action :create end - # this is the main systemd unit file - template "/etc/systemd/system/#{mysql_name}.service" do - path "/etc/systemd/system/#{mysql_name}.service" + # Use an override.conf so that we override the values we care about and + # let the package do the heavy lifting + # this stops us from breaking during upgrades as we have done before + template '/etc/systemd/system/mysqld.service.d/override.conf' do + path '/etc/systemd/system/mysqld.service.d/override.conf' source 'systemd/mysqld.service.erb' owner 'root' group 'root' mode '0644' - variables( - config: new_resource, - etc_dir: etc_dir, - base_dir: base_dir, - mysqld_bin: mysqld_bin, - mysql_systemd_start_pre: mysql_systemd_start_pre, - mysql_systemd: mysql_systemd - ) + variables(config: new_resource) cookbook 'mysql' notifies :run, "execute[#{new_resource.instance} systemctl daemon-reload]", :immediately - action :create + action :nothing end # avoid 'Unit file changed on disk' warning @@ -85,9 +83,10 @@ class MysqlServiceManagerSystemd < MysqlServiceBase service_name mysql_name provider Chef::Provider::Service::Systemd supports restart: true, status: true - action [:enable, :start] + action %i[enable start] end end + # rubocop:enable Metrics/BlockLength action :stop do # service management resource @@ -95,7 +94,7 @@ class MysqlServiceManagerSystemd < MysqlServiceBase service_name mysql_name provider Chef::Provider::Service::Systemd supports status: true - action [:disable, :stop] + action %i[disable stop] only_if { ::File.exist?("/usr/lib/systemd/system/#{mysql_name}.service") } end end @@ -126,7 +125,7 @@ def stop_system_service service_name system_service_name provider Chef::Provider::Service::Systemd supports status: true - action [:stop, :disable] + action %i[disable stop] end end @@ -136,10 +135,12 @@ def delete_stop_service service_name mysql_name provider Chef::Provider::Service::Systemd supports status: true - action [:disable, :stop] + action %i[disable stop] only_if { ::File.exist?("/usr/lib/systemd/system/#{mysql_name}.service") } end end end end + # rubocop:enable Metrics/ClassLength, Style/Documentation end +# rubocop:enable Style/FrozenStringLiteralComment diff --git a/libraries/mysql_service_manager_sysvinit.rb b/libraries/mysql_service_manager_sysvinit.rb deleted file mode 100644 index 563ab77c9..000000000 --- a/libraries/mysql_service_manager_sysvinit.rb +++ /dev/null @@ -1,80 +0,0 @@ -module MysqlCookbook - class MysqlServiceManagerSysvinit < MysqlServiceBase - resource_name :mysql_service_manager_sysvinit - provides :mysql_service_manager_sysvinit - - provides :mysql_service_manager, os: 'linux' - - action :create do - # from base - create_system_user - stop_system_service - create_config - initialize_database - configure_apparmor - end - - action :start do - template "/etc/init.d/#{mysql_name}" do - source 'sysvinit/mysqld.erb' - owner 'root' - group 'root' - mode '0755' - variables( - config: new_resource, - defaults_file: defaults_file, - error_log: new_resource.error_log, - mysql_name: mysql_name, - mysqladmin_bin: mysqladmin_bin, - mysqld_safe_bin: mysqld_safe_bin, - pid_file: new_resource.pid_file, - scl_name: scl_name - ) - cookbook 'mysql' - action :create - end - - service mysql_name do - supports restart: true, status: true - action [:enable, :start] - end - end - - action :stop do - service mysql_name do - supports restart: true, status: true - action [:stop] - end - end - - action :restart do - service mysql_name do - supports restart: true - action :restart - end - end - - action :reload do - service mysql_name do - action :reload - end - end - - action_class do - def stop_system_service - service system_service_name do - supports status: true - action [:stop, :disable] - end - end - - def delete_stop_service - service mysql_name do - supports status: true - action [:disable, :stop] - only_if { ::File.exist?("#{etc_dir}/init.d/#{mysql_name}") } - end - end - end - end -end diff --git a/libraries/mysql_service_manager_upstart.rb b/libraries/mysql_service_manager_upstart.rb deleted file mode 100644 index f547e3516..000000000 --- a/libraries/mysql_service_manager_upstart.rb +++ /dev/null @@ -1,104 +0,0 @@ -module MysqlCookbook - class MysqlServiceManagerUpstart < MysqlServiceBase - resource_name :mysql_service_manager_upstart - provides :mysql_service_manager_upstart - - provides :mysql_service_manager, platform_family: 'debian' do |_node| - Chef::Platform::ServiceHelpers.service_resource_providers.include?(:upstart) && - !Chef::Platform::ServiceHelpers.service_resource_providers.include?(:systemd) && - !Chef::Platform::ServiceHelpers.service_resource_providers.include?(:redhat) && - ::File.exist?('/sbin/status') # Fix for Docker, in 7 and 8 images /sbin/status doesn't exists and Upstart provider doesn't work - end - - action :create do - # from base - create_system_user - stop_system_service - create_config - configure_apparmor - initialize_database - end - - action :start do - template "/usr/sbin/#{mysql_name}-wait-ready" do - source 'upstart/mysqld-wait-ready.erb' - owner 'root' - group 'root' - mode '0755' - variables(socket_file: socket_file) - cookbook 'mysql' - action :create - end - - template "/etc/init/#{mysql_name}.conf" do - source 'upstart/mysqld.erb' - owner 'root' - group 'root' - mode '0644' - variables( - defaults_file: defaults_file, - mysql_name: mysql_name, - run_group: new_resource.run_group, - run_user: new_resource.run_user, - socket_dir: new_resource.socket_dir - ) - cookbook 'mysql' - action :create - end - - service mysql_name do - provider Chef::Provider::Service::Upstart - supports status: true - action [:start] - end - end - - action :stop do - service mysql_name do - provider Chef::Provider::Service::Upstart - supports restart: true, status: true - action [:stop] - end - end - - action :restart do - # With Upstart, restarting the service doesn't behave "as expected". - # We want the post-start stanzas, which wait until the - # service is available before returning - # - # http://upstart.ubuntu.com/cookbook/#restart - service mysql_name do - provider Chef::Provider::Service::Upstart - action [:stop, :start] - end - end - - action :reload do - # With Upstart, reload just sends a HUP signal to the process. - # As far as I can tell, this doesn't work the way it's - # supposed to, so we need to actually restart the service. - service mysql_name do - provider Chef::Provider::Service::Upstart - action [:stop, :start] - end - end - - action_class do - def stop_system_service - service system_service_name do - provider Chef::Provider::Service::Upstart - supports status: true - action [:stop, :disable] - end - end - - def delete_stop_service - service mysql_name do - provider Chef::Provider::Service::Upstart - action [:disable, :stop] - only_if { ::File.exist?("#{etc_dir}/init/#{mysql_name}") } - end - end - end - end -end diff --git a/templates/default/systemd/mysqld.service.erb b/templates/default/systemd/mysqld.service.erb index 1a5cd417c..9721b5302 100644 --- a/templates/default/systemd/mysqld.service.erb +++ b/templates/default/systemd/mysqld.service.erb @@ -1,21 +1,3 @@ -[Unit] -Description=mysql_service[mysql-<%= @config.instance %>] -After=syslog.target -After=network.target - [Service] -Type=simple User=<%= @config.run_user %> Group=<%= @config.run_group %> -PermissionsStartOnly=true -ExecStartPre=<%= @mysql_systemd_start_pre %> - -ExecStart=<%= @mysqld_bin %> --defaults-file=<%= @etc_dir %>/my.cnf --basedir=<%= @base_dir %> -ExecStartPost=<%= @mysql_systemd %> -TimeoutSec=300 -Restart=on-failure -RuntimeDirectory=mysqld -RuntimeDirectoryMode=755 - -[Install] -WantedBy=multi-user.target diff --git a/test/cookbooks/test/recipes/user_database.rb b/test/cookbooks/test/recipes/user_database.rb index 8514b40d4..e2bba6063 100644 --- a/test/cookbooks/test/recipes/user_database.rb +++ b/test/cookbooks/test/recipes/user_database.rb @@ -1,7 +1,5 @@ ::Chef::DSL::Recipe.include MysqlCookbook::HashedPassword::Helper -include_recipe 'test::yum_repo' - # variables root_pass = 'arandompassword' diff --git a/test/cookbooks/test/recipes/yum_repo.rb b/test/cookbooks/test/recipes/yum_repo.rb index 7c96c05ba..48f8ddd73 100644 --- a/test/cookbooks/test/recipes/yum_repo.rb +++ b/test/cookbooks/test/recipes/yum_repo.rb @@ -1,7 +1,7 @@ # Before that, we use "native" versions -# unless node['mysql_test'].nil? || platform_family?('debian') -# yum_mysql_community_repo 'mysql_repo' do -# version node['mysql_test']['version'] -# end -# end +unless node['mysql_test'].nil? || platform_family?('debian') + yum_mysql_community_repo 'mysql_repo' do + version node['mysql_test']['version'] + end +end