Repository navigation
Expand file tree
/
Copy pathcommand.php
More file actions
128 lines (111 loc) · 3.97 KB
/
Copy pathcommand.php
File metadata and controls
128 lines (111 loc) · 3.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Command of PCP
*
* PHP versions 4 and 5
*
* LICENSE: Permission to use, copy, modify, and distribute this software and
* its documentation for any purpose and without fee is hereby
* granted, provided that the above copyright notice appear in all
* copies and that both that copyright notice and this permission
* notice appear in supporting documentation, and that the name of the
* author not be used in advertising or publicity pertaining to
* distribution of the software without specific, written prior
* permission. The author makes no representations about the
* suitability of this software for any purpose. It is provided "as
* is" without express or implied warranty.
*
* @author Ryuma Ando <ando@ecomas.co.jp>
* @copyright 2003-2007 PgPool Global Development Group
* @version CVS: $Id$
*/
require_once('common.php');
/**
* Execute pcp command
*
* @param string $command
* @param srgs $num
* @return array
*/
function execPcp($command, $num='') {
$pcpStatus = array (
'0' => 'SUCCESS',
'1' => 'UNKNOWNERR',
'2' => 'EOFERR',
'3' => 'NOMEMERR',
'4' => 'READERR',
'5' => 'WRITEERR',
'6' => 'TIMEOUTERR',
'7' => 'INVALERR',
'8' => 'CONNERR',
'9' => 'NOCONNERR',
'10' => 'SOCKERR',
'11' => 'HOSTERR',
'12' => 'BACKENDERR',
'13' => 'AUTHERR',
'127' => 'COMMANDERROR'
);
$param = readPcpInfo();
$param['hostname'] = _PGPOOL2_PCP_HOSTNAME;
$args = " " . $param['pcp_timeout'] . " " . $param['hostname'] . " " . $param['pcp_port'] . " ". $_SESSION[SESSION_LOGIN_USER] . " " . $_SESSION[SESSION_LOGIN_USER_PASSWORD] . " " . $num;
switch ($command) {
case 'PCP_NODE_COUNT':
$cmd = _PGPOOL2_PCP_DIR . '/pcp_node_count' . $args;
$ret = exec($cmd, $output, $return_var);
break;
case 'PCP_NODE_INFO':
$cmd = _PGPOOL2_PCP_DIR . '/pcp_node_info' . $args;
$ret = exec($cmd, $output, $return_var);
break;
case 'PCP_ATTACH_NODE':
$cmd = _PGPOOL2_PCP_DIR . '/pcp_attach_node' . $args;
$ret = exec($cmd, $output, $return_var);
break;
case 'PCP_DETACH_NODE':
$cmd = _PGPOOL2_PCP_DIR . '/pcp_detach_node' . $args;
$ret = exec($cmd, $output, $return_var);
break;
case 'PCP_PROC_COUNT':
$cmd = _PGPOOL2_PCP_DIR . '/pcp_proc_count' . $args;
$ret = exec($cmd, $output, $return_var);
break;
case 'PCP_PROC_INFO':
$cmd = _PGPOOL2_PCP_DIR . '/pcp_proc_info' . $args;
$ret = exec($cmd, $output, $return_var);
$ret = $output;
break;
case 'PCP_START_PGPOOL':
$cmdOption = $num;
$cmdOption = $cmdOption . ' -f ' . _PGPOOL2_CONFIG_FILE
. ' -F ' . _PGPOOL2_PASSWORD_FILE;
if(DoesPgpoolPidExist()) {
return array('FAIL'=> '');
}
$cmd = _PGPOOL2_COMMAND . $cmdOption . ' 2>&1 &';
$ret = exec($cmd, $output, $return_var);
if($return_var == 0) {
return array($pcpStatus[$return_var] => $output);
} else {
return array('FAIL' => $output);
}
break;
case 'PCP_STOP_PGPOOL':
$cmd = _PGPOOL2_PCP_DIR . '/pcp_stop_pgpool' . $args;
$ret = exec($cmd, $output, $return_var);
break;
default:
return array($pspStatus[1] => $pspStatus[1]);
}
return array($pcpStatus[$return_var] => $ret);
}
/**
* Read parameter of pcp_port and pcp_timeout from pgpool.conf
*
* @return array
*/
function readPcpInfo() {
$params = readConfigParams(array('pcp_port', 'pcp_timeout'));
return $params;
}
?>