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 < 1.0 This is a Dummy Resource Agent. It does absolutely nothing except wait for various amounts of time on execution. Dummy resource agent How long to delay before each action. Action delay Location to store the resource state in. State file - Complain loudly if they try to run us in parallel on the same resource. Report error if run twice at the same time 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 </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 < 1.1 Master/Slave OCF Resource Agent for DRBD 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. The name of the drbd resource from the drbd.conf file. drbd resource name Full path to the drbd.conf file. Path to drbd.conf 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. Override drbd hostname Number of clones of this drbd resource. Do not fiddle with the default. Number of clones Clones per node. Do not fiddle with the default. Number of nodes Maximum number of active primaries. Do not fiddle with the default. Number of primaries Maximum number of primaries per node. Do not fiddle with the default. Number of primaries per node 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__.*</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 </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 < 1.0 Resource script for MySQL. It manages a MySQL Database instance as an HA resource. MySQL resource agent Location of the MySQL binary MySQL binary Configuration file MySQL config Directory containing databases MySQL datadir User running MySQL daemon MySQL user Group running MySQL daemon (for logfile and directory permissions) MySQL group -Table to be tested in monitor statement (in . notation) +Table to be tested in monitor statement (in database.table notation) MySQL test table MySQL test user MySQL test user MySQL test user password MySQL test user password If the MySQL database does not exist, it will be created Create the database if it does not exist 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 $?