diff --git a/heartbeat/Dummy.in b/heartbeat/Dummy.in index adb332747..3de49c17d 100644 --- a/heartbeat/Dummy.in +++ b/heartbeat/Dummy.in @@ -1,199 +1,198 @@ #!/bin/sh # # # Dummy OCF RA. Does nothing but wait a few seconds, can be # configured to fail occassionally. # # Copyright (c) 2004 SUSE LINUX AG, Lars Marowsky-Br�e # All Rights Reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of version 2 of the GNU General Public License as # published by the Free Software Foundation. # # This program is distributed in the hope that it would be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # # Further, this software is distributed without any warranty that it is # free of the rightful claim of any third person regarding infringement # or the like. Any license provided herein, whether implied or # otherwise, applies only to this software file. Patent licenses, if # any, provided herein do not apply to combinations of this program with # other software, or any other product whatsoever. # # You should have received a copy of the GNU General Public License # along with this program; if not, write the Free Software Foundation, # Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. # ####################################################################### # Initialization: . @hb_libdir@/ocf-shellfuncs ####################################################################### meta_data() { cat <<END <?xml version="1.0"?> <!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd"> <resource-agent name="Dummy" version="0.9"> <version>1.0</version> <longdesc lang="en"> This is a Dummy Resource Agent. It does absolutely nothing except wait for various amounts of time on execution. </longdesc> <shortdesc lang="en">Dummy resource agent</shortdesc> <parameters> <parameter name="delay" unique="0"> <longdesc lang="en"> How long to delay before each action. </longdesc> <shortdesc lang="en">Action delay</shortdesc> <content type="integer" default="5" /> </parameter> <parameter name="state" unique="1"> <longdesc lang="en"> Location to store the resource state in. </longdesc> <shortdesc lang="en">State file</shortdesc> <content type="string" default="" /> </parameter> -<parameters> <parameter name="check_parallel" unique="0"> <longdesc lang="en"> Complain loudly if they try to run us in parallel on the same resource. </longdesc> <shortdesc lang="en">Report error if run twice at the same time</shortdesc> <content type="boolean" default="true" /> </parameter> </parameters> <actions> <action name="start" timeout="90" /> <action name="stop" timeout="100" /> <action name="monitor" timeout="20" interval="10" depth="0" start-delay="0" /> <action name="reload" timeout="90" /> <action name="migrate_to" timeout="100" /> <action name="migrate_from" timeout="90" /> <action name="meta-data" timeout="5" /> <action name="verify-all" timeout="30" /> </actions> </resource-agent> END } ####################################################################### # don't exit on TERM, to test that lrmd makes sure that we do exit trap sigterm_handler TERM sigterm_handler() { ocf_log info "They use TERM to bring us down. No such luck." return } dummy_usage() { cat <<END usage: $0 {start|stop|monitor|migrate_to|migrate_from|validate-all|meta-data} Expects to have a fully populated OCF RA-compliant environment set. END } # dejan said: what is this for? # dummy_exit() { if [ -e /tmp/Dummy.$__OCF_ACTION ]; then exit $OCF_ERR_GENERIC else exit $1 fi } # signals interrupt slow calls (sleep) # this is an approximation (after all it's just a dummy) sleepsleep() { delay=$1 now=`perl -e 'print time()'` by=$((now+delay)) while [ $now -lt $by ]; do ocf_log debug "Gonna sleep for $((by-now)) seconds..." sleep $((by-now)) now=`perl -e 'print time()'` done } dummy_start() { sleepsleep $OCF_RESKEY_delay ha_pseudo_resource Dummy_${OCF_RESKEY_instance} start ${OCF_RESKEY_state} } dummy_stop() { sleepsleep $OCF_RESKEY_delay ha_pseudo_resource Dummy_${OCF_RESKEY_instance} stop ${OCF_RESKEY_state} } dummy_monitor() { sleepsleep $OCF_RESKEY_delay ha_pseudo_resource Dummy_${OCF_RESKEY_instance} monitor ${OCF_RESKEY_state} } dummy_validate() { exit $OC_ERR_UNIMPLEMENTED } : ${OCF_RESKEY_delay=1} : ${OCF_RESKEY_check_parallel=1} lockf=` ha_pseudo_resource Dummy_${OCF_RESOURCE_INSTANCE} print ${OCF_RESKEY_state} | sed 's/$/.lock/' ` check4parallel() { if [ -f "$lockf" ] && kill -0 `cat $lockf` 2>/dev/null then ocf_log err "There is another instance of ${OCF_RESOURCE_INSTANCE} running: pid `cat $lockf`." exit $OCF_ERR_GENERIC fi } [ "$OCF_RESKEY_check_parallel" = 1 ] && check4parallel echo $$ > $lockf trap "rm -f $lockf" EXIT case $__OCF_ACTION in meta-data) meta_data exit $OCF_SUCCESS ;; start) dummy_start;; stop) dummy_stop;; monitor) dummy_monitor;; migrate_to) ocf_log info "Migrating ${OCF_RESOURCE_INSTANCE} to ${OCF_RESKEY_CRM_meta_migrate_to}." dummy_stop ;; migrate_from) ocf_log info "Migrating ${OCF_RESOURCE_INSTANCE} to ${OCF_RESKEY_CRM_meta_migrated_from}." dummy_start ;; reload) ocf_log err "Reloading..." dummy_start ;; validate-all) dummy_validate;; usage|help) dummy_usage exit $OCF_SUCCESS ;; *) dummy_usage exit $OCF_ERR_UNIMPLEMENTED ;; esac rc=$? ocf_log debug "${OCF_RESOURCE_INSTANCE} $__OCF_ACTION : $rc" dummy_exit $rc diff --git a/heartbeat/drbd.in b/heartbeat/drbd.in index ac250587b..a8dc92ed2 100644 --- a/heartbeat/drbd.in +++ b/heartbeat/drbd.in @@ -1,596 +1,596 @@ #!/bin/sh # # # OCF Resource Agent compliant drbd resource script. # # Copyright (c) 2004 - 2007 SUSE LINUX Products GmbH, Lars Marowsky-Bree # All Rights Reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of version 2 of the GNU General Public License as # published by the Free Software Foundation. # # This program is distributed in the hope that it would be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # # Further, this software is distributed without any warranty that it is # free of the rightful claim of any third person regarding infringement # or the like. Any license provided herein, whether implied or # otherwise, applies only to this software file. Patent licenses, if # any, provided herein do not apply to combinations of this program with # other software, or any other product whatsoever. # # You should have received a copy of the GNU General Public License # along with this program; if not, write the Free Software Foundation, # Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. # # # OCF instance parameters # OCF_RESKEY_drbd_resource # OCF_RESKEY_drbdconf # OCF_RESKEY_CRM_meta_clone_max # OCF_RESKEY_CRM_meta_clone_node_max # OCF_RESKEY_master_max # OCF_RESKEY_master_node_max ####################################################################### # Initialization: if [ -n "$OCF_DEBUG_LIBRARY" ]; then . $OCF_DEBUG_LIBRARY else . @hb_libdir@/ocf-shellfuncs fi ####################################################################### meta_data() { cat <<END <?xml version="1.0"?> <!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd"> <resource-agent name="drbd"> <version>1.1</version> <longdesc lang="en"> Master/Slave OCF Resource Agent for DRBD </longdesc> <shortdesc lang="en">This resource agent manages a Distributed Replicated Block Device (DRBD) object as a master/slave resource. DRBD is a mechanism for replicating storage; please see the documentation for setup details.</shortdesc> <parameters> <parameter name="drbd_resource" unique="1" required="1"> <longdesc lang="en"> The name of the drbd resource from the drbd.conf file. </longdesc> <shortdesc lang="en">drbd resource name</shortdesc> <content type="string" default="drbd0" /> </parameter> <parameter name="drbdconf"> <longdesc lang="en"> Full path to the drbd.conf file. </longdesc> <shortdesc lang="en">Path to drbd.conf</shortdesc> <content type="string" default="/etc/drbd.conf"/> </parameter> <parameter name="clone_overrides_hostname"> <longdesc lang="en"> Whether or not to override the hostname with the clone number. This can be used to create floating peer configurations; drbd will be told to -use node_≤cloneno≥ as the hostname instead of the real uname, +use node_<cloneno> as the hostname instead of the real uname, which can then be used in drbd.conf. </longdesc> <shortdesc lang="en">Override drbd hostname</shortdesc> <content type="boolean" default="no"/> </parameter> <parameter name="clone_max" required="1"> <longdesc lang="en"> Number of clones of this drbd resource. Do not fiddle with the default. </longdesc> <shortdesc lang="en">Number of clones</shortdesc> <content type="integer" default="2"/> </parameter> <parameter name="clone_node_max" required="1"> <longdesc lang="en"> Clones per node. Do not fiddle with the default. </longdesc> <shortdesc lang="en">Number of nodes</shortdesc> <content type="integer" default="1"/> </parameter> <parameter name="master_max" required="1"> <longdesc lang="en"> Maximum number of active primaries. Do not fiddle with the default. </longdesc> <shortdesc lang="en">Number of primaries</shortdesc> <content type="integer" default="1"/> </parameter> <parameter name="master_node_max" required="1"> <longdesc lang="en"> Maximum number of primaries per node. Do not fiddle with the default. </longdesc> <shortdesc lang="en">Number of primaries per node</shortdesc> <content type="integer" default="1"/> </parameter> </parameters> <actions> <action name="start" timeout="240" /> <action name="promote" timeout="90" /> <action name="demote" timeout="90" /> <action name="notify" timeout="90" /> <action name="stop" timeout="100" /> <action name="monitor" depth="0" timeout="20" interval="20" start-delay="1m" role="Slave" /> <action name="monitor" depth="0" timeout="20" interval="10" start-delay="1m" role="Master" /> <action name="meta-data" timeout="5" /> <action name="validate-all" timeout="30" /> </actions> </resource-agent> END exit $OCF_SUCCESS } do_cmd() { local cmd="$*" ocf_log debug "$RESOURCE: Calling $cmd" local cmd_out=$($cmd 2>&1) ret=$? if [ $ret -ne 0 ]; then ocf_log err "$RESOURCE: Called $cmd" ocf_log err "$RESOURCE: Exit code $ret" ocf_log err "$RESOURCE: Command output: $cmd_out" else ocf_log debug "$RESOURCE: Exit code $ret" ocf_log debug "$RESOURCE: Command output: $cmd_out" fi echo $cmd_out return $ret } do_drbdadm() { local cmd="$DRBDADM -c $DRBDCONF $*" ocf_log debug "$RESOURCE: Calling $cmd" local cmd_out=$($cmd 2>&1) ret=$? # Trim the garbage drbdadm likes to print when using the node # override feature: local cmd_ret=$(echo $cmd_out | sed -e 's/found __DRBD_NODE__.*<<//;') if [ $ret -ne 0 ]; then ocf_log err "$RESOURCE: Called $cmd" ocf_log err "$RESOURCE: Exit code $ret" ocf_log err "$RESOURCE: Command output: $cmd_ret" else ocf_log debug "$RESOURCE: Exit code $ret" ocf_log debug "$RESOURCE: Command output: $cmd_ret" fi echo $cmd_ret return $ret } drbd_init() { DRBDADM=$(which drbdadm 2>/dev/null) CRM_MASTER=@sbindir@/crm_master RESOURCE="$OCF_RESKEY_drbd_resource" CLONE_NO="$OCF_RESKEY_CRM_meta_clone" DRBDCONF="${OCF_RESKEY_drbdconf:=/etc/drbd.conf}" if [ -z "$DRBDADM" -o ! -x "$DRBDADM" ]; then ocf_log err "drbdadm not installed." if [ '$ACTION' = 'monitor' ]; then exit $OCF_NOT_RUNNING else exit $OCF_ERR_INSTALLED fi fi if [ ! -f "$DRBDCONF" ]; then ocf_log err "drbd.conf not installed." if [ '$ACTION' = 'monitor' ]; then exit $OCF_NOT_RUNNING else exit $OCF_ERR_INSTALLED fi fi case "$OCF_RESKEY_clone_overrides_hostname" in [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) __DRBD_NODE__="node_${CLONE_NO}" export __DRBD_NODE__ ocf_log info "$RESOURCE: Using hostname $__DRBD_NODE__" ;; esac } ####################################################################### drbd_usage() { cat <<END usage: $0 {start|stop|monitor|validate-all|promote|demote|notify|meta-data} Expects to have a fully populated OCF RA-compliant environment set. END } is_drbd_enabled () { if [ -f /proc/drbd ]; then return 0 fi return 1 } drbd_get_status() { DRBD_STATE=$(do_drbdadm state $RESOURCE) DRBD_STATE_LOCAL=$(echo $DRBD_STATE | sed -e 's#/.*##') DRBD_STATE_REMOTE=$(echo $DRBD_STATE | sed -e 's#.*/##') DRBD_CSTATE=$(do_drbdadm cstate $RESOURCE) # Sanitize the various states, drbdadm is quite annoying; so if it # outputs something which doesn't make sense, translate it into # a harmless state: case "$DRBD_STATE_LOCAL" in "Not configured"|"Primary"|"Secondary") ;; *) DRBD_STATE_LOCAL="Not configured" ;; esac case "$DRBD_STATE_REMOTE" in "Primary"|"Secondary"|"Unknown") ;; *) DRBD_STATE_REMOTE="Not configured" ;; esac case "$DRBD_CSTATE" in Unconfigured|StandAlone|Unconnected|Timeout|BrokenPipe) ;; NetworkFailure|WFConnection|WFReportParams|Connected|SkippedSyncS) ;; SkippedSyncT|WFBitMapS|WFBitMapT|SyncSource|SyncTarget) ;; PausedSyncS|PausedSyncT) ;; *) DRBD_CSTATE="Unconfigured" ;; esac ocf_log debug "$RESOURCE status: $DRBD_STATE $DRBD_STATE_LOCAL $DRBD_STATE_REMOTE $DRBD_CSTATE" } drbd_start() { if is_drbd_enabled; then : OK else do_cmd modprobe -s drbd `$DRBDADM sh-mod-parms` || { ocf_log err "Cannot load the drbd module."$'\n'; return $OCF_ERR_GENERIC } ocf_log debug "$RESOURCE start: Module loaded." fi drbd_get_status if [ "$DRBD_STATE_LOCAL" != "Not configured" ]; then ocf_log debug "$RESOURCE start: already configured." return $OCF_SUCCESS fi if do_drbdadm up $RESOURCE ; then drbd_get_status if [ "$DRBD_STATE_LOCAL" != "Secondary" ]; then ocf_log err "$RESOURCE start: not in Secondary mode after start." return $OCF_ERR_GENERIC fi ocf_log debug "$RESOURCE start: succeeded." return $OCF_SUCCESS else ocf_log err "$RESOURCE: Failed to start up." return $OCF_ERR_GENERIC fi } drbd_update_prefs() { drbd_get_status # TODO: This is probably way too complex. case $DRBD_CSTATE in Connected) do_cmd $CRM_MASTER -v 75 -l reboot ;; SyncSource|PausedSyncS|WFBitMapS|SkippedSyncS) do_cmd $CRM_MASTER -v 100 -l reboot ;; # TODO: # (Inconsistent || Diskless && WFConnection) should be -infinity # This one implies we'll try to promote even on disconnected # nodes, but that might not work. WFConnection) do_cmd $CRM_MASTER -v 10 -l reboot ;; *) do_cmd $CRM_MASTER -v 5 -l reboot ;; esac return $OCF_SUCCESS } drbd_stop() { # Do not bother if drbd is not enabled if is_drbd_enabled; then drbd_get_status # Clear preference for becoming master do_cmd $CRM_MASTER -D if [ "$DRBD_STATE_LOCAL" = "Not configured" ]; then ocf_log debug "$RESOURCE stop: already unconfigured." return $OCF_SUCCESS fi # TODO: this is a _force_ operation. we may need to kill higher # levels to be able to down drbd. figure out how... if do_drbdadm down $RESOURCE ; then ocf_log debug "$RESOURCE stop: drbdadm down succeeded." # TODO: If drbdadm propagated error codes, this # wouldn't be needed. drbd_get_status if [ "$DRBD_STATE_LOCAL" = "Not configured" ]; then return $OCF_SUCCESS else ocf_log err "$RESOURCE stop: Not stopped." fi else ocf_log err "$RESOURCE stop: Failed with exit code: $?" fi return $OCF_ERR_GENERIC else ocf_log debug "$RESOURCE stop: drbd not loaded." fi return $OCF_SUCCESS } drbd_monitor() { # TODO: Think about how to monitor drbd and what constitutes # failure cases... # diskless etc? # A secondary node which is supposed to be primary? # TODO: we ought to update the preferences here occasionally, # but that causes transitions right now ... if is_drbd_enabled; then : OK else ocf_log warn "$RESOURCE monitor: drbd module not loaded" return $OCF_NOT_RUNNING fi drbd_get_status if [ "$DRBD_STATE_LOCAL" = "Not configured" ]; then ocf_log debug "$RESOURCE monitor: resource not configured" return $OCF_NOT_RUNNING elif [ "$DRBD_STATE_LOCAL" = "Primary" ]; then # drbd_update_prefs return $OCF_RUNNING_MASTER elif [ "$DRBD_STATE_LOCAL" = "Secondary" ]; then # drbd_update_prefs return $OCF_SUCCESS else ocf_log err "$RESOURCE monitor: unexpected local state: $DRBD_STATE_LOCAL" fi return $OCF_ERR_GENERIC } drbd_promote() { if is_drbd_enabled; then : OK else ocf_log err "drbd is not enabled" return $OCF_ERR_GENERIC fi drbd_get_status if [ "$DRBD_STATE_LOCAL" = "Primary" ]; then ocf_log info "$RESOURCE promote: already primary" return $OCF_SUCCESS fi if [ "$DRBD_STATE_LOCAL" != "Secondary" ]; then ocf_log warn "$RESOURCE promote: Not secondary to start with." return $OCF_ERR_GENERIC fi if do_drbdadm primary $RESOURCE ; then # TODO: WORK AROUND because drbdadm has a bug and # reports success even if it failed :-( drbd_get_status if [ "$DRBD_STATE_LOCAL" = "Primary" ]; then ocf_log info "$RESOURCE promote: primary succeeded" return $OCF_SUCCESS else ocf_log err "$RESOURCE promote: Not primary despite drbdadm call." fi else ocf_log err "$RESOURCE promote: Failed with exit code $?." fi return $OCF_ERR_GENERIC } drbd_demote() { if is_drbd_enabled; then : OK else # A stopped resource also is demoted. ocf_log debug "$RESOURCE demote: module not loaded" return $OCF_SUCCESS fi if [ "$DRBD_STATE_LOCAL" = "Secondary" ]; then ocf_log debug "$RESOURCE demote: already secondary" return $OCF_SUCCESS fi if [ "$DRBD_STATE_LOCAL" = "Not configured" ]; then ocf_log debug "$RESOURCE demote: already stopped" return $OCF_NOT_RUNNING fi # TODO: this is a _force_ operation. we may need to kill higher # levels (or switch them to r/o) to be able to demote drbd. # figure out how... if do_drbdadm secondary $RESOURCE ; then if [ "$DRBD_STATE_LOCAL" = "Primary" ]; then ocf_log err "$RESOURCE demote: still primary!" return $OCF_ERR_GENERIC fi ocf_log debug "$RESOURCE demote: succeeded" return $OCF_SUCCESS else ocf_log err "$RESOURCE demote: Failed with exit code $?." return $OCF_ERR_GENERIC fi } drbd_notify() { local n_type="$OCF_RESKEY_CRM_meta_notify_type" local n_op="$OCF_RESKEY_CRM_meta_notify_operation" set -- $OCF_RESKEY_CRM_meta_notify_active_resource local n_active="$#" set -- $OCF_RESKEY_CRM_meta_notify_stop_resource local n_stop="$#" set -- $OCF_RESKEY_CRM_meta_notify_start_resource local n_start="$#" ocf_log debug "$RESOURCE notify: $n_type for $n_op - counts: active $n_active - starting $n_start - stopping $n_stop" case $n_type in pre) case $n_op in promote) # TODO: # Resist promotion of the other side in case we # are already primary - though the CRM should # not even attempt that. ;; esac ;; post) # TODO: Entire case statement which follows redundant? case $n_op in start) if [ "$n_active" -eq 2 ]; then # The other side is running, so we ought # to connect and wait for that. do_drbdadm connect $RESOURCE do_drbdadm wait_connect $RESOURCE # TODO: If this can cause a hang if the # other side isn't connected or goes # away during that, maybe just sleep # here for 5-10s or take out the entire # case statement fi ;; stop) # TODO BUG: disconnect seems to force # non-primary mode?!? #### do_drbdadm disconnect $RESOURCE # TODO: If we are secondary, do we need to do # anything about a stopped primary in case we # had an outdated flag...? ;; esac # After something has been done is a good time to # recheck our status: drbd_update_prefs ;; esac return $OCF_SUCCESS } drbd_validate_all () { # First check the configuration file if [ -n "$DRBDCONF" ] && [ ! -f "$DRBDCONF" ]; then ocf_log err "Configuration file does not exist: $DRBDCONF" return $OCF_ERR_CONFIGURED fi # Check the resource name, it should appear in DRBDCONF if [ -z "$RESOURCE" ]; then ocf_log err "No resource name specified!" return $OCF_ERR_ARGS fi if do_drbdadm dump $RESOURCE 2>/dev/null ; then : else ocf_log err "Invalid configuration file $DRBDCONF" return $OCF_ERR_CONFIGURED fi if [ "$OCF_RESKEY_CRM_meta_clone_max" -ne 2 ] \ || [ "$OCF_RESKEY_CRM_meta_clone_node_max" -ne 1 ] \ || [ "$OCF_RESKEY_master_node_max" -ne 1 ] \ || [ "$OCF_RESKEY_master_max" -ne 1 ] ; then ocf_log err "Clone options misconfigured." exit $OCF_ERR_CONFIGURED fi return $OCF_SUCCESS } if [ $# -ne 1 ]; then echo "Incorrect parameter count." drbd_usage exit $OCF_ERR_ARGS fi ACTION=$1 case $ACTION in meta-data) meta_data ;; validate-all) drbd_init drbd_validate_all ;; start|stop|monitor|promote|demote|notify) if ocf_is_root ; then : ; else ocf_log err "You must be root to perform this operation." exit $OCF_ERR_PERM fi drbd_init drbd_$ACTION exit $? ;; usage|help) drbd_usage exit $OCF_SUCCESS ;; *) drbd_usage exit $OCF_ERR_ARGS ;; esac diff --git a/heartbeat/mysql.in b/heartbeat/mysql.in index 458981a4a..e89a8b483 100644 --- a/heartbeat/mysql.in +++ b/heartbeat/mysql.in @@ -1,351 +1,351 @@ #!/bin/sh # # # MySQL # # Description: Manages a MySQL database as Linux-HA resource # # Author: Alan Robertson : DB2 Script # Author: Jakub Janczak : Rewrite as MySQL # Author: Andrew Beekhof : Cleanup and import # # Support: linux-ha@lists.linux-ha.org # License: GNU General Public License (GPL) # Copyright: (C) 2002 - 2005 International Business Machines, Inc. # # An example usage in /etc/ha.d/haresources: # node1 10.0.0.170 mysql # # See usage() function below for more details... # # OCF instance parameters: # OCF_RESKEY_mysql_config # OCF_RESKEY_mysql_datadir # OCF_RESKEY_mysql_user # OCF_RESKEY_mysql_group # OCF_RESKEY_mysql_test_table ####################################################################### # Initialization: . @hb_libdir@/ocf-shellfuncs ####################################################################### SH=/bin/sh # Fill in some defaults if no values are specified : ${OCF_RESKEY_binary="/usr/bin/safe_mysqld"} MYSQL_BINDIR=`dirname ${OCF_RESKEY_binary}` : ${OCF_RESKEY_config="/etc/my.cnf"} : ${OCF_RESKEY_datadir="/var/lib/mysql"} : ${OCF_RESKEY_user="mysql"} : ${OCF_RESKEY_group="mysql"} : ${OCF_RESKEY_log="/var/log/mysqld.log"} : ${OCF_RESKEY_pid="/var/run/mysql/mysqld.pid"} : ${OCF_RESKEY_socket="/var/lib/mysql/mysql.sock"} : ${OCF_RESKEY_test_user="root"} : ${OCF_RESKEY_test_table="mysql.user"} : ${OCF_RESKEY_test_passwd=""} : ${OCF_RESKEY_enable_creation=0} usage() { cat <<UEND usage: $0 (start|stop|validate-all|meta-data|monitor) $0 manages a MySQL Database as an HA resource. The 'start' operation starts the database. The 'stop' operation stops the database. The 'status' operation reports whether the database is running The 'monitor' operation reports whether the database seems to be working The 'validate-all' operation reports whether the parameters are valid UEND } meta_data() { cat <<END <?xml version="1.0"?> <!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd"> <resource-agent name="mysql"> <version>1.0</version> <longdesc lang="en"> Resource script for MySQL. It manages a MySQL Database instance as an HA resource. </longdesc> <shortdesc lang="en">MySQL resource agent</shortdesc> <parameters> <parameter name="binary" unique="0" required="0"> <longdesc lang="en"> Location of the MySQL binary </longdesc> <shortdesc lang="en">MySQL binary</shortdesc> <content type="string" default="/usr/bin/safe_mysqld" /> </parameter> <parameter name="config" unique="0" required="0"> <longdesc lang="en"> Configuration file </longdesc> <shortdesc lang="en">MySQL config</shortdesc> <content type="string" default="/etc/my.cnf" /> </parameter> <parameter name="datadir" unique="0" required="0"> <longdesc lang="en"> Directory containing databases </longdesc> <shortdesc lang="en">MySQL datadir</shortdesc> <content type="string" default="/var/lib/mysql" /> </parameter> <parameter name="user" unique="0" required="0"> <longdesc lang="en"> User running MySQL daemon </longdesc> <shortdesc lang="en">MySQL user</shortdesc> <content type="string" default="mysql" /> </parameter> <parameter name="group" unique="0" required="0"> <longdesc lang="en"> Group running MySQL daemon (for logfile and directory permissions) </longdesc> <shortdesc lang="en">MySQL group</shortdesc> <content type="string" default="mysql"/> </parameter> <parameter name="test_table" unique="0" required="0"> <longdesc lang="en"> -Table to be tested in monitor statement (in <database>.<table> notation) +Table to be tested in monitor statement (in database.table notation) </longdesc> <shortdesc lang="en">MySQL test table</shortdesc> <content type="string" default="mysql.user" /> </parameter> <parameter name="test_user" unique="0" required="0"> <longdesc lang="en"> MySQL test user </longdesc> <shortdesc lang="en">MySQL test user</shortdesc> <content type="string" default="root" /> </parameter> <parameter name="test_passwd" unique="0" required="0"> <longdesc lang="en"> MySQL test user password </longdesc> <shortdesc lang="en">MySQL test user password</shortdesc> <content type="string" default="" /> </parameter> <parameter name="enable_creation" unique="0" required="0"> <longdesc lang="en"> If the MySQL database does not exist, it will be created </longdesc> <shortdesc lang="en">Create the database if it does not exist</shortdesc> <content type="integer" default="0"/> </parameter> </parameters> <actions> <action name="start" timeout="120" /> <action name="stop" timeout="120" /> <action name="status" timeout="60" /> <action name="monitor" depth="0" timeout="30" interval="10" start-delay="10" /> <action name="validate-all" timeout="5" /> <action name="meta-data" timeout="5" /> </actions> </resource-agent> END } mysql_validate() { # checking the parameters if [ ! -f $OCF_RESKEY_config ]; then ocf_log err "Config $OCF_RESKEY_mysql_config doesn't exist"; exit $OCF_ERR_ARGS; fi if [ ! -d $OCF_RESKEY_datadir ]; then ocf_log err "Datadir $OCF_RESKEY_datadir dosen't exist"; exit $OCF_ERR_ARGS; fi grep $OCF_RESKEY_user /etc/passwd >/dev/null 2>&1 if [ ! $? -eq 0 ]; then ocf_log err "User $OCF_RESKEY_user doesn't exit"; exit $OCF_ERR_ARGS; fi grep $OCF_RESKEY_test_user /etc/passwd >/dev/null 2>&1 if [ ! $? -eq 0 ]; then ocf_log err "Test user $OCF_RESKEY_test_user doesn't exit"; exit $OCF_ERR_ARGS; fi grep $OCF_RESKEY_group /etc/group >/dev/null 2>&1 if [ ! $? -eq 0 ]; then ocf_log err "Group $OCF_RESKEY_group doesn't exist"; exit $OCF_ERR_ARGS; fi } mysql_status() { if [ ! -e $OCF_RESKEY_pid ]; then ocf_log debug "MySQL is not running" return $OCF_NOT_RUNNING; fi pid=`cat $OCF_RESKEY_pid`; if [ -d /proc -a -d /proc/1 ]; then [ "u$pid" != "u" -a -d /proc/$pid ] else kill -0 $pid >/dev/null 2>&1 fi if [ $? -eq 0 ]; then return $OCF_SUCCESS; else ocf_log debug "MySQL not running: removing old PID file" rm -f $OCF_RESKEY_pid return $OCF_NOT_RUNNING; fi } mysql_monitor() { mysql_status rc=$? if [ $OCF_CHECK_LEVEL = 0 -o $rc != 0 ]; then return $rc fi # Do a detailed status check buf=`echo "SELECT * FROM $OCF_RESKEY_test_table" | mysql --user=$OCF_RESKEY_test_user --password=$OCF_RESKEY_test_passwd --socket=$OCF_RESKEY_socket -O connect_timeout=1 2>&1` rc=$? if [ ! $rc -eq 0 ]; then ocf_log err "MySQL $test_table monitor failed:"; if [ ! -z "$buf" ]; then ocf_log err $buf; fi return $OCF_ERR_GENERIC; else ocf_log info "MySQL monitor succeded"; return $OCF_SUCCESS; fi } mysql_start() { mysql_status if [ $? == $OCF_SUCCESS ]; then ocf_log info "MySQL already running" return $OCF_SUCCESS fi touch $OCF_RESKEY_log chown $OCF_RESKEY_user:$OCF_RESKEY_group $OCF_RESKEY_log chmod 0640 $OCF_RESKEY_log [ -x /sbin/restorecon ] && /sbin/restorecon $OCF_RESKEY_log if [ $OCF_RESKEY_enable_creation -a ! -d $OCF_RESKEY_datadir/mysql ] ; then ocf_log info "Initializing MySQL database: " $MYSQL_BINDIR/mysql_install_db --datadir=$OCF_RESKEY_datadir rc=$? if [ $rc -ne 0 ] ; then ocf_log err "Initialization failed: $rc"; exit $OCF_ERR_GENERIC fi chown -R $OCF_RESKEY_user:$OCF_RESKEY_group $OCF_RESKEY_datadir fi # Uncomment to perform permission clensing # - not convinced this should be enabled by default # #chmod 0755 $OCF_RESKEY_datadir #chown -R $OCF_RESKEY_user $OCF_RESKEY_datadir #chgrp -R $OCF_RESKEY_group $OCF_RESKEY_datadir ${OCF_RESKEY_binary} --defaults-file=$OCF_RESKEY_config --pid-file=$OCF_RESKEY_pid --socket=$OCF_RESKEY_socket --datadir=$OCF_RESKEY_datadir --user=$OCF_RESKEY_user >/dev/null 2>&1 & rc=$? if [ $rc != 0 ]; then ocf_log err "MySQL start command failed: $rc" return $rc fi # Spin waiting for the server to come up. # Let the CRM/LRM time us out if required start_wait=1 while [ $start_wait = 1 ]; do mysql_status rc=$? if [ $rc = $OCF_SUCCESS ]; then start_wait=0 elif [ $rc != $OCF_NOT_RUNNING ]; then ocf_log info "MySQL start failed: $rc" return $rc fi sleep 2 done ocf_log info "MySQL started" return $OCF_SUCCESS } mysql_stop() { if [ ! -f $OCF_RESKEY_pid ]; then return $OCF_SUCCESS fi pid=`cat $OCF_RESKEY_pid 2> /dev/null ` /bin/kill $pid > /dev/null 2>&1 rc=$? if [ $rc != 0 ]; then ocf_log err "MySQL couldn't be stopped" return $OCF_ERR_GENERIC fi stop_wait=1 while [ $stop_wait = 1 ]; do mysql_status rc=$? if [ $rc == $OCF_NOT_RUNNING ]; then stop_wait=0 fi sleep 1 done ocf_log info "MySQL stopped"; rm -f /var/lock/subsys/mysqld rm -f $OCF_RESKEY_datadir/mysql.sock return $OCF_SUCCESS } # What kind of method was invoked? case "$1" in start) mysql_validate; mysql_start;; stop) mysql_stop;; status) mysql_status;; monitor) mysql_monitor;; meta-data) meta_data; exit $OCF_SUCCESS;; validate-all) mysql_validate; exit $OCF_SUCCESS;; *) usage exit $OCF_ERR_UNIMPLEMENTED;; esac exit $?