Explorar el Código

Getting closer

Andy Baugh hace 5 años
padre
commit
081353136d
Se han modificado 3 ficheros con 40 adiciones y 12 borrados
  1. 4 1
      js/pgupgrade.js
  2. 34 11
      lib/Troglodyne/API/Postgres.pm
  3. 2 0
      templates/ui/pgupgrade.tmpl

+ 4 - 1
js/pgupgrade.js

@@ -193,7 +193,10 @@ window.doUpgrade = function () {
     let submitBtn = document.getElementById('submit');
     submitBtn.disabled = true;
     submitBtn.innerHTML = '<span class="fa fa-spin fa-spinner"></span>';
-    document.getElementById('upgradeDiv').innerHTML = '<pre id="upgradeWell" class="well">Ensuring that the PostgreSQL Community repository is installed...\n</pre>';
+    let upgradeWell = document.getElementById('upgradeWell');
+    upgradeWell.textContent = 'Ensuring that the PostgreSQL Community repository is installed...\n';
+    upgradeWell.style.display = "block";
+    upgradeForm.style.display = "none";
     doAPIRequestWithCallback( 'GET', 'Postgres', 'enable_community_repositories', doInstallScroller, generalErrorHandler );
 
     return false;

+ 34 - 11
lib/Troglodyne/API/Postgres.pm

@@ -71,7 +71,7 @@ sub start_postgres_install {
     # OK. We are logging, now return the log loc after kicking it off.
     # Yeah, yeah, I'm forking twice. who cares
     require Cpanel::Daemonizer::Tiny;
-    my $pid = Cpanel::Daemonizer::Tiny::run_as_daemon( &_real_install, $version, $lgg );
+    my $pid = Cpanel::Daemonizer::Tiny::run_as_daemon( \&_real_install, $version, $lgg );
     symlink( $pid, "$dir/INSTALL_IN_PROGRESS" ) if $pid;
     return {
         'log' => $lgg,
@@ -88,16 +88,28 @@ sub _real_install {
         "postgresql$no_period_version-server",
     );
     # TODO: Use Cpanel::Yum::Install based module, let all that stuff handle this "for you".
-    open( my $lh, ">", $lgg ) or do {
-        _cleanup("255");
-        return;
-    };
+    open( my $lh, ">", $log ) or return _cleanup("255");
+    select $lh;
+    $| = 1;
+    select $lh;
     print $lh "Beginning install...\n";
 
     # Check for CCS. Temporarily disable it if so.
-    require Cpanel::RPM;
-    my $ccs_installed = Cpanel::RPM->get_version('cpanel-ccs-calendarserver');
-    $ccs_installed = $ccs_installed->{'cpanel-ccs-calendarserver'};
+    my ( $ccs_installed, $err );
+    {
+        local $@;
+        eval {
+            require Cpanel::RPM;
+            $ccs_installed = Cpanel::RPM->new()->get_version('cpanel-ccs-calendarserver');
+            $ccs_installed = $ccs_installed->{'cpanel-ccs-calendarserver'};
+        };
+        $err = $@;
+    }
+    if($err) {
+        print $lh "[ERROR] $err\n";
+        return _cleanup('255');
+    }
+    print $lh "[DEBUG] CCS Installed? $ccs_installed\n";
     if($ccs_installed) {
         print $lh "\ncpanel-ccs-calendarserver is installed.\nDisabling the service while the upgrade is in process.\n\n";
         require Whostmgr::Services;
@@ -109,13 +121,23 @@ sub _real_install {
     return _cleanup("$exit") if $exit;
 
     # Init the DB
-    require Cpanel::AccessIds::ReducedPrivileges;
     {
-        my $pants_on_the_ground = Cpanel::AccessIds::ReducedPrivileges->new('postgres');
-        $exit = _saferun( $lh, "/usr/pgsql-$ver2install/bin/initdb", '-D', "/var/lib/pgsql/$ver2install/data/" );
+        local $@;
+        eval {
+            require Cpanel::AccessIds::ReducedPrivileges;
+            my $pants_on_the_ground = Cpanel::AccessIds::ReducedPrivileges->new('postgres');
+            $exit = _saferun( $lh, "/usr/pgsql-$ver2install/bin/initdb", '-D', "/var/lib/pgsql/$ver2install/data/" );
+        };
+        $err = $@;
+    }
+    if($err) {
+        print $lh "[ERROR] $err\n";
+        return _cleanup('255');
     }
     return _cleanup("$exit") if $exit;
 
+    # XXX FAILING HERE
+    print $lh "[DEBUG] pg_ctl workaround step...\n";
     require File::Slurper;
     # Move some bullcrap out of the way if we're on old PGs
     my @cur_ver = ( Cpanel::PostgresUtils::get_version() );
@@ -135,6 +157,7 @@ sub _real_install {
         print $lh "Workaround should be in place now. Proceeding with pg_upgrade.\n\n";
     }
 
+    print $lh "[DEBUG] Uprade cluster\n";
     # 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/
     my ( $old_datadir, $old_bindir ) = ( $str_ver + 0 < 9.5 ) ? ( '/var/lib/pgsql/data', '/usr/bin' ) : ( "/var/lib/pgsql/$str_ver/data/", "/usr/pgsql-$str_ver/bin/" );

+ 2 - 0
templates/ui/pgupgrade.tmpl

@@ -69,6 +69,8 @@ This interface at least attempts to take care of those issues for you.
             </tbody>
         </table>
     </form>
+    <pre style="display: none;" id="upgradeWell" class="well">
+    </pre>
 </div>
 <button id="submit" class="btn btn-success" title="Please select a version above to continue" onclick="window.doUpgrade();">Continue</button>
 <br><br>