diff options
author | Nozomi Anzai | 2015-12-07 09:56:44 +0000 |
---|---|---|
committer | Nozomi Anzai | 2015-12-07 09:56:44 +0000 |
commit | bea081cd78b7dd220ac0093ad9573f717deff121 (patch) | |
tree | 55930b0fdb13a155b8981d2068221d96edb08911 | |
parent | 60d286bf10ac52e45ae6252ef9d36a2dffb7da92 (diff) |
Fix pgpoolAdmin cannot start and execute PCP command not in 3.5
-rw-r--r-- | command.php | 31 | ||||
-rw-r--r-- | common.php | 14 | ||||
-rw-r--r-- | status.php | 58 |
3 files changed, 52 insertions, 51 deletions
diff --git a/command.php b/command.php index bf78c30..42313c4 100644 --- a/command.php +++ b/command.php @@ -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; @@ -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) { @@ -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; |