فهرست منبع

Better loggin

Andy Baugh 5 سال پیش
والد
کامیت
d057c44608
1فایلهای تغییر یافته به همراه31 افزوده شده و 19 حذف شده
  1. 31 19
      lib/Troglodyne/API/Postgres.pm

+ 31 - 19
lib/Troglodyne/API/Postgres.pm

@@ -95,13 +95,14 @@ sub _real_install {
     select $lh;
     $| = 1;
     select $lh;
-    print $lh "Beginning install...\n";
+    print $lh "# [INFO] Beginning install...\n";
 
     require Whostmgr::Services;
     require Cpanel::Services::Enabled;
     if( Cpanel::Services::Enabled::is_enabled('postgresql') ) {
-        print $lh "Disabling postgresql during the upgrade window since it is currently enabled...\n";
+        print $lh "# [INFO] Disabling postgresql during the upgrade window since it is currently enabled...\n";
         Whostmgr::Services::disable('postgresql');
+        print $lh "# [INFO] Adding 're-enable postgresql' to \@ROLLBACKS stack...\n"; 
         my $rb = sub { Whostmgr::Services::enable('postgresql'); };
         push @ROLLBACKS, $rb;
     }
@@ -119,12 +120,13 @@ sub _real_install {
         $err = $@;
     }
     if($err) {
-        print $lh "[ERROR] $err\n";
+        print $lh "# [ERROR] $err\n";
         return _cleanup('255');
     }
     if($ccs_installed) {
-        print $lh "\ncpanel-ccs-calendarserver is installed.\nDisabling the service while the upgrade is in process.\n\n";
+        print $lh "# [INFO] cpanel-ccs-calendarserver is installed.\nDisabling the service while the upgrade is in process.\n\n";
         Whostmgr::Services::disable('cpanel-ccs');
+        print $lh "# [INFO] Adding 're-enable cpanel-ccs' to \@ROLLBACKS stack...\n"; 
         my $rb = sub { Whostmgr::Services::enable('cpanel-ccs'); };
         push @ROLLBACKS, $rb;
     }
@@ -132,6 +134,7 @@ sub _real_install {
     require Cpanel::SafeRun::Object;
     my $exit = _saferun( $lh, 'yum', qw{install -y}, @RPMS );
     return _cleanup("$exit") if $exit;
+    print $lh "# [INFO] Adding 'yum remove new pg version' to \@ROLLBACKS stack...\n"; 
     my $rollbck = sub { _saferun( $lh, 'yum', qw{remove -y}, @RPMS ) };
     push @ROLLBACKS, $rollbck;
 
@@ -146,11 +149,12 @@ sub _real_install {
         $err = $@;
     }
     if($err) {
-        print $lh "[ERROR] $err\n";
+        print $lh "# [ERROR] $err\n";
         return _cleanup('255');
     }
     return _cleanup("$exit") if $exit;
     # probably shouldn't do it this way. Whatever
+    print $lh "# [INFO] Adding 'Clean up new pgdata dir' to \@ROLLBACKS stack...\n"; 
     my $rd_rllr = sub { _saferun( $lh, qw{rm -rf}, "/var/lib/pgsql/$ver2install/data" ) };
     push @ROLLBACKS, $rd_rllr;
 
@@ -160,14 +164,15 @@ sub _real_install {
     my @cur_ver = ( Cpanel::PostgresUtils::get_version() );
     my $str_ver = join( '.', @cur_ver );
     if( $str_ver + 0 < 9.4 ) {
-        print $lh "\n\nInstalled version is less than 9.4 ($str_ver), Implementing workaround in pg_ctl to ensure pg_upgrade works...\n";
+        print $lh "# [INFO] Installed version is less than 9.4 ($str_ver), Implementing workaround in pg_ctl to ensure pg_upgrade works...\n";
         require File::Copy;
-        print $lh "Backing up /usr/bin/pg_ctl to /usr/bin/pg_ctl.orig\n";
+        print $lh "# [BACKUP] Backing up /usr/bin/pg_ctl to /usr/bin/pg_ctl.orig\n";
         File::Copy::cp('/usr/bin/pg_ctl','/usr/bin/pg_ctl.orig') or do {
             print $lh "Backup of /usr/bin/pg_ctl to /usr/bin/pg_ctl.orig failed: $!\n";
             return _cleanup("255");
         };
         chmod(0755, '/usr/bin/pg_ctl.orig');
+        print $lh "# [INFO] Adding 'Restore old pg_ctl process to \@ROLLBACKS stack...\n";
         my $rb = sub { File::Copy::mv('/usr/bin/pg_ctl.orig','/usr/bin/pg_ctl'); };
         push @ROLLBACKS, $rb;
 
@@ -178,12 +183,13 @@ sub _real_install {
             chmod( 0755, '/usr/bin/pg_ctl' );
         };
         if($@) {
-            print $lh "[ERROR] Write to /usr/bin/pg_ctl failed: $@\n";
+            print $lh "# [ERROR] Write to /usr/bin/pg_ctl failed: $@\n";
             return _cleanup('255');
         }
-        print $lh "Workaround should be in place now. Proceeding with pg_upgrade.\n\n";
+        print $lh "# [INFO] Workaround should be in place now. Proceeding with pg_upgrade.\n\n";
     }
 
+    print $lh "# [INFO] Setting things up for pg_upgrade -- delete postmaster.pid, ensure .pgpass in place.\n";
     require Cpanel::Chdir;
     # Upgrade the cluster
     # /usr/pgsql-9.6/bin/pg_upgrade --old-datadir /var/lib/pgsql/data/ --new-datadir /var/lib/pgsql/9.6/data/ --old-bindir /usr/bin/ --new-bindir /usr/pgsql-9.6/bin/
@@ -192,12 +198,14 @@ sub _real_install {
 
     # Copy over the .pgpass file for the postgres user so that it knows how to connect as itself (oof)
     File::Copy::cp('/root/.pgpass', '/var/lib/pgsql/.pgpass');
+    print $lh "# [INFO] Adding 'cleanup .pgpass file to \@ROLLBACKS stack...\n";
     my $reb = sub { unlink '/var/lib/pgsql/.pgpass' };
     push @ROLLBACKS, $reb;
     require Cpanel::SafetyBits::Chown;
     Cpanel::SafetyBits::Chown::safe_chown( 'postgres', 'postgres', '/var/lib/pgsql/.pgpass' );
     chmod( 0600, '/var/lib/pgsql/.pgpass' );
 
+    print "# [INFO] Now running pg_upgrade on the default cluster...\n";
     {
         local $@;
         eval {
@@ -220,18 +228,19 @@ sub _real_install {
 
 
     # Start the server.
+    print $lh "# [INFO] Starting up postgresql-$ver2install...\n";
     $exit = _saferun( $lh, qw{systemctl start}, "postgresql-$ver2install" );
     return _cleanup("$exit") if $exit;
 
     if( $ccs_installed ) {
-        print $lh "\n\nNow upgrading PG cluster for cpanel-ccs-calendarserver...\n";
         my $ccs_pg_datadir = '/opt/cpanel-ccs/data/Data/Database/cluster';
-        print $lh "Old PG datadir is being moved to '$ccs_pg_datadir.old'...\n";
+        print $lh "# [INFO] Old PG datadir is being moved to '$ccs_pg_datadir.old'...\n";
         File::Copy::mv( $ccs_pg_datadir, "$ccs_pg_datadir.old" );
         mkdir($ccs_pg_datadir);
         chmod( 0700, $ccs_pg_datadir );
         Cpanel::SafetyBits::Chown::safe_chown( 'cpanel-ccs', 'cpanel-ccs', $ccs_pg_datadir );
-        
+       
+        print $lh "# [INFO] Adding 'restore old CCS cluster' to \@ROLLBACKS stack...\n";
         my $rb = sub {
             require File::Path;
             File::Path::remove_tree($ccs_pg_datadir, { 'error' => \my $err } );
@@ -240,6 +249,7 @@ sub _real_install {
         };
         push @ROLLBACKS, $rb;
 
+        print $lh "# [INFO] Now initializing the new PG cluster for cpanel-ccs-calendarserver...\n";
         unlink '/opt/cpanel-ccs/data/Data/Database/cluster/postmaster.pid';
 
         # Init the DB
@@ -257,6 +267,7 @@ sub _real_install {
         }
         return _cleanup("$exit") if $exit;
 
+        print $lh "# [INFO] Now upgrading the PG cluster for cpanel-ccs-calendarserver...\n";
         # Upgrade the DB
         {
             local $@;
@@ -282,36 +293,37 @@ sub _real_install {
     }
 
     # At this point we're at the point where we don't need to restore. Just clean up.
+    print $lh "# [INFO] Clearing \@ROLLBACKS stack, as we have cleared the necessary checkpoint.\n";
     @ROLLBACKS = ();
     if( $str_ver + 0 < 9.4 ) {
-        print $lh "\n\nWorkaround resulted in successful start of the server. Reverting workaround changes to pg_ctl...\n\n";
+        print $lh "# [INFO] Workaround resulted in successful start of the server. Reverting workaround changes to pg_ctl...\n\n";
         rename( '/usr/bin/pg_ctl.orig', '/usr/bin/pg_ctl' ) or do {
-            print $lh "Restore of /usr/bin/pg_ctl.orig to /usr/bin/pg_ctl failed: $!\n";
+            print $lh "# [ERROR] Restore of /usr/bin/pg_ctl.orig to /usr/bin/pg_ctl failed: $!\n";
             return _cleanup("255");
         };
     }
 
-    print $lh "\n\nNow cleaning up old postgresql version...\n";
+    print $lh "# [INFO] Now cleaning up old postgresql version...\n";
     my $svc2remove = ( $str_ver + 0 < 9.5 ) ? 'postgresql' : "postgresql-$str_ver";
     $exit = _saferun( $lh, qw{systemctl disable}, $svc2remove );
     return _cleanup("$exit") if $exit;
-
-    # XXX Can't actually remove 9.2 if CCS is installed :(
     $exit = _saferun( $lh, qw{yum -y remove}, $svc2remove );
     return _cleanup("$exit") if $exit;
 
-    print $lh "\n\nNow enabling postgresql-$ver2install on startup...\n";
+    print $lh "# [INFO] Now enabling postgresql-$ver2install on startup...\n";
     $exit = _saferun( $lh, qw{systemctl enable}, "postgresql-$ver2install" );
     return _cleanup("$exit") if $exit;
 
     if($ccs_installed) {
-        print $lh "\nRe-Enabling cpanel-ccs-calendarserver...\n\n";
+        print $lh "# [INFO] Re-Enabling cpanel-ccs-calendarserver...\n";
         require Whostmgr::Services;
         Whostmgr::Services::enable('cpanel-ccs');
     }
 
     # XXX Now the postgres service appears as "disabled" for cPanel's sake. Frowny faces everywhere.
     # Not sure how to fix yet.
+    print $lh "# [INFO] Re-Enabling postgres services for cPanel...\n";
+    print $lh "# [TODO] Actually do this!\n";
 
     return _cleanup("0");
 }