From e1b3bdc02621c17328961a7a0586b051bd05f25c Mon Sep 17 00:00:00 2001 From: Manuel Torrinha Date: Thu, 24 Jan 2019 15:54:15 +0000 Subject: [PATCH 01/22] fixes #214 #178 fixes `only_if` and mysql query issues with setting password --- resources/client_install.rb | 2 +- resources/server_install.rb | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/resources/client_install.rb b/resources/client_install.rb index c2a20c7d..630908ef 100644 --- a/resources/client_install.rb +++ b/resources/client_install.rb @@ -22,7 +22,7 @@ action :install do mariadb_repository 'Add mariadb.org repository' do version new_resource.version - only_if { new_resource.setup_repo } + only_if { !new_resource.setup_repo.nil? } end case node['platform_family'] diff --git a/resources/server_install.rb b/resources/server_install.rb index f4049705..058c027c 100644 --- a/resources/server_install.rb +++ b/resources/server_install.rb @@ -54,16 +54,14 @@ mariadb_root_password = new_resource.password == 'generate' || new_resource.password.nil? ? secure_random : new_resource.password - # Generate a ramdom password or set the a password defined with node['mariadb']['password']['root']. + # Generate a random password or set the a password defined with node['mariadb']['server_root_password']. # The password is set or change at each run. It is good for security if you choose to set a random password and # allow you to change the root password if needed. - bash 'generate-mariadb-root-password' do + execute 'generate-mariadb-root-password' do user 'root' - code <<-EOH - echo "ALTER USER 'root'@'localhost' IDENTIFIED BY \'#{mariadb_root_password}\';" | /usr/bin/mysql - EOH + command "/usr/bin/mysql -e \"ALTER USER 'root'@'localhost' IDENTIFIED BY '#{mariadb_root_password}';\"" not_if { ::File.exist? "#{data_dir}/recovery.conf" } - only_if { new_resource.password } + only_if { !new_resource.password.nil? } end end From 2634453772f0cc72bd2c75a068ec9b4b3145ca20 Mon Sep 17 00:00:00 2001 From: Manuel Torrinha Date: Thu, 24 Jan 2019 17:15:12 +0000 Subject: [PATCH 02/22] fixes #214 #178 before starting the service, checks for an initial config file, creates it if it doesn't exist and runs mysqld with init-file argument --- resources/server_install.rb | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/resources/server_install.rb b/resources/server_install.rb index 058c027c..402234ea 100644 --- a/resources/server_install.rb +++ b/resources/server_install.rb @@ -49,6 +49,9 @@ log 'Enable and start MariaDB service' do notifies :enable, "service[#{platform_service_name}]", :immediately + notifies :stop, "service[#{platform_service_name}]", :immediately + notifies :run, 'file[generate-mariadb-root-password]', :immediately + notifies :run, 'execute[apply-mariadb-root-password]', :immediately notifies :start, "service[#{platform_service_name}]", :immediately end @@ -57,11 +60,20 @@ # Generate a random password or set the a password defined with node['mariadb']['server_root_password']. # The password is set or change at each run. It is good for security if you choose to set a random password and # allow you to change the root password if needed. - execute 'generate-mariadb-root-password' do - user 'root' - command "/usr/bin/mysql -e \"ALTER USER 'root'@'localhost' IDENTIFIED BY '#{mariadb_root_password}';\"" + file 'generate-mariadb-root-password' do + owner 'root' + group 'root' + mode '600' + sensitive true + content "ALTER USER 'root'@'localhost' IDENTIFIED BY '#{mariadb_root_password}';" + action :create not_if { ::File.exist? "#{data_dir}/recovery.conf" } - only_if { !new_resource.password.nil? } + end + + execute 'apply-mariadb-root-password' do + user 'root' + command "/usr/sbin/mysqld --init-file=#{data_dir}/recovery.conf" + only_if { ::File.exist? "#{data_dir}/recovery.conf" } end end From 97ab5ee57edbf1c81a72f6eb764d3ca28f1fc65c Mon Sep 17 00:00:00 2001 From: Manuel Torrinha Date: Thu, 24 Jan 2019 17:18:07 +0000 Subject: [PATCH 03/22] fixes #214 #178 minor fix --- resources/server_install.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/resources/server_install.rb b/resources/server_install.rb index 402234ea..05ae5726 100644 --- a/resources/server_install.rb +++ b/resources/server_install.rb @@ -66,7 +66,6 @@ mode '600' sensitive true content "ALTER USER 'root'@'localhost' IDENTIFIED BY '#{mariadb_root_password}';" - action :create not_if { ::File.exist? "#{data_dir}/recovery.conf" } end From e4d46178414b9b561ebf44caa10a4fa3e2541702 Mon Sep 17 00:00:00 2001 From: Manuel Torrinha Date: Thu, 24 Jan 2019 17:21:19 +0000 Subject: [PATCH 04/22] fixes #214 #178 minor fix, file has :create, not :run... --- resources/server_install.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/server_install.rb b/resources/server_install.rb index 05ae5726..4ed74b0a 100644 --- a/resources/server_install.rb +++ b/resources/server_install.rb @@ -50,7 +50,7 @@ log 'Enable and start MariaDB service' do notifies :enable, "service[#{platform_service_name}]", :immediately notifies :stop, "service[#{platform_service_name}]", :immediately - notifies :run, 'file[generate-mariadb-root-password]', :immediately + notifies :create, 'file[generate-mariadb-root-password]', :immediately notifies :run, 'execute[apply-mariadb-root-password]', :immediately notifies :start, "service[#{platform_service_name}]", :immediately end From f0c29fcf54c1712949280591a0f1cdbf921e4a4f Mon Sep 17 00:00:00 2001 From: Manuel Torrinha Date: Thu, 24 Jan 2019 19:12:38 +0000 Subject: [PATCH 05/22] fixes #214 path got lost somewhere in time --- resources/server_install.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/server_install.rb b/resources/server_install.rb index 4ed74b0a..a0d9e2b2 100644 --- a/resources/server_install.rb +++ b/resources/server_install.rb @@ -61,6 +61,7 @@ # The password is set or change at each run. It is good for security if you choose to set a random password and # allow you to change the root password if needed. file 'generate-mariadb-root-password' do + path "#{data_dir}/recovery.conf" owner 'root' group 'root' mode '600' From 4ba12f4ba433711c968208aeba85239d47c9e7d4 Mon Sep 17 00:00:00 2001 From: Manuel Torrinha Date: Fri, 25 Jan 2019 10:48:27 +0000 Subject: [PATCH 06/22] fixes #214 Updated mysqld command to run as root for setting the initial password as per https://dev.mysql.com/doc/refman/5.7/en/changing-mysql-user.html --- resources/server_install.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/server_install.rb b/resources/server_install.rb index a0d9e2b2..71e49704 100644 --- a/resources/server_install.rb +++ b/resources/server_install.rb @@ -72,7 +72,7 @@ execute 'apply-mariadb-root-password' do user 'root' - command "/usr/sbin/mysqld --init-file=#{data_dir}/recovery.conf" + command "/usr/sbin/mysqld --user=root --init-file=#{data_dir}/recovery.conf" only_if { ::File.exist? "#{data_dir}/recovery.conf" } end end From 42bd0bc56e671f87fbd77a0cce549613202be9d4 Mon Sep 17 00:00:00 2001 From: Manuel Torrinha Date: Fri, 25 Jan 2019 12:45:58 +0000 Subject: [PATCH 07/22] fixes #214 updates root password, and verifies it was updated --- resources/server_install.rb | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/resources/server_install.rb b/resources/server_install.rb index 71e49704..c2850894 100644 --- a/resources/server_install.rb +++ b/resources/server_install.rb @@ -50,21 +50,23 @@ log 'Enable and start MariaDB service' do notifies :enable, "service[#{platform_service_name}]", :immediately notifies :stop, "service[#{platform_service_name}]", :immediately - notifies :create, 'file[generate-mariadb-root-password]', :immediately notifies :run, 'execute[apply-mariadb-root-password]', :immediately - notifies :start, "service[#{platform_service_name}]", :immediately + notifies :start, "service[#{platform_service_name}]", :delayed end - mariadb_root_password = new_resource.password == 'generate' || new_resource.password.nil? ? secure_random : new_resource.password + # here we want to generate a new password if: 1- the user passed 'generate' to the password argument + # 2- the user did not pass anything to the password argument OR + # the user did not define node['mariadb']['server_root_password'] attribute + mariadb_root_password = (new_resource.password == 'generate' || (new_resource.password.nil? && node['mariadb']['server_root_password'].nil?)) ? secure_random : new_resource.password - # Generate a random password or set the a password defined with node['mariadb']['server_root_password']. + # Generate a random password or set a password defined with node['mariadb']['server_root_password']. # The password is set or change at each run. It is good for security if you choose to set a random password and # allow you to change the root password if needed. file 'generate-mariadb-root-password' do path "#{data_dir}/recovery.conf" - owner 'root' + owner 'mysql' group 'root' - mode '600' + mode '640' sensitive true content "ALTER USER 'root'@'localhost' IDENTIFIED BY '#{mariadb_root_password}';" not_if { ::File.exist? "#{data_dir}/recovery.conf" } @@ -72,8 +74,15 @@ execute 'apply-mariadb-root-password' do user 'root' - command "/usr/sbin/mysqld --user=root --init-file=#{data_dir}/recovery.conf" + command "/usr/sbin/mysqld --init-file=#{data_dir}/recovery.conf&>/dev/null&" only_if { ::File.exist? "#{data_dir}/recovery.conf" } + notifies :create, 'file[generate-mariadb-root-password]', :before + notifies :run, 'execute[ensure-root-password-okay]', :immediately + end + + execute 'verify-root-password-okay' do + user 'root' + command "mysql -p#{mariadb_root_password} -e '\s'&>/dev/null && kill `cat #{external_pid_file}`" end end From 89870628048f7e13dd4f855a387aedc1cc990cd8 Mon Sep 17 00:00:00 2001 From: Manuel Torrinha Date: Fri, 25 Jan 2019 14:19:08 +0000 Subject: [PATCH 08/22] fixes #214 added failsafe to make sure the mysql service is not running --- resources/server_install.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/resources/server_install.rb b/resources/server_install.rb index c2850894..3b5275ea 100644 --- a/resources/server_install.rb +++ b/resources/server_install.rb @@ -72,14 +72,16 @@ not_if { ::File.exist? "#{data_dir}/recovery.conf" } end + # make sure that mysqld is not running, and then set the root password execute 'apply-mariadb-root-password' do user 'root' - command "/usr/sbin/mysqld --init-file=#{data_dir}/recovery.conf&>/dev/null&" + command "kill `cat #{external_pid_file}` && /usr/sbin/mysqld --init-file=#{data_dir}/recovery.conf&>/dev/null&" only_if { ::File.exist? "#{data_dir}/recovery.conf" } notifies :create, 'file[generate-mariadb-root-password]', :before notifies :run, 'execute[ensure-root-password-okay]', :immediately end + # make sure the password was properly set execute 'verify-root-password-okay' do user 'root' command "mysql -p#{mariadb_root_password} -e '\s'&>/dev/null && kill `cat #{external_pid_file}`" From 189cd639cf2eb1fb7e8906c016f9faf79703ba2e Mon Sep 17 00:00:00 2001 From: Manuel Torrinha Date: Fri, 25 Jan 2019 14:32:02 +0000 Subject: [PATCH 09/22] fixes #214 added failsafe to make sure the mysql service is not running --- resources/server_install.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/resources/server_install.rb b/resources/server_install.rb index 3b5275ea..b9a98516 100644 --- a/resources/server_install.rb +++ b/resources/server_install.rb @@ -72,10 +72,12 @@ not_if { ::File.exist? "#{data_dir}/recovery.conf" } end + pid_file = default_pid_file.nil? ? '/var/run/mysql/mysqld.pid' : default_pid_file + # make sure that mysqld is not running, and then set the root password execute 'apply-mariadb-root-password' do user 'root' - command "kill `cat #{external_pid_file}` && /usr/sbin/mysqld --init-file=#{data_dir}/recovery.conf&>/dev/null&" + command "kill `cat #{pid_file}`; /usr/sbin/mysqld --init-file=#{data_dir}/recovery.conf&>/dev/null&" only_if { ::File.exist? "#{data_dir}/recovery.conf" } notifies :create, 'file[generate-mariadb-root-password]', :before notifies :run, 'execute[ensure-root-password-okay]', :immediately @@ -84,7 +86,7 @@ # make sure the password was properly set execute 'verify-root-password-okay' do user 'root' - command "mysql -p#{mariadb_root_password} -e '\s'&>/dev/null && kill `cat #{external_pid_file}`" + command "mysql -p#{mariadb_root_password} -e '\s'&>/dev/null && kill `cat #{pid_file}`" end end From 8e7414a63a6bc6a89905d98c2161f7ec86d70e3c Mon Sep 17 00:00:00 2001 From: Manuel Torrinha Date: Fri, 25 Jan 2019 14:32:53 +0000 Subject: [PATCH 10/22] fixes #214 added failsafe to make sure the mysql service is not running --- resources/server_install.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/server_install.rb b/resources/server_install.rb index b9a98516..5d4e2be9 100644 --- a/resources/server_install.rb +++ b/resources/server_install.rb @@ -80,7 +80,7 @@ command "kill `cat #{pid_file}`; /usr/sbin/mysqld --init-file=#{data_dir}/recovery.conf&>/dev/null&" only_if { ::File.exist? "#{data_dir}/recovery.conf" } notifies :create, 'file[generate-mariadb-root-password]', :before - notifies :run, 'execute[ensure-root-password-okay]', :immediately + notifies :run, 'execute[verify-root-password-okay]', :immediately end # make sure the password was properly set From bd97c98200495ad74b8659bf0946e88d2baa119c Mon Sep 17 00:00:00 2001 From: Manuel Torrinha Date: Fri, 25 Jan 2019 15:15:52 +0000 Subject: [PATCH 11/22] fixes #214 removed reload support as mariadb service does not support it and can be misleading --- test/cookbooks/test/recipes/server_install.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cookbooks/test/recipes/server_install.rb b/test/cookbooks/test/recipes/server_install.rb index cb3ebce6..89526200 100644 --- a/test/cookbooks/test/recipes/server_install.rb +++ b/test/cookbooks/test/recipes/server_install.rb @@ -9,6 +9,6 @@ find_resource(:service, 'mariadb') do extend MariaDBCookbook::Helpers service_name lazy { platform_service_name } - supports restart: true, status: true, reload: true + supports restart: true, status: true action [:enable, :start] end From f448777ca23335b08cc6319ff1dddf55407a1bb8 Mon Sep 17 00:00:00 2001 From: Manuel Torrinha Date: Fri, 25 Jan 2019 15:37:20 +0000 Subject: [PATCH 12/22] fixes #214 added presence test for pid_file --- resources/server_install.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/server_install.rb b/resources/server_install.rb index 5d4e2be9..086fe530 100644 --- a/resources/server_install.rb +++ b/resources/server_install.rb @@ -77,7 +77,7 @@ # make sure that mysqld is not running, and then set the root password execute 'apply-mariadb-root-password' do user 'root' - command "kill `cat #{pid_file}`; /usr/sbin/mysqld --init-file=#{data_dir}/recovery.conf&>/dev/null&" + command "(test -f #{pid_file} && kill $(< #{pid_file})); /usr/sbin/mysqld --init-file=#{data_dir}/recovery.conf&>/dev/null&" only_if { ::File.exist? "#{data_dir}/recovery.conf" } notifies :create, 'file[generate-mariadb-root-password]', :before notifies :run, 'execute[verify-root-password-okay]', :immediately @@ -86,7 +86,7 @@ # make sure the password was properly set execute 'verify-root-password-okay' do user 'root' - command "mysql -p#{mariadb_root_password} -e '\s'&>/dev/null && kill `cat #{pid_file}`" + command "mysql -p#{mariadb_root_password} -e '\s'&>/dev/null && kill $(< #{pid_file})" end end From b8fc90122b327c6bfb3245de26001381de57c87a Mon Sep 17 00:00:00 2001 From: Manuel Torrinha Date: Fri, 25 Jan 2019 15:43:58 +0000 Subject: [PATCH 13/22] fixes #214 fixing issues with kill --- resources/server_install.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/server_install.rb b/resources/server_install.rb index 086fe530..14577859 100644 --- a/resources/server_install.rb +++ b/resources/server_install.rb @@ -86,7 +86,7 @@ # make sure the password was properly set execute 'verify-root-password-okay' do user 'root' - command "mysql -p#{mariadb_root_password} -e '\s'&>/dev/null && kill $(< #{pid_file})" + command "mysql -p#{mariadb_root_password} -e '\\s'&>/dev/null && kill $(< #{pid_file})" end end From a8f288c13d4433bf26a3a7be411759630d7bdae8 Mon Sep 17 00:00:00 2001 From: Manuel Torrinha Date: Fri, 25 Jan 2019 15:45:13 +0000 Subject: [PATCH 14/22] fixes #214 fixing issues using kill --- resources/server_install.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/server_install.rb b/resources/server_install.rb index 14577859..cf4feef2 100644 --- a/resources/server_install.rb +++ b/resources/server_install.rb @@ -86,7 +86,7 @@ # make sure the password was properly set execute 'verify-root-password-okay' do user 'root' - command "mysql -p#{mariadb_root_password} -e '\\s'&>/dev/null && kill $(< #{pid_file})" + command "mysql -p#{mariadb_root_password} -e '\\s'&>/dev/null && (test -f #{pid_file} && kill $(< #{pid_file}))" end end From 88c8d239110f44119444dbeb5808bd1664ae5c7a Mon Sep 17 00:00:00 2001 From: Manuel Torrinha Date: Fri, 25 Jan 2019 16:16:34 +0000 Subject: [PATCH 15/22] fixes #214 apparently the mysqld service is stopped afterwards --- resources/server_install.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/resources/server_install.rb b/resources/server_install.rb index cf4feef2..3ece05b3 100644 --- a/resources/server_install.rb +++ b/resources/server_install.rb @@ -51,7 +51,8 @@ notifies :enable, "service[#{platform_service_name}]", :immediately notifies :stop, "service[#{platform_service_name}]", :immediately notifies :run, 'execute[apply-mariadb-root-password]', :immediately - notifies :start, "service[#{platform_service_name}]", :delayed + notifies :start, "service[#{platform_service_name}]", :immediately + notifies :run, 'execute[verify-root-password-okay]', :immediately end # here we want to generate a new password if: 1- the user passed 'generate' to the password argument @@ -80,13 +81,12 @@ command "(test -f #{pid_file} && kill $(< #{pid_file})); /usr/sbin/mysqld --init-file=#{data_dir}/recovery.conf&>/dev/null&" only_if { ::File.exist? "#{data_dir}/recovery.conf" } notifies :create, 'file[generate-mariadb-root-password]', :before - notifies :run, 'execute[verify-root-password-okay]', :immediately end # make sure the password was properly set execute 'verify-root-password-okay' do user 'root' - command "mysql -p#{mariadb_root_password} -e '\\s'&>/dev/null && (test -f #{pid_file} && kill $(< #{pid_file}))" + command "mysql -p#{mariadb_root_password} -e '\\s'&>/dev/null" end end From 85ab93938d3a439b30647949f8f34358c1559b78 Mon Sep 17 00:00:00 2001 From: Manuel Torrinha Date: Fri, 25 Jan 2019 17:07:30 +0000 Subject: [PATCH 16/22] fixes #214 improved resource notifications --- resources/server_install.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/resources/server_install.rb b/resources/server_install.rb index 3ece05b3..4bfc4aa0 100644 --- a/resources/server_install.rb +++ b/resources/server_install.rb @@ -70,7 +70,7 @@ mode '640' sensitive true content "ALTER USER 'root'@'localhost' IDENTIFIED BY '#{mariadb_root_password}';" - not_if { ::File.exist? "#{data_dir}/recovery.conf" } + action :nothing end pid_file = default_pid_file.nil? ? '/var/run/mysql/mysqld.pid' : default_pid_file @@ -78,15 +78,17 @@ # make sure that mysqld is not running, and then set the root password execute 'apply-mariadb-root-password' do user 'root' - command "(test -f #{pid_file} && kill $(< #{pid_file})); /usr/sbin/mysqld --init-file=#{data_dir}/recovery.conf&>/dev/null&" + command "(test -f #{pid_file} && kill $(< #{pid_file})); /usr/sbin/mysqld --init-file=#{data_dir}/recovery.conf&>/dev/null&; sleep 2" only_if { ::File.exist? "#{data_dir}/recovery.conf" } notifies :create, 'file[generate-mariadb-root-password]', :before + action :nothing end # make sure the password was properly set execute 'verify-root-password-okay' do user 'root' command "mysql -p#{mariadb_root_password} -e '\\s'&>/dev/null" + action :nothing end end From 2cef57f41f209e9df82e699d5f71ba715376543e Mon Sep 17 00:00:00 2001 From: Manuel Torrinha Date: Fri, 25 Jan 2019 17:15:34 +0000 Subject: [PATCH 17/22] fixes #214 improved resource notifications --- resources/server_install.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/resources/server_install.rb b/resources/server_install.rb index 4bfc4aa0..e80ac0a7 100644 --- a/resources/server_install.rb +++ b/resources/server_install.rb @@ -50,9 +50,7 @@ log 'Enable and start MariaDB service' do notifies :enable, "service[#{platform_service_name}]", :immediately notifies :stop, "service[#{platform_service_name}]", :immediately - notifies :run, 'execute[apply-mariadb-root-password]', :immediately - notifies :start, "service[#{platform_service_name}]", :immediately - notifies :run, 'execute[verify-root-password-okay]', :immediately + notifies :run, "execute[apply-mariadb-root-password]", :immediately end # here we want to generate a new password if: 1- the user passed 'generate' to the password argument @@ -81,6 +79,8 @@ command "(test -f #{pid_file} && kill $(< #{pid_file})); /usr/sbin/mysqld --init-file=#{data_dir}/recovery.conf&>/dev/null&; sleep 2" only_if { ::File.exist? "#{data_dir}/recovery.conf" } notifies :create, 'file[generate-mariadb-root-password]', :before + notifies :start, "service[#{platform_service_name}]", :immediately + notifies :run, "execute[verify-root-password-okay]", :delayed action :nothing end From 10fe4c5151e6a8b802338d6362aef0d534cd597e Mon Sep 17 00:00:00 2001 From: Manuel Torrinha Date: Fri, 25 Jan 2019 17:25:53 +0000 Subject: [PATCH 18/22] fixes #214 removed `only_if` clause, as `generate-mariadb-root-password` resource already creates the file for us and is required by this resource --- resources/server_install.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/resources/server_install.rb b/resources/server_install.rb index e80ac0a7..aec839d3 100644 --- a/resources/server_install.rb +++ b/resources/server_install.rb @@ -77,7 +77,6 @@ execute 'apply-mariadb-root-password' do user 'root' command "(test -f #{pid_file} && kill $(< #{pid_file})); /usr/sbin/mysqld --init-file=#{data_dir}/recovery.conf&>/dev/null&; sleep 2" - only_if { ::File.exist? "#{data_dir}/recovery.conf" } notifies :create, 'file[generate-mariadb-root-password]', :before notifies :start, "service[#{platform_service_name}]", :immediately notifies :run, "execute[verify-root-password-okay]", :delayed From aeccd6a0a948678c2581cdb2d40f2a469b1dd759 Mon Sep 17 00:00:00 2001 From: Manuel Torrinha Date: Fri, 25 Jan 2019 17:32:07 +0000 Subject: [PATCH 19/22] fixes #214 removed `only_if` clause, as `generate-mariadb-root-password` resource already creates the file for us and is required by this resource --- resources/server_install.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/server_install.rb b/resources/server_install.rb index aec839d3..9ba285c2 100644 --- a/resources/server_install.rb +++ b/resources/server_install.rb @@ -76,7 +76,7 @@ # make sure that mysqld is not running, and then set the root password execute 'apply-mariadb-root-password' do user 'root' - command "(test -f #{pid_file} && kill $(< #{pid_file})); /usr/sbin/mysqld --init-file=#{data_dir}/recovery.conf&>/dev/null&; sleep 2" + command "(test -f #{pid_file} && kill $(< #{pid_file})); /usr/sbin/mysqld --init-file=#{data_dir}/recovery.conf&>/dev/null&; sleep 2;" notifies :create, 'file[generate-mariadb-root-password]', :before notifies :start, "service[#{platform_service_name}]", :immediately notifies :run, "execute[verify-root-password-okay]", :delayed From 3ebbba34eb021941520aecd866fd3a6e66ccd71d Mon Sep 17 00:00:00 2001 From: Manuel Torrinha Date: Fri, 25 Jan 2019 17:47:09 +0000 Subject: [PATCH 20/22] fixes #214 working out chef resource behaviour... --- resources/server_install.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/server_install.rb b/resources/server_install.rb index 9ba285c2..905b54b5 100644 --- a/resources/server_install.rb +++ b/resources/server_install.rb @@ -76,7 +76,7 @@ # make sure that mysqld is not running, and then set the root password execute 'apply-mariadb-root-password' do user 'root' - command "(test -f #{pid_file} && kill $(< #{pid_file})); /usr/sbin/mysqld --init-file=#{data_dir}/recovery.conf&>/dev/null&; sleep 2;" + command "(test -f #{pid_file} && kill $(< #{pid_file})) || /usr/sbin/mysqld --init-file=#{data_dir}/recovery.conf&>/dev/null&" notifies :create, 'file[generate-mariadb-root-password]', :before notifies :start, "service[#{platform_service_name}]", :immediately notifies :run, "execute[verify-root-password-okay]", :delayed From f4828c35ff78504016a9e30e8b72961a7f1cef3d Mon Sep 17 00:00:00 2001 From: Manuel Torrinha Date: Fri, 25 Jan 2019 18:12:54 +0000 Subject: [PATCH 21/22] fixes #214 fixes linting --- resources/server_install.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/server_install.rb b/resources/server_install.rb index 905b54b5..c6cdc76f 100644 --- a/resources/server_install.rb +++ b/resources/server_install.rb @@ -50,7 +50,7 @@ log 'Enable and start MariaDB service' do notifies :enable, "service[#{platform_service_name}]", :immediately notifies :stop, "service[#{platform_service_name}]", :immediately - notifies :run, "execute[apply-mariadb-root-password]", :immediately + notifies :run, 'execute[apply-mariadb-root-password]', :immediately end # here we want to generate a new password if: 1- the user passed 'generate' to the password argument @@ -79,7 +79,7 @@ command "(test -f #{pid_file} && kill $(< #{pid_file})) || /usr/sbin/mysqld --init-file=#{data_dir}/recovery.conf&>/dev/null&" notifies :create, 'file[generate-mariadb-root-password]', :before notifies :start, "service[#{platform_service_name}]", :immediately - notifies :run, "execute[verify-root-password-okay]", :delayed + notifies :run, 'execute[verify-root-password-okay]', :delayed action :nothing end From 9a4face65c0f2df2f258c645e5373b69bffd8f64 Mon Sep 17 00:00:00 2001 From: Manuel Torrinha Date: Mon, 28 Jan 2019 11:44:00 +0000 Subject: [PATCH 22/22] fixes #214 bad boolean algebra... it would not apply password if there was any mysqld process to kill --- resources/server_install.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/server_install.rb b/resources/server_install.rb index c6cdc76f..abf97f62 100644 --- a/resources/server_install.rb +++ b/resources/server_install.rb @@ -76,7 +76,7 @@ # make sure that mysqld is not running, and then set the root password execute 'apply-mariadb-root-password' do user 'root' - command "(test -f #{pid_file} && kill $(< #{pid_file})) || /usr/sbin/mysqld --init-file=#{data_dir}/recovery.conf&>/dev/null&" + command "(test -f #{pid_file} && kill $(< #{pid_file})); /usr/sbin/mysqld --init-file=#{data_dir}/recovery.conf&>/dev/null&" notifies :create, 'file[generate-mariadb-root-password]', :before notifies :start, "service[#{platform_service_name}]", :immediately notifies :run, 'execute[verify-root-password-okay]', :delayed