/usr/lib/ocf/resource.d/heartbeat/mysql-proxy is in resource-agents 1:3.9.2-5ubuntu4.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 | #!/bin/sh
#
# Resource script for MySQL Proxy
#
# Description: Manages MySQL Proxy as an OCF resource in
# an high-availability setup.
#
# Tested with mysql-proxy 0.7.0 on Debian 5.0.
# Based on the mysql and Pure-Ftpd OCF resource agents.
#
# Author: Raoul Bhatia <r.bhatia@ipax.at> : Original Author
# License: GNU General Public License (GPL)
#
#
# usage: $0 {start|stop|reload|status|monitor|validate-all|meta-data}
#
# The "start" arg starts a MySQL Proxy instance
#
# The "stop" arg stops it.
#
# TODO
# * add error checking like in mysql ocf ra (e.g. socketdir)
#
# Test via
# */usr/sbin/ocf-tester -n mp /usr/lib/ocf/resource.d/heartbeat/mysql-proxy
# */usr/sbin/ocf-tester -n ms -o binary="/usr/sbin/mysql-proxy" -o defaults_file="" -o parameters="--proxy-skip-profiling" \
# -o admin_address="127.0.0.1:4041" -o proxy_backend_addresses="192.168.100.200:42006" \
# -o proxy_address="/var/run/mysqld/mysqld.sock" /usr/lib/ocf/resource.d/heartbeat/mysql-proxy
#
# * adding two mysql-instances (mysql-proxy-tcp and mysql-proxy-socket) and killing mysql-proxy-tcp
# beware, that as of mysql-proxy 0.7.0 (and possibly later), the socket is not automatically removed
#
#
# OCF parameters:
# OCF_RESKEY_binary
# OCF_RESKEY_defaults_file
# OCF_RESKEY_proxy_backend_addresses
# OCF_RESKEY_proxy_read_only_backend_addresses
# OCF_RESKEY_proxy_address
# OCF_RESKEY_log_level
# OCF_RESKEY_keepalive
# OCF_RESKEY_admin_address
# OCF_RESKEY_admin_username
# OCF_RESKEY_admin_password
# OCF_RESKEY_admin_lua_script
# OCF_RESKEY_parameters
# OCF_RESKEY_pidfile
#
##########################################################################
# Initialization:
: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
: ${OCF_RESKEY_binary="/usr/sbin/mysql-proxy"}
: ${OCF_RESKEY_defaults_file=""}
: ${OCF_RESKEY_proxy_backend_addresses="127.0.0.1:3306"}
: ${OCF_RESKEY_proxy_read_only_backend_addresses=""}
: ${OCF_RESKEY_proxy_address=":4040"}
: ${OCF_RESKEY_log_level=""}
: ${OCF_RESKEY_keepalive=""}
: ${OCF_RESKEY_admin_address="127.0.0.1:4041"}
: ${OCF_RESKEY_admin_username=""}
: ${OCF_RESKEY_admin_password=""}
: ${OCF_RESKEY_admin_lua_script=""}
: ${OCF_RESKEY_parameters=""}
: ${OCF_RESKEY_pidfile="${HA_RSCTMP}/mysql-proxy-${OCF_RESOURCE_INSTANCE}.pid"}
USAGE="Usage: $0 {start|stop|reload|status|monitor|validate-all|meta-data}";
##########################################################################
usage() {
echo $USAGE >&2
}
meta_data() {
cat <<END
<?xml version="1.0"?>
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
<resource-agent name="mysql-proxy">
<version>0.1</version>
<longdesc lang="en">
This script manages MySQL Proxy as an OCF resource in a high-availability setup.
Tested with MySQL Proxy 0.7.0 on Debian 5.0.
</longdesc>
<shortdesc lang="en">Manages a MySQL Proxy daemon</shortdesc>
<parameters>
<parameter name="binary" unique="0" required="0">
<longdesc lang="en">
Full path to the MySQL Proxy binary.
For example, "/usr/sbin/mysql-proxy".
</longdesc>
<shortdesc lang="en">Full path to MySQL Proxy binary</shortdesc>
<content type="string" default="/usr/sbin/mysql-proxy" />
</parameter>
<parameter name="defaults_file" unique="1" required="0">
<longdesc lang="en">
Full path to a MySQL Proxy configuration file.
For example, "/etc/mysql-proxy.conf".
</longdesc>
<shortdesc lang="en">Full path to configuration file</shortdesc>
<content type="string" default="" />
</parameter>
<parameter name="proxy_backend_addresses" unique="0" required="0">
<longdesc lang="en">
Address:port of the remote backend-servers (default: 127.0.0.1:3306).
</longdesc>
<shortdesc lang="en">MySQL Proxy backend-servers</shortdesc>
<content type="string" default="127.0.0.1:3306" />
</parameter>
<parameter name="proxy_read_only_backend_addresses" unique="0" required="0">
<longdesc lang="en">
Address:port of the remote (read only) slave-server (default: ).
</longdesc>
<shortdesc lang="en">MySql Proxy read only backend-servers</shortdesc>
<content type="string" default="127.0.0.1:3306" />
</parameter>
<parameter name="proxy_address" unique="0" required="0">
<longdesc lang="en">
Listening address:port of the proxy-server (default: :4040).
You can also specify a socket like "/tmp/mysql-proxy.sock".
</longdesc>
<shortdesc lang="en">MySQL Proxy listening address</shortdesc>
<content type="string" default=":4040" />
</parameter>
<parameter name="log_level" unique="0" required="0">
<longdesc lang="en">
Log all messages of level (error|warning|info|message|debug|) or higher.
An empty value disables logging.
</longdesc>
<shortdesc lang="en">MySQL Proxy log level.</shortdesc>
<content type="string" default="" />
</parameter>
<parameter name="keepalive" unique="0" required="0">
<longdesc lang="en">
Try to restart the proxy if it crashed (default: ).
Valid values: true or false. An empty value equals "false".
</longdesc>
<shortdesc lang="en">Use keepalive option</shortdesc>
<content type="string" default="" />
</parameter>
<parameter name="admin_address" unique="0" required="0">
<longdesc lang="en">
Listening address:port of the admin-server (default: 127.0.0.1:4041).
</longdesc>
<shortdesc lang="en">MySQL Proxy admin-server address</shortdesc>
<content type="string" default="127.0.0.1:4041" />
</parameter>
<parameter name="admin_username" unique="0" required="0">
<longdesc lang="en">
Username to allow to log in (default: ).
</longdesc>
<shortdesc lang="en">MySQL Proxy admin-server username</shortdesc>
<content type="string" default="" />
</parameter>
<parameter name="admin_password" unique="0" required="0">
<longdesc lang="en">
Password to allow to log in (default: ).
</longdesc>
<shortdesc lang="en">MySQL Proxy admin-server password</shortdesc>
<content type="string" default="" />
</parameter>
<parameter name="admin_lua_script" unique="0" required="0">
<longdesc lang="en">
Script to execute by the admin plugin.
</longdesc>
<shortdesc lang="en">MySQL Proxy admin-server lua script</shortdesc>
<content type="string" default="" />
</parameter>
<parameter name="parameters" unique="0" required="0">
<longdesc lang="en">
The MySQL Proxy daemon may be called with additional parameters.
Specify any of them here.
</longdesc>
<shortdesc lang="en">MySQL Proxy additional parameters</shortdesc>
<content type="string" default="" />
</parameter>
<parameter name="pidfile" unique="1" required="0">
<longdesc lang="en">PID file</longdesc>
<shortdesc lang="en">PID file</shortdesc>
<content type="string" default="${HA_RSCTMP}/mysql-proxy-${OCF_RESOURCE_INSTANCE}.pid" />
</parameter>
</parameters>
<actions>
<action name="start" timeout="30s" />
<action name="stop" timeout="30s" />
<action name="reload" timeout="30s" />
<action name="monitor" depth="0" timeout="20s" interval="60s" />
<action name="validate-all" timeout="30s" />
<action name="meta-data" timeout="5s" />
</actions>
</resource-agent>
END
}
isRunning()
{
kill -s 0 "$1" 2>/dev/null
}
mysqlproxy_status()
{
if [ -f "${pidfile}" ]; then
# MySQL Proxy is probably running
PID=`head -n 1 "${pidfile}"`
if [ ! -z "$PID" ] ; then
isRunning "$PID"
# @TODO in-depth check: issue a query and/or check proxy-admin interface
return $?
fi
fi
# MySQL Proxy is not running
false
}
mysqlproxy_start()
{
# if MySQL Proxy is running return success
if mysqlproxy_status ; then
ocf_log info "MySQL Proxy already running."
return $OCF_SUCCESS
fi
PARAM_PREFIX=''
# check if the MySQL Proxy defaults-file exist
if [ -f "$defaults_file" ]; then
PARAM_PREFIX="--defaults-file=$defaults_file "
fi
# set log-level
if [ ! -z "$log_level" ]; then
PARAM_PREFIX="$PARAM_PREFIX --log-level=$log_level "
fi
# set keepalive
if [ "$keepalive" = "true" ]; then
PARAM_PREFIX="$PARAM_PREFIX --keepalive "
fi
# honor admin_* options
if [ ! -z "$admin_username" ]; then
PARAM_PREFIX="$PARAM_PREFIX --admin-username=$admin_username "
fi
if [ ! -z "$admin_password" ]; then
PARAM_PREFIX="$PARAM_PREFIX --admin-password=$admin_password "
fi
if [ ! -z "$admin_lua_script" ]; then
PARAM_PREFIX="$PARAM_PREFIX --admin-lua-script=$admin_lua_script "
fi
# split multiple proxy-address options.
# currently unsupported but let us hope for the future ;)
for pa in $proxy_address; do
[ -z "$pa" ] && continue
OPTIONS=" $OPTIONS --proxy-address=$pa"
done
# split multiple proxy-backend-addresses options.
for pba in $proxy_backend_addresses; do
[ -z "$pba" ] && continue
OPTIONS=" $OPTIONS --proxy-backend-addresses=$pba"
done
# split multiple proxy-backend-addresses options.
for proba in $proxy_read_only_backend_addresses; do
[ -z "$proba" ] && continue
OPTIONS=" $OPTIONS --proxy-read-only-backend-addresses=$proba"
done
# build $OPTIONS and add addmin-address and pidfile
OPTIONS="$PARAM_PREFIX $OPTIONS --admin-address=$admin_address --pid-file=${pidfile}"
# start MySQL Proxy
#start-stop-daemon --start --quiet --pidfile $pidfile --make-pidfile --name mysql-proxy --startas $binary -b -- $OPTIONS
$binary --daemon $OPTIONS
ret=$?
if [ $ret -ne 0 ]; then
ocf_log err "MySQL Proxy returned error." $ret
return $OCF_ERR_GENERIC
fi
return $OCF_SUCCESS
}
mysqlproxy_stop()
{
if mysqlproxy_status ; then
#start-stop-daemon --stop --quiet --retry 3 --exec $binary --pidfile $pidfile
/bin/kill `cat "${pidfile}"`
ret=$?
if [ $ret -ne 0 ]; then
ocf_log err "MySQL Proxy returned an error while stopping." $ret
return $OCF_ERR_GENERIC
fi
# grant some time for shutdown and recheck
sleep 1
if mysqlproxy_status ; then
ocf_log err "MySQL Proxy failed to stop."
return $OCF_ERR_GENERIC
fi
# remove dangling socketfile, if specified
for pa in $proxy_address; do
if [ -S "$pa" ]; then
ocf_log info "Removing dangling socket file '$pa'."
rm -f "$pa"
fi
done
# remove dangling pidfile
if [ -f "${pidfile}" ]; then
ocf_log info "Removing dangling pidfile '${pidfile}'."
rm -f "${pidfile}"
fi
fi
return $OCF_SUCCESS
}
mysqlproxy_reload()
{
if mysqlproxy_status; then
ocf_log info "Reloading MySQL Proxy."
kill -s HUP `cat ${pidfile}`
fi
}
mysqlproxy_monitor()
{
if [ "${OCF_RESKEY_CRM_meta_interval:-0}" -eq "0" ]; then
# in case of probe, monitor operation is surely treated as
# under suspension. This will call start operation.
# (c/p from ocf:heartbeat:sfex)
mysqlproxy_validate_all
rc=$?
[ $rc -ne 0 ] && return $rc
fi
if mysqlproxy_status ; then
return $OCF_SUCCESS
fi
return $OCF_NOT_RUNNING
}
mysqlproxy_validate_all()
{
# check that the MySQL Proxy binary exists and can be executed
if [ ! -x "$binary" ]; then
ocf_log err "MySQL Proxy binary '$binary' does not exist or cannot be executed."
return $OCF_ERR_INSTALLED
fi
# check for valid log-level
echo $log_level | egrep "^(error|warning|info|message|debug|)$" >/dev/null
if [ $? -ne 0 ]; then
ocf_log err "MySQL Proxy log level '$log_level' not in valid range error|warning|info|message|debug"
return $OCF_ERR_CONFIGURED
fi
return $OCF_SUCCESS
}
#
# Main
#
if [ $# -ne 1 ]; then
usage
exit $OCF_ERR_ARGS
fi
pidfile=$OCF_RESKEY_pidfile
binary=$OCF_RESKEY_binary
defaults_file=$OCF_RESKEY_defaults_file
proxy_backend_addresses=$OCF_RESKEY_proxy_backend_addresses
proxy_read_only_backend_addresses=$OCF_RESKEY_proxy_read_only_backend_addresses
admin_address=$OCF_RESKEY_admin_address
admin_username=$OCF_RESKEY_admin_username
admin_password=$OCF_RESKEY_admin_password
admin_lua_script=$OCF_RESKEY_admin_lua_script
proxy_address=$OCF_RESKEY_proxy_address
log_level=$OCF_RESKEY_log_level
keepalive=$OCF_RESKEY_keepalive
# debugging stuff
#echo OCF_RESKEY_binary=$OCF_RESKEY_binary >> /tmp/prox_conf_$OCF_RESOURCE_INSTANCE
#echo OCF_RESKEY_defaults_file=$OCF_RESKEY_defaults_file >> /tmp/prox_conf_$OCF_RESOURCE_INSTANCE
#echo OCF_RESKEY_proxy_backend_addresses=$OCF_RESKEY_proxy_backend_addresses >> /tmp/prox_conf_$OCF_RESOURCE_INSTANCE
#echo OCF_RESKEY_proxy_read_only_backend_addresses=$OCF_RESKEY_proxy_read_only_backend_addresses >> /tmp/prox_conf_$OCF_RESOURCE_INSTANCE
#echo OCF_RESKEY_proxy_address=$OCF_RESKEY_proxy_address >> /tmp/prox_conf_$OCF_RESOURCE_INSTANCE
#echo OCF_RESKEY_log_level=$OCF_RESKEY_log_level >> /tmp/prox_conf_$OCF_RESOURCE_INSTANCE
#echo OCF_RESKEY_keepalive=$OCF_RESKEY_keepalive >> /tmp/prox_conf_$OCF_RESOURCE_INSTANCE
#echo OCF_RESKEY_admin_address=$OCF_RESKEY_admin_address >> /tmp/prox_conf_$OCF_RESOURCE_INSTANCE
#echo OCF_RESKEY_admin_username=$OCF_RESKEY_admin_username >> /tmp/prox_conf_$OCF_RESOURCE_INSTANCE
#echo OCF_RESKEY_admin_password=$OCF_RESKEY_admin_password >> /tmp/prox_conf_$OCF_RESOURCE_INSTANCE
#echo OCF_RESKEY_admin_lua_script=$OCF_RESKEY_admin_lua_script >> /tmp/prox_conf_$OCF_RESOURCE_INSTANCE
#echo OCF_RESKEY_parameters=$OCF_RESKEY_parameters >> /tmp/prox_conf_$OCF_RESOURCE_INSTANCE
#echo OCF_RESKEY_pidfile=$OCF_RESKEY_pidfile >> /tmp/prox_conf_$OCF_RESOURCE_INSTANCE
case $1 in
start) mysqlproxy_validate_all &&
mysqlproxy_start
exit $?
;;
stop) mysqlproxy_validate_all &&
mysqlproxy_stop
exit $?
;;
reload) mysqlproxy_reload
exit $?
;;
status) if mysqlproxy_status; then
ocf_log info "MySQL Proxy is running."
exit $OCF_SUCCESS
else
ocf_log info "MySQL Proxy is stopped."
exit $OCF_NOT_RUNNING
fi
;;
monitor) mysqlproxy_monitor
exit $?
;;
validate-all) mysqlproxy_validate_all
exit $?
;;
meta-data) meta_data
exit $?
;;
usage) usage
exit $OCF_SUCCESS
;;
*) usage
exit $OCF_ERR_UNIMPLEMENTED
;;
esac
|