From 443aabcd58bce672f99459a016236663c9bef797 Mon Sep 17 00:00:00 2001 From: Nicolas Rochelemagne Date: Thu, 7 Sep 2023 15:59:57 -0400 Subject: [PATCH 1/3] Add an extra buffer to let MySQL upgrade succeeds --- lib/Elevate/Components/MySQL.pm | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/Elevate/Components/MySQL.pm b/lib/Elevate/Components/MySQL.pm index c16c6a04..3cb2acaa 100644 --- a/lib/Elevate/Components/MySQL.pm +++ b/lib/Elevate/Components/MySQL.pm @@ -18,6 +18,7 @@ use Log::Log4perl qw(:easy); use parent qw{Elevate::Components::Base}; my $cnf_file = '/etc/my.cnf'; + sub pre_leapp ($self) { $self->run_once("_cleanup_mysql_packages"); @@ -62,7 +63,7 @@ sub _cleanup_mysql_packages ($self) { sub _reinstall_mysql_packages { my $mysql_version = cpev::read_stage_file( 'mysql-version', '' ) or return; - my $enabled = cpev::read_stage_file( 'mysql-enabled', '' ) or return; + my $enabled = cpev::read_stage_file( 'mysql-enabled', '' ) or return; INFO("Restoring MySQL $mysql_version"); @@ -73,9 +74,10 @@ sub _reinstall_mysql_packages { INFO("Restoring $cnf_file.rpmsave_pre_elevate to $cnf_file..."); File::Copy::copy( "$cnf_file.rpmsave_pre_elevate", $cnf_file ) or WARN("Couldn't restore $cnf_file.rpmsave: $!"); - if( !$enabled ) { + if ( !$enabled ) { INFO("MySQL is not enabled. This will cause the MySQL upgrade tool to fail. Temporarily enabling it to ensure the upgrade succeeds."); - Cpanel::SafeRun::Simple::saferunnoerror( qw{/usr/local/cpanel/bin/whmapi1 configureservice service=mysql enabled=1} ); + Cpanel::SafeRun::Simple::saferunnoerror(qw{/usr/local/cpanel/bin/whmapi1 configureservice service=mysql enabled=1}); + # Pray it goes ok, as what exactly do you want me to do if this reports failure? May as well just move forward in this case without checking. } @@ -92,10 +94,11 @@ sub _reinstall_mysql_packages { my $c = 0; + my $wait_more = 30; while (1) { $c = ( $c + 1 ) % 10; $out = Cpanel::SafeRun::Simple::saferunnoerror( qw{/usr/local/cpanel/bin/whmapi1 background_mysql_upgrade_status }, "upgrade_id=$id" ); - if($?) { + if ($?) { last if !$enabled; die qq[Failed to restore MySQL $mysql_version: cannot check upgrade_id=$id]; } @@ -110,11 +113,18 @@ sub _reinstall_mysql_packages { if ( $out =~ m{\sstate:\s*(\w+)} ) { $status = $1; } + + # we cannot trust the whmapi1 call (race condition) CPANEL-43253 + if ( $status ne 'success' && --$wait_more > 0 ) { + sleep 1; + next; + } + last; } - print "\n" if $c; # clear the last "." from above - Cpanel::SafeRun::Simple::saferunnoerror( qw{/usr/local/cpanel/bin/whmapi1 configureservice service=mysql enabled=0} ) if !$enabled; + print "\n" if $c; # clear the last "." from above + Cpanel::SafeRun::Simple::saferunnoerror(qw{/usr/local/cpanel/bin/whmapi1 configureservice service=mysql enabled=0}) if !$enabled; if ( $status eq 'success' ) { INFO("MySQL $mysql_version restored"); From b5086fe0ee37142e40bc5bb2875333399c32853f Mon Sep 17 00:00:00 2001 From: Nicolas Rochelemagne Date: Thu, 7 Sep 2023 16:01:09 -0400 Subject: [PATCH 2/3] Give some extra time to check whmapi1 background_mysql_upgrade_status Fix #311 The API call is not reliable... and can show up failure for a short time... give some extra time before checking the status... This is a mitigation --- elevate-cpanel | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/elevate-cpanel b/elevate-cpanel index dc9c7834..fbc5585b 100755 --- a/elevate-cpanel +++ b/elevate-cpanel @@ -3087,6 +3087,7 @@ EOS if ( !$enabled ) { INFO("MySQL is not enabled. This will cause the MySQL upgrade tool to fail. Temporarily enabling it to ensure the upgrade succeeds."); Cpanel::SafeRun::Simple::saferunnoerror(qw{/usr/local/cpanel/bin/whmapi1 configureservice service=mysql enabled=1}); + } my $out = Cpanel::SafeRun::Simple::saferunnoerror( qw{/usr/local/cpanel/bin/whmapi1 start_background_mysql_upgrade}, "version=$mysql_version" ); @@ -3102,6 +3103,7 @@ EOS my $c = 0; + my $wait_more = 30; while (1) { $c = ( $c + 1 ) % 10; $out = Cpanel::SafeRun::Simple::saferunnoerror( qw{/usr/local/cpanel/bin/whmapi1 background_mysql_upgrade_status }, "upgrade_id=$id" ); @@ -3120,6 +3122,12 @@ EOS if ( $out =~ m{\sstate:\s*(\w+)} ) { $status = $1; } + + if ( $status ne 'success' && --$wait_more > 0 ) { + sleep 1; + next; + } + last; } From d6c990259843ad238642bd1e02f9c05db5a0a599 Mon Sep 17 00:00:00 2001 From: Nicolas Rochelemagne Date: Thu, 7 Sep 2023 16:04:59 -0400 Subject: [PATCH 3/3] Do not abort when failing to recover MySQL Fix #311 --- elevate-cpanel | 11 ++++++++--- lib/Elevate/Components/MySQL.pm | 13 +++++++++---- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/elevate-cpanel b/elevate-cpanel index fbc5585b..e873819e 100755 --- a/elevate-cpanel +++ b/elevate-cpanel @@ -3028,8 +3028,9 @@ EOS use File::Copy (); - # use Log::Log4perl qw(:easy); + # use Log::Log4perl qw(:easy); INIT { Log::Log4perl->import(qw{:easy}); } + use Elevate::Notify (); # use Elevate::Components::Base(); our @ISA; @@ -3138,9 +3139,13 @@ EOS INFO("MySQL $mysql_version restored"); } else { - FATAL("Failed to restore MySQL $mysql_version: upgrade $id status '$status'"); + my $msg = "Failed to restore MySQL $mysql_version: upgrade $id status '$status'"; + + FATAL($msg); FATAL("$out"); - die 'Failed to restore MySQL'; + + Elevate::Notify::add_final_notification($msg); + return; } } else { diff --git a/lib/Elevate/Components/MySQL.pm b/lib/Elevate/Components/MySQL.pm index 3cb2acaa..11c7ba8c 100644 --- a/lib/Elevate/Components/MySQL.pm +++ b/lib/Elevate/Components/MySQL.pm @@ -12,8 +12,9 @@ Capture and reinstall MySQL packages. use cPstrict; -use File::Copy (); -use Log::Log4perl qw(:easy); +use File::Copy (); +use Log::Log4perl qw(:easy); +use Elevate::Notify (); use parent qw{Elevate::Components::Base}; @@ -130,9 +131,13 @@ sub _reinstall_mysql_packages { INFO("MySQL $mysql_version restored"); } else { - FATAL("Failed to restore MySQL $mysql_version: upgrade $id status '$status'"); + my $msg = "Failed to restore MySQL $mysql_version: upgrade $id status '$status'"; + + FATAL($msg); FATAL("$out"); - die 'Failed to restore MySQL'; + + Elevate::Notify::add_final_notification($msg); + return; } } else {