3 # pgpool-II resource agent.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of version 2 of the GNU General Public License as
7 # published by the Free Software Foundation.
9 # This program is distributed in the hope that it would be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 # Further, this software is distributed without any warranty that it is
14 # free of the rightful claim of any third person regarding infringement
15 # or the like. Any license provided herein, whether implied or
16 # otherwise, applies only to this software file. Patent licenses, if
17 # any, provided herein do not apply to combinations of this program with
18 # other software, or any other product whatsoever.
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write the Free Software Foundation,
22 # Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
24 #######################################################################
26 # This resource agent was written by Eliot Gable <egable at gmail.com>
28 #######################################################################
30 #######################################################################
33 : ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/resource.d/heartbeat}
34 .
${OCF_FUNCTIONS_DIR}/.ocf-shellfuncs
36 #######################################################################
41 <!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
42 <resource-agent name="pgpool2" version="0.1">
43 <version>1.0</version>
46 This resource agent provides basic management of pgpool-II.
47 It starts and stops pgpool-II and monitors its status. It will
48 also monitor the status of each connection and can optionally
49 attempt to automatically reconnect detached nodes or can
50 mark the service as failed if there are any detached nodes.
52 <shortdesc lang="en">Manages pgpool-II</shortdesc>
56 <parameter name="pcp_admin_username" required="1">
58 Administrative username for pgpool-II control.
60 <shortdesc lang="en">Administrative username.</shortdesc>
61 <content type="string" default="" />
64 <parameter name="pcp_admin_password" required="1">
66 Administrative password for pgpool-II control.
68 <shortdesc lang="en">Administrative password.</shortdesc>
69 <content type="string" default="" />
72 <parameter name="pcp_admin_port" required="1">
74 Administrative port for pgpool-II control.
76 <shortdesc lang="en">Administrative port for PCP commands.</shortdesc>
77 <content type="string" default="" />
80 <parameter name="pcp_admin_host">
82 Administrative host for pgpool-II control.
84 <shortdesc lang="en">Administrative host for PCP commands.</shortdesc>
85 <content type="string" default="localhost" />
88 <parameter name="pgpool_bin">
90 Path to the pgpool-II binary.
92 <shortdesc lang="en">Path to pgpool.</shortdesc>
93 <content type="string" default="/usr/bin/pgpool" />
96 <parameter name="pcp_attach_node_bin">
98 Path to the pcp_attach_node binary.
100 <shortdesc lang="en">Path to pcp_attach_node.</shortdesc>
101 <content type="string" default="/usr/bin/pcp_attach_node" />
104 <parameter name="pcp_detach_node_bin">
106 Path to the pcp_detach_node binary.
108 <shortdesc lang="en">Path to pcp_detach_node.</shortdesc>
109 <content type="string" default="/usr/bin/pcp_detach_node" />
112 <parameter name="pcp_node_count_bin">
114 Path to the pcp_node_count binary.
116 <shortdesc lang="en">Path to pcp_node_count.</shortdesc>
117 <content type="string" default="/usr/bin/pcp_node_count" />
120 <parameter name="pcp_node_info_bin">
122 Path to the pcp_node_info binary.
124 <shortdesc lang="en">Path to pcp_node_info.</shortdesc>
125 <content type="string" default="/usr/bin/pcp_node_info" />
128 <parameter name="stop_mode">
130 Stop mode to use when stopping pgpool-II.
132 <shortdesc lang="en">Stop mode for pgpool-II.</shortdesc>
133 <content type="string" default="f" />
136 <parameter name="auto_reconnect">
138 If "true", then during monitoring actions,
139 the resource agent will attempt to re-attach any disconnected
140 nodes. No error will be reported if re-attachment fails.
142 <shortdesc lang="en">Automatically reattach failed nodes</shortdesc>
143 <content type="boolean" default="" />
146 <parameter name="fail_on_detached">
148 This instructs the resource agent to mark pgpool-II in a
149 failed state if one or more of the nodes is detached. The monitor
150 action will always mark pgpool-II in a failed state if all nodes are
151 detached, so this is only useful if you want to mark pgpool-II in a
152 failed state if at least one node is detached. The auto_reconnect
153 option will always try to reconnect detached nodes (if enabled)
154 before this fail_on_detached mechanism triggers.
156 <shortdesc lang="en">Marks resource as failed if at least one node is detached.</shortdesc>
157 <content type="string" default="" />
160 <parameter name="fail_on_node_detached">
162 This is similar to fail_on_detached, except you can
163 specify a comma-seperated list of node IDs. If specified, pgpool2
164 will only be marked as "failed" if one of the nodes in the list
165 is detached or if all nodes are detached.
167 <shortdesc lang="en">Specify a list of nodes to monitor for failure.</shortdesc>
168 <content type="string" default="" />
174 <action name="start" timeout="20" />
175 <action name="stop" timeout="40" />
176 <action name="monitor" timeout="20" interval="5" depth="0"/>
177 <action name="reload" timeout="20" />
178 <action name="meta-data" timeout="5" />
179 <action name="validate-all" timeout="20" />
185 #######################################################################
189 usage: $0 {start|stop|status|monitor|validate-all|meta-data}
191 Expects to have a fully populated OCF RA-compliant environment set.
196 if pgpool2_status
; then
197 ocf_log debug
"${OCF_RESOURCE_INSTANCE} $__OCF_ACTION : already started."
201 #echo "Trying to start pgpool..." >> /tmp/pgpool
203 if pgpool2_status
; then
204 ocf_log info
"${OCF_RESOURCE_INSTANCE} Successfully started pgpool-II"
207 #echo "pgpool couldn't be started, why?" /tmp/pgpool
208 ocf_log error
"${OCF_RESOURCE_INSTANCE} Failed to start pgpool-II"
209 return $OCF_ERR_GENERIC
212 ocf_log error
"${OCF_RESOURCE_INSTANCE} Failed to start pgpool-II"
214 return $OCF_ERR_GENERIC
218 ocf_log info
"Using $PGPOOL -m $STOP_MODE stop to stop pgpool-II"
219 if $PGPOOL -m $STOP_MODE stop
; then
220 ocf_log info
"${OCF_RESOURCE_INSTANCE} Successfully stopped pgpool-II"
223 ocf_log info
"${OCF_RESOURCE_INSTANCE} Already stopped pgpool-II"
229 if [ ! -r "/var/postgres/pgpool-II/pgpool.pid" ]; then
230 return $OCF_NOT_RUNNING
232 ps_info
=$
(ps ax |
grep "pgpool" |
grep $
(cat /var
/postgres
/pgpool-II
/pgpool.pid
))
233 #echo "ps_info: $ps_info" >> /tmp/pgpool
234 if [ -z "$ps_info" ]; then
235 #echo "Found pgpool is NOT running..." >> /tmp/pgpool
236 return $OCF_NOT_RUNNING
238 #echo "Found pgpool is running..." >> /tmp/pgpool
239 # Try to reconnect any detached nodes
240 if ocf_is_true
${OCF_RESKEY_auto_reconnect} ; then
241 NODE_COUNT
=$
($PCP_NODE_COUNT 1 $OCF_RESKEY_pcp_admin_host $OCF_RESKEY_pcp_admin_port $OCF_RESKEY_pcp_admin_username $OCF_RESKEY_pcp_admin_password)
242 for node
in `seq 0 $((NODE_COUNT-1))`; do
243 NODE_INFO
=$
($PCP_NODE_INFO 1 $OCF_RESKEY_pcp_admin_host $OCF_RESKEY_pcp_admin_port $OCF_RESKEY_pcp_admin_username $OCF_RESKEY_pcp_admin_password $node |
awk '{print $3}')
244 if [ "$NODE_INFO" = "3" ]; then
245 ocf_log info
"Node $node is currently detached. Attempting to reattach the node."
246 $PCP_ATTACH_NODE 1 $OCF_RESKEY_pcp_admin_host $OCF_RESKEY_pcp_admin_port $OCF_RESKEY_pcp_admin_username $OCF_RESKEY_pcp_admin_password $node
250 if [ -n "${ATTACHED}" ]; then
254 # Fail if configured to fail on one or more detached nodes and a node is still detached
255 if ocf_is_true
${OCF_RESKEY_fail_on_detached} ; then
256 NODE_COUNT
=$
($PCP_NODE_COUNT 1 $OCF_RESKEY_pcp_admin_host $OCF_RESKEY_pcp_admin_port $OCF_RESKEY_pcp_admin_username $OCF_RESKEY_pcp_admin_password)
257 for node
in `seq 0 $((NODE_COUNT-1))`; do
258 NODE_INFO
=$
($PCP_NODE_INFO 1 $OCF_RESKEY_pcp_admin_host $OCF_RESKEY_pcp_admin_port $OCF_RESKEY_pcp_admin_username $OCF_RESKEY_pcp_admin_password $node |
awk '{print $3}')
259 if [ "$NODE_INFO" = "3" ]; then
260 ocf_log error
"Node $node is detached. The pgpool-II service has failed."
261 return $OCF_ERR_GENERIC
265 # Fail if one of the specifically configured nodes is detached at this point
266 if [ -n "${OCF_RESKEY_fail_on_node_detached}" ]; then
267 NODE_COUNT
=$
($PCP_NODE_COUNT 1 $OCF_RESKEY_pcp_admin_host $OCF_RESKEY_pcp_admin_port $OCF_RESKEY_pcp_admin_username $OCF_RESKEY_pcp_admin_password)
268 for node
in `seq 0 $((NODE_COUNT-1))`; do
269 NODE_INFO
=$
($PCP_NODE_INFO 1 $OCF_RESKEY_pcp_admin_host $OCF_RESKEY_pcp_admin_port $OCF_RESKEY_pcp_admin_username $OCF_RESKEY_pcp_admin_password $node |
awk '{print $3}')
270 if [ "$NODE_INFO" = "3" ]; then
271 TOKEN
=${OCF_RESKEY_fail_on_node_detached%%,*}
272 TOKEN_STRING
=${OCF_RESKEY_fail_on_node_detached#*,}
273 while [ -n "$TOKEN" ] && [ "${TOKEN}" != "${TOKEN_STRING}" ]; do
274 if [ "$TOKEN" -eq $node ]; then
275 ocf_log error
"Node $node is detached. The pgpool-II service has failed."
276 return $OCF_ERR_GENERIC
278 TOKEN
=${TOKEN_STRING%%,*}
279 if [ "${TOKEN_STRING}" == "${TOKEN_STRING#*,}" ]; then
282 TOKEN_STRING
=${TOKEN_STRING#*,}
289 # Service is running and there is no reason to fail
290 #echo "pgpool should be running..." >> /tmp/pgpool
295 # If we're running as a clone, are the clone meta attrs OK?
296 # if [ "${OCF_RESKEY_CRM_meta_clone}" ]; then
297 # if [ "${OCF_RESKEY_CRM_meta_clone_node_max}" != 1 ]; then
298 # ocf_log error "Misconfigured clone parameters. Must set meta attribute \"clone_node_max\" to 1, got ${OCF_RESKEY_CRM_meta_clone_node_max}."
299 # return $OCF_ERR_ARGS
302 if [ -z "$OCF_RESKEY_pcp_admin_username" ]; then
303 ocf_log error
"Missing required parameter \"pcp_admin_username\"."
306 if [ -z "$OCF_RESKEY_pcp_admin_password" ]; then
307 ocf_log error
"Missing required parameter \"pcp_admin_password\"."
310 if [ -z "$OCF_RESKEY_pcp_admin_host" ]; then
311 ocf_log error
"Missing required parameter \"pcp_admin_host\"."
314 if [ -z "$OCF_RESKEY_pcp_admin_port" ]; then
315 ocf_log error
"Missing required parameter \"pcp_admin_port\"."
318 # Did we get a path for the pgpool binary?
319 if [ -z "$OCF_RESKEY_pgpool_bin" ]; then
320 ocf_log error
"Missing required parameter \"pgpool_bin\"."
323 if [ -x "$PGPOOL" ]; then
324 ocf_log error
"The pgpool binary is not executable or is not installed."
325 return $OCF_ERR_INSTALLED
328 # Did we get a path for the pcp_attach_node binary?
329 if [ -z "$OCF_RESKEY_pcp_attach_node_bin" ]; then
330 ocf_log error
"Missing required parameter \"pcp_attach_node_bin\"."
333 if [ -x "$PCP_ATTACH_NODE" ]; then
334 ocf_log error
"The pcp_attach_node binary is not executable or is not installed."
335 return $OCF_ERR_INSTALLED
338 # Did we get a path for the pcp_detach_node binary?
339 if [ -z "$OCF_RESKEY_pcp_detach_node_bin" ]; then
340 ocf_log error
"Missing required parameter \"pcp_detach_node_bin\"."
343 if [ -x "$PCP_DETACH_NODE" ]; then
344 ocf_log error
"The pcp_detach_node binary is not executable or is not installed."
345 return $OCF_ERR_INSTALLED
348 # Did we get a path for the pcp_node_count binary?
349 if [ -z "$OCF_RESKEY_pcp_node_count_bin" ]; then
350 ocf_log error
"Missing required parameter \"pcp_node_count_bin\"."
353 if [ -x "$PCP_NODE_COUNT" ]; then
354 ocf_log error
"The pcp_node_count binary is not executable or is not installed."
355 return $OCF_ERR_INSTALLED
358 # Did we get a path for the pcp_node_info binary?
359 if [ -z "$OCF_RESKEY_pcp_node_info_bin" ]; then
360 ocf_log error
"Missing required parameter \"pcp_node_info_bin\"."
363 if [ -x "$PCP_NODE_INFO" ]; then
364 ocf_log error
"The pcp_node_info binary is not executable or is not installed."
365 return $OCF_ERR_INSTALLED
368 if [ -n "$OCF_RESKEY_stop_mode" ]; then
369 if ! echo "$OCF_RESKEY_stop_mode" |
grep -E '[fsi]|fast|start|immediate' >> /dev
/null
; then
370 ocf_log error
"Stop mode is invalid."
374 ocf_log error
"Stop mode was not specified."
377 if [ -n "$OCF_RESKEY_auto_reconnect" ] &&
378 [ "$OCF_RESKEY_auto_reconnect" != "true" ] &&
379 [ "$OCF_RESKEY_auto_reconnect" != "false" ]; then
380 ocf_log error
"Parameter 'auto_reconnect' must be empty, 'true', or 'false'."
383 if [ -n "$OCF_RESKEY_fail_on_detached" ] &&
384 [ "$OCF_RESKEY_fail_on_detached" != "true" ] &&
385 [ "${OCF_RESKEY_fail_on_detached}" != "false" ]; then
386 ocf_log error
"Parameter 'fail_on_detached' must be empty, 'true', or 'false'."
390 if [ -n "$OCF_RESKEY_fail_on_node_detached" ]; then
391 TOKEN
=${OCF_RESKEY_fail_on_node_detached%%,*}
392 TOKEN_STRING
=${OCF_RESKEY_fail_on_node_detached#*,}
393 while [ -n $TOKEN ] && [ "${TOKEN}" != "${TOKEN_STRING}" ]; do
396 ocf_log error
"Invalid token '${TOKEN}' in parameter 'fail_on_node_detached'."
400 TOKEN
=${TOKEN_STRING%%,*}
401 if [ "${TOKEN_STRING}" == "${TOKEN_STRING#*,}" ]; then
404 TOKEN_STRING
=${TOKEN_STRING#*,}
411 # These two actions must always succeed
412 case $__OCF_ACTION in
414 # OCF variables are not set when querying meta-data
417 usage|
help) pgpool2_usage
422 pgpool2_validate ||
exit $?
424 PGPOOL
=$OCF_RESKEY_pgpool_bin
425 PCP_ATTACH_NODE
=$OCF_RESKEY_pcp_attach_node_bin
426 PCP_DETACH_NODE
=$OCF_RESKEY_pcp_detach_node_bin
427 PCP_NODE_COUNT
=$OCF_RESKEY_pcp_node_count_bin
428 PCP_NODE_INFO
=$OCF_RESKEY_pcp_node_info_bin
429 STOP_MODE
=$OCF_RESKEY_stop_mode
430 #echo "$(date)" >> /tmp/pgpool
431 case $__OCF_ACTION in
432 start
) pgpool2_start
;;
434 status|monitor
) pgpool2_status
;;
437 exit $OCF_ERR_UNIMPLEMENTED
441 ocf_log debug
"${OCF_RESOURCE_INSTANCE} $__OCF_ACTION returned $rc"