diff options
-rw-r--r-- | bootstrap.php | 24 | ||||
-rw-r--r-- | command.php | 36 | ||||
-rw-r--r-- | innerWatchdog.php | 34 |
3 files changed, 54 insertions, 40 deletions
diff --git a/bootstrap.php b/bootstrap.php index 24385c4..7edd935 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -1,6 +1,6 @@ <?php /** - * @copyright 2003-2013 PgPool Global Development Group + * @copyright 2003-2016 PgPool Global Development Group */ // Session @@ -27,11 +27,23 @@ define('NODE_ACTIVE_CONNECTED', 2); define('NODE_DOWN', 3); define('NODE_NOT_LOADED', -1); // only for pgpoolAdmin -// watchdog status in "pcp_watchdog_info" result -define('WATCHDOG_INIT', 1); -define('WATCHDOG_STANDBY', 2); -define('WATCHDOG_ACTIVE', 3); -define('WATCHDOG_DOWN', 4); +// watchdog status in "pcp_watchdog_info" result (- 3.4) +// (defined in $src/inclucde/watchdog/watchdog.h +$g_watchdog_status_str_arr = array(); +if (_PGPOOL2_VERSION < 3.5) { + define('WATCHDOG_END', 0); + define('WATCHDOG_INIT', 1); + define('WATCHDOG_NORMAL', 2); + define('WATCHDOG_MASTER', 3); + define('WATCHDOG_DOWN', 4); + $g_watchdog_status_str_arr = array( + WATCHDOG_END => 'END', + WATCHDOG_INIT => 'INIT', + WATCHDOG_NORMAL => 'NORMAL', + WATCHDOG_MASTER => 'MASTER', + WATCHDOG_DOWN => 'DOWN', + ); +} // timeout seconds // (The parameter "pcp_timeout" existed till V3.0.) diff --git a/command.php b/command.php index fa88432..8f8c9be 100644 --- a/command.php +++ b/command.php @@ -19,7 +19,7 @@ * is" without express or implied warranty. * * @author Ryuma Ando <[email protected]> - * @copyright 2003-2015 PgPool Global Development Group + * @copyright 2003-2016 PgPool Global Development Group * @version CVS: $Id$ */ @@ -152,6 +152,9 @@ function execPcp($command, $extra_args = array()) case 'PCP_WATCHDOG_INFO': $cmd = _PGPOOL2_PCP_DIR . '/pcp_watchdog_info' . $args; $ret = exec($cmd, $output, $return_var); + if (3.5 <= _PGPOOL2_VERSION) { + $ret = $output[2]; + } break; default: @@ -218,23 +221,37 @@ function getNodeInfo($i) */ function getWatchdogInfo($i = '') { - global $tpl; + global $tpl, $g_watchdog_status_str_arr; - $result = execPcp('PCP_WATCHDOG_INFO', $i); + $result = execPcp('PCP_WATCHDOG_INFO', + (3.5 <= _PGPOOL2_VERSION) ? array('n' => $i) : array($i) + ); - if (!array_key_exists('SUCCESS', $result)) { + if (! array_key_exists('SUCCESS', $result)) { $errorCode = 'e1013'; $tpl->assign('errorCode', $errorCode); $tpl->display('innerError.tpl'); exit(); } - $arr = explode(" ", $result['SUCCESS']); - $rtn['hostname'] = $arr[0]; - $rtn['pgpool_port'] = $arr[1]; - $rtn['wd_port'] = $arr[2]; - $rtn['status'] = $arr[3]; + $arr = explode(' ', $result['SUCCESS']); + if (3.5 <= _PGPOOL2_VERSION) { + // ex.) Linux_dhcp-177-180_9999 133.137.177.180 9999 9000 4 MASTER + $rtn['hostname'] = $arr[1]; + $rtn['pgpool_port'] = $arr[2]; + $rtn['wd_port'] = $arr[3]; + $rtn['status'] = $arr[4]; + $rtn['status_str'] = $arr[5]; + + } else { + // ex.) 133.137.177.180 9999 9000 3 + $rtn['hostname'] = $arr[0]; + $rtn['pgpool_port'] = $arr[1]; + $rtn['wd_port'] = $arr[2]; + $rtn['status'] = $arr[3]; + $rtn['status_str'] = $g_watchdog_status_str_arr[$rtn['status']]; + } return $rtn; } @@ -261,4 +278,3 @@ function checkPcppass() exit(); } } -?> diff --git a/innerWatchdog.php b/innerWatchdog.php index 31b9543..9b4c723 100644 --- a/innerWatchdog.php +++ b/innerWatchdog.php @@ -19,7 +19,7 @@ * is" without express or implied warranty. * * @author Ryuma Ando <[email protected]> - * @copyright 2003-2013 PgPool Global Development Group + * @copyright 2003-2016 PgPool Global Development Group * @version CVS: $Id$ */ @@ -49,33 +49,19 @@ $params = readConfigParams(array('port', // get watchdog information $watchdogInfo = array(); -for ($i = 0; $i < count($params['other_pgpool_hostname']); $i++) { - $watchdogInfo[] = getWatchdogInfo($i); -} -$watchdogInfo['local'] = getWatchdogInfo(); +if (3.5 <= _PGPOOL2_VERSION) { + $watchdogInfo['local'] = getWatchdogInfo(0); + for ($i = 0; $i < count($params['other_pgpool_hostname']); $i++) { + $watchdogInfo[] = getWatchdogInfo($i + 1); + } -foreach ($watchdogInfo as $key => $info) { - switch ($info['status']) { - case WATCHDOG_INIT: - $watchdogInfo[$key]['status_str'] = $message['strWdInit']; - break; - case WATCHDOG_STANDBY: - $watchdogInfo[$key]['status_str'] = $message['strWdStandby']; - break; - case WATCHDOG_ACTIVE: - $watchdogInfo[$key]['status_str'] = $message['strWdActive']; - break; - case WATCHDOG_DOWN: - $watchdogInfo[$key]['status_str'] = $message['strWdDown']; - break; - default: - $watchdogInfo[$key]['status_str'] = $message['strUnknown']; - break; +} else { + $watchdogInfo['local'] = getWatchdogInfo(); + for ($i = 0; $i < count($params['other_pgpool_hostname']); $i++) { + $watchdogInfo[] = getWatchdogInfo($i); } } $tpl->assign('params', $params); $tpl->assign('watchdogInfo', $watchdogInfo); $tpl->display('innerWatchdog.tpl'); - -?> |