Jelajahi Sumber

UNTESTED: I think we may have it y'all

Andy Baugh 5 tahun lalu
induk
melakukan
ffbcad1bf5
2 mengubah file dengan 50 tambahan dan 0 penghapusan
  1. 1 0
      Makefile
  2. 49 0
      lib/Troglodyne/API/Postgres.pm

+ 1 - 0
Makefile

@@ -63,6 +63,7 @@ rpm:
 	ln -s $(pwd)/templates SOURCES/BetterPostgres4cP-1.0/templates
 	cp $(pwd)/Makefile SOURCES/BetterPostgres4cP-1.0/Makefile
 	cp $(pwd)/configure SOURCES/BetterPostgres4cP-1.0/configure
+	mkdir -p ~/rpmbuild/SOURCES
 	cd SOURCES && tar --exclude="*.swp" --exclude="*.swn" --exclude="*.swo" -ch BetterPostgres4cP-1.0 | gzip > ~/rpmbuild/SOURCES/BetterPostgres4cP-1.0.tar.gz
 	rpmbuild -ba --clean --target noarch SPECS/BetterPostgres.spec
 	rm -rf SOURCES/*

+ 49 - 0
lib/Troglodyne/API/Postgres.pm

@@ -84,6 +84,16 @@ sub start_postgres_install {
             _cleanup("255");
             return;
         };
+
+        # Check for CCS. Temporarily disable it if so.
+        require Cpanel::RPM;
+        my $ccs_installed = Cpanel::RPM::get_version('cpanel-ccs-calendarserver');
+        if($ccs_installed) {
+            print $lh "\ncpanel-ccs-calendarserver is installed.\nDisabling the service while the upgrade is in process.\n\n";
+            require Whostmgr::Services;
+            Whostmgr::Services::disable('cpanel-ccs');
+        }
+
         require Cpanel::SafeRun::Object;
         my $run_result = Cpanel::SafeRun::Object->new(
             'program' => 'yum',
@@ -150,6 +160,38 @@ sub start_postgres_install {
         $exit = $run_result->error_code() || 0;
         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";
+            rename( $ccs_pg_datadir, "$ccs_pg_datadir.old" );
+            mkdir($ccs_pg_datadir);
+
+            # Init the DB
+            $run_result = Cpanel::SafeRun::Object->new(
+                'program' => "/usr/pgsql-$ver2install/bin/initdb",
+                'args'    => [ '-D', $ccs_pg_datadir ],
+                'stdout'  => $lh,
+                'stderr'  => $lh,
+            );
+            $exit = $run_result->error_code() || 0;
+            return _cleanup("$exit") if $exit;
+
+            $run_result = Cpanel::SafeRun::Object->new(
+                'program' => "/usr/pgsql-$ver2install/bin/pg_upgrade",
+                'args'    => [
+                    '--old-datadir', "$ccs_pg_datadir.old",
+                    '--new-datadir', $ccs_pg_datadir,
+                    '--old-bindir', $old_bindir,
+                    '--new_bindir', "/usr/pgsql-$ver2install/bin/",
+                ],
+                'stdout'  => $lh,
+                'stderr'  => $lh,
+            );
+            $exit = $run_result->error_code() || 0;
+            return _cleanup("$exit") if $exit;
+        }
+
         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";
             rename( '/usr/bin/pg_ctl.orig', '/usr/bin/pg_ctl' ) or do {
@@ -195,6 +237,13 @@ export PGDATA
 export PATH=\$PATH:/usr/pgsql-$ver2install/bin\n";
         File::Slurper::write_text( '/var/lib/pgsql/.bash_profile', $bash_profile );
 
+        if($ccs_installed) {
+            File::Slurper::write_text( '/opt/cpanel-ccs/.bash_profile', $bash_profile );
+            print $lh "\nRe-Enabling cpanel-ccs-calendarserver...\n\n";
+            require Whostmgr::Services;
+            Whostmgr::Services::enable('cpanel-ccs');
+        }
+
         return _cleanup("0");
     };
     my $pid = Cpanel::Daemonizer::Tiny::run_as_daemon( $install, $version, $lgg );