Fix pgpoolAdmin cannot start and execute PCP command not in 3.5
authorNozomi Anzai <anzai@sraoss.co.jp>
Mon, 7 Dec 2015 09:56:44 +0000 (18:56 +0900)
committerNozomi Anzai <anzai@sraoss.co.jp>
Mon, 7 Dec 2015 09:56:44 +0000 (18:56 +0900)
command.php
common.php
status.php

index bf78c30540a4d189937614984dea59196c3f98b8..42313c4c55b316b6d9dab2dbdddc4136aee367c6 100644 (file)
@@ -32,7 +32,7 @@ require_once('common.php');
  * @param srgs $num
  * @return array
  */
-function execPcp($command, $extra_args)
+function execPcp($command, $extra_args = array())
 {
     $pcpStatus = array (
         '0'   => 'SUCCESS',
@@ -68,7 +68,7 @@ function execPcp($command, $extra_args)
             $args .= " -{$arg_name} {$val}";
         }
 
-    } else {
+    } elseif ($param) {
         $args = " " . PCP_TIMEOUT.
                 " " . $param['hostname'] .
                 " " . $param['pcp_port'] .
@@ -110,22 +110,9 @@ function execPcp($command, $extra_args)
             break;
 
         case 'PCP_START_PGPOOL':
-            $configOption = ' -f ' . _PGPOOL2_CONFIG_FILE .
-                            ' -F ' . _PGPOOL2_PASSWORD_FILE;
-
-            if(isPipe($num)) {
-                $cmdOption = $configOption . $num . ' > /dev/null &';
-            } else {
-                $cmdOption = $configOption . $num . ' 2>&1 &';
-            }
-
-            /* we should not check pid file here.
-             * let pgpool handle bogus pid file
-             * if(DoesPgpoolPidExist()) {
-             *   return array('FAIL'=> '');
-             * }
-             */
-            $cmd = _PGPOOL2_COMMAND . $cmdOption;
+            $args = _setStartArgs();
+            $cmd = _PGPOOL2_COMMAND . $args;
+            pr($cmd);
             $ret = exec($cmd, $output, $return_var);
             if ($return_var == 0) {
                 return array($pcpStatus[$return_var] => $output);
@@ -135,11 +122,8 @@ function execPcp($command, $extra_args)
             break;
 
         case 'PCP_RELOAD_PGPOOL':
-            $cmdOption = $num;
-            $cmdOption = $cmdOption .
-                         ' -f ' . _PGPOOL2_CONFIG_FILE .
-                         ' -F ' . _PGPOOL2_PASSWORD_FILE . ' reload';
-            $cmd = _PGPOOL2_COMMAND . $cmdOption . ' 2>&1 &';
+            $args = _setStartArgs();
+            $cmd = _PGPOOL2_COMMAND . $args. ' reload 2>&1 &';
             $ret = exec($cmd, $output, $return_var);
             if ($return_var == 0) {
                 return array($pcpStatus[$return_var] => $output);
@@ -149,6 +133,7 @@ function execPcp($command, $extra_args)
             break;
 
         case 'PCP_STOP_PGPOOL':
+            $args .= " {$_POST['stop_mode']}";
             $cmd = _PGPOOL2_PCP_DIR . '/pcp_stop_pgpool' . $args;
             $ret = exec($cmd, $output, $return_var);
             break;
index 4b7e26576047ed5d30c3040e7374dfd371718983..25ac2ed5eb966031a0bb4b0b11c175288f672baa 100644 (file)
@@ -216,6 +216,8 @@ function NodeStandby($nodeNum)
 function isSuperUser($user_name)
 {
     $params = readConfigParams(array('port'));
+
+    // Try to connect the backend by login user
     $conn = openDBConnection(array(
         'port'     => $params['port'],
         'dbname'   => 'template1',
@@ -223,9 +225,17 @@ function isSuperUser($user_name)
         'password' => $_SESSION[SESSION_LOGIN_USER_PASSWORD],
     ));
 
-    if ($conn == FALSE) {
-        return NULL;
+    // Try to connect health check user
+    if ($conn === FALSE) {
+        $params = readConfigParams(array('port', 'health_check_user', 'health_check_password'));
+        $conn = openDBConnection(array(
+            'port'     => $params['port'],
+            'dbname'   => 'template1',
+            'user'     => $params['health_check_user'],
+            'password' => $params['health_check_password']
+        ));
     }
+    if ($conn === FALSE) { return NULL; }
 
     $result = pg_query($conn, "SELECT usesuper FROM pg_user WHERE usename = '{$user_name}'");
     if (! pg_result_status($result) == PGSQL_TUPLES_OK) {
index 6abe11e8ec0225cc551b5bd0768e09ebcfc5d6fa..fb82a22de0217d7e3fe422f4d93c73aea02251a3 100644 (file)
@@ -224,33 +224,40 @@ function setNodeInfoFromConf()
 /** Modify start options */
 function _setStartArgs()
 {
-    $args = ' ';
+    $args = array();
+
+    $args[] = "-f ". _PGPOOL2_CONFIG_FILE;
+    $args[] = "-F ".  _PGPOOL2_PASSWORD_FILE;
+
+    foreach ($_POST as $key => $value) {
+        switch ($key) {
+        case 'c':
+        case 'D':
+        case 'd':
+        case 'C':
+        case 'n':
+            if ($value == 'on') {
+                $args[] = "-{$key}";
+            }
 
-    if (isset($_POST['c'])) {
-        $args = $args . "-c ";
-    }
-    if (isset($_POST['D'])) {
-        $args = $args . "-D ";
-    }
-    if (isset($_POST['d'])) {
-        $args = $args . "-d ";
-    }
-    if (isset($_POST['n'])) {
-        $pgpoolLog = _PGPOOL2_LOG_FILE;
-        if ($pgpoolLog == '') {
-            $logDir = readLogDir();
-            $pgpoolLog = "$logDir/pgpool.log";
-        }
-        if (isPipe($pgpoolLog)) {
-            $args = "$args -n 2>&1 $pgpoolLog ";
-        } else {
-            $args = "$args -n > $pgpoolLog ";
+            if ($key == 'n') {
+                $pgpoolLog = _PGPOOL2_LOG_FILE;
+                if ($pgpoolLog == '') {
+                    $logDir = readLogDir();
+                    $pgpoolLog = "$logDir/pgpool.log";
+                }
+                if (isPipe($pgpoolLog)) {
+                    $args[] = "2>&1 > $pgpoolLog &";
+                } else {
+                    $args[] = "> $pgpoolLog &";
+                }
+            }
+            break;
         }
     }
-    if (isset($_POST['C'])) {
-        $args = $args . "-C ";
-    }
 
+
+    $args = ' ' . implode(' ', $args);
     return $args;
 }
 
@@ -286,9 +293,8 @@ function _startPgpool()
     global $tpl;
     $rtn = FALSE;
 
-    $args = _setStartArgs();
-    $result = execPcp('PCP_START_PGPOOL', $args);
-    if (!array_key_exists('SUCCESS', $result)) {
+    $result = execPcp('PCP_START_PGPOOL');
+    if (! array_key_exists('SUCCESS', $result)) {
         $pgpoolStatus = 'pgpool start failed.';
         $pgpoolMessage = $result;