From mboxrd@z Thu Jan 1 00:00:00 1970 From: mgrac@sourceware.org Date: 31 Aug 2006 13:52:21 -0000 Subject: [Cluster-devel] cluster/rgmanager/src/resources mysql.metadata ... Message-ID: <20060831135221.2755.qmail@sourceware.org> List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit CVSROOT: /cvs/cluster Module name: cluster Changes by: mgrac at sourceware.org 2006-08-31 13:52:21 Added files: rgmanager/src/resources: mysql.metadata mysql.sh rgmanager/src/resources/utils: config-utils.sh messages.sh Log message: Bug #204054. Adding MySQL resource agents and utilities which will be common for other RA. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/rgmanager/src/resources/mysql.metadata.diff?cvsroot=cluster&r1=NONE&r2=1.1 http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/rgmanager/src/resources/mysql.sh.diff?cvsroot=cluster&r1=NONE&r2=1.1 http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/rgmanager/src/resources/utils/config-utils.sh.diff?cvsroot=cluster&r1=NONE&r2=1.1 http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/rgmanager/src/resources/utils/messages.sh.diff?cvsroot=cluster&r1=NONE&r2=1.1 /cvs/cluster/cluster/rgmanager/src/resources/mysql.metadata,v --> standard output revision 1.1 --- cluster/rgmanager/src/resources/mysql.metadata +++ - 2006-08-31 13:52:21.520208000 +0000 @@ -0,0 +1,76 @@ + + + 1.0 + + + This defines an instance of MySQL database server + + + Defines a MySQL database server + + + + + + Define a name + + + Name + + + + + + + Define configuration file + + + Define configuration file + + + + + + + Define an IP address for MySQL + + + Define an IP address for MySQL server. If the address + is not given then first IP address from the service is taken. + + + + + + + Inherit the service name. We need to know + the service name in order to determine file + systems and IPs for this service. + + + Inherit the service name. + + + + + + + + + + + + + + + + + + + + + + + + + /cvs/cluster/cluster/rgmanager/src/resources/mysql.sh,v --> standard output revision 1.1 --- cluster/rgmanager/src/resources/mysql.sh +++ - 2006-08-31 13:52:21.598241000 +0000 @@ -0,0 +1,207 @@ +#!/bin/bash + +# +# Copyright Red Hat, Inc. 2006 +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2, or (at your option) any +# later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; see the file COPYING. If not, write to the +# Free Software Foundation, Inc., 675 Mass Ave, Cambridge, +# MA 02139, USA. +# +# +# Author(s): +# Marek Grac (mgrac at redhat.com) +# + +export LC_ALL=C +export LANG=C +export PATH=/bin:/sbin:/usr/bin:/usr/sbin + +declare MYSQL_MYSQLD=/usr/bin/mysqld_safe +declare MYSQL_ipAddress +declare MYSQL_pidFile="/var/run/mysqld/mysql.$OCF_RESKEY_name.pid" +declare MYSQL_timeout=30 + +. $(dirname $0)/ocf-shellfuncs +. $(dirname $0)/utils/config-utils.sh +. $(dirname $0)/utils/messages.sh + +verify_all() +{ + clog_service_verify $CLOG_INIT + + if [ -z "$OCF_RESKEY_name" ]; then + clog_service_verify $CLOG_FAILED "Invalid Name Of Service" + return $OCF_ERR_ARGS + fi + + if [ -z "$OCF_RESKEY_configFile" ]; then + clog_check_file_exist $CLOG_FAILED_INVALID + clog_service_verify $CLOG_FAILED + return $OCF_ERR_ARGS + fi + + if [ ! -r "$OCF_RESKEY_configFile" ]; then + clog_check_file_exist $CLOG_FAILED_NOT_READABLE $OCF_RESKEY_configFile + clog_service_verify $CLOG_FAILED + return $OCF_ERR_ARGS + fi + + if [ -z "$MYSQL_pidFile" ]; then + clog_service_verify $CLOG_FAILED "Invalid name of PID file" + return $OCF_ERR_ARGS + fi + + clog_service_verify $CLOG_SUCCEED + return 0 +} + +start() +{ + declare ccs_fd; + + clog_service_start $CLOG_INIT + + if [ -e "$MYSQL_pidFile" ]; then + clog_check_pid $CLOG_FAILED "$MYSQL_pidFile" + clog_service_start $CLOG_FAILED + return $OCF_GENERIC_ERROR + fi + + if [ -n "$OCF_RESKEY_ipAddress" ]; then + MYSQL_ipAddress="$OCF_RESKEY_ipAddress" + else + clog_looking_for $CLOG_INIT "IP Address" + + ccs_fd=$(ccs_connect); + if [ $? -ne 0 ]; then + clog_looking_for $CLOG_FAILED_CCS + return $OCF_GENERIC_ERROR + fi + + get_service_ip_keys "$ccs_fd" "$OCF_RESKEY_service_name" + ip_addresses=`build_ip_list "$ccs_fd"` + + if [ -n "$ip_addresses" ]; then + for i in $ip_addresses; do + MYSQL_ipAddress="$i" + break; + done + else + clog_looking_for $CLOG_FAILED_NOT_FOUND "IP Address" + fi + fi + + clog_looking_for $CLOG_SUCCEED "IP Address" + + $MYSQL_MYSQLD --defaults-file="$OCF_RESKEY_configFile" \ + --pid-file="$MYSQL_pidFile" \ + --bind-address="$MYSQL_ipAddress" > /dev/null 2>&1 & + + if [ $? -ne 0 ]; then + clog_service_start $CLOG_FAILED + return $OCF_GENERIC_ERROR + fi + + while [ "$MYSQL_timeout" -gt 0 ]; do + if [ -f "$MYSQL_pidFile" ]; then + break; + fi + sleep 1 + let MYSQL_timeout=${MYSQL_timeout}-1 + done + + if [ "$MYSQL_timeout" -eq 0 ]; then + clog_service_start $CLOG_FAILED_TIMEOUT + return $OCF_GENERIC_ERROR + fi + + clog_service_start $CLOG_SUCCEED + + return 0; +} + +stop() +{ + clog_service_stop $CLOG_INIT + + if [ ! -e "$MYSQL_pidFile" ]; then + clog_check_file_exist $CLOG_FAILED_NOT_FOUND "$MYSQL_pidFile" + clog_service_stop $CLOG_FAILED + return $OCF_GENERIC_ERROR + fi + + kill `cat "$MYSQL_pidFile"` + + if [ $? -ne 0 ]; then + clog_service_stop $CLOG_FAILED + return $OCF_GENERIC_ERROR + else + clog_service_stop $CLOG_SUCCEED + fi + + return 0; +} + +status() +{ + clog_service_status $CLOG_INIT + + if [ ! -e "$MYSQL_pidFile" ]; then + clog_check_file_exist $CLOG_FAILED_NOT_FOUND "$MYSQL_pidFile" + clog_service_statuts $CLOG_FAILED + return $OCF_GENERIC_ERROR + fi + + if [ ! -d /proc/`cat "$MYSQL_pidFile"` ]; then + clog_service_status $CLOG_FAILED + return $OCF_GENERIC_ERROR + fi + + clog_service_status $CLOG_SUCCEED + return 0 +} + +case $1 in + meta-data) + cat $(dirname $0)/mysql.metadata + exit 0 + ;; + verify-all) + verify_all + exit $? + ;; + start) + verify_all && start + exit $? + ;; + stop) + verify_all && stop + exit $? + ;; + status|monitor) + verify_all + status + exit $? + ;; + restart) + verify_all + stop + start + exit $? + ;; + *) + echo "Usage: $0 {start|stop|status|monitor|restart|meta-data|verify-all}" + exit $OCF_ERR_GENERIC + ;; +esac /cvs/cluster/cluster/rgmanager/src/resources/utils/config-utils.sh,v --> standard output revision 1.1 --- cluster/rgmanager/src/resources/utils/config-utils.sh +++ - 2006-08-31 13:52:21.679818000 +0000 @@ -0,0 +1,217 @@ +#!/bin/bash + +# +# Copyright Red Hat, Inc. 2006 +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2, or (at your option) any +# later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; see the file COPYING. If not, write to the +# Free Software Foundation, Inc., 675 Mass Ave, Cambridge, +# MA 02139, USA. +# + +declare -i FAIL=-1 +declare -a ip_keys + +generate_configTemplate() +{ + cat > $1 << EOT +# +# "$1" was created from the "$2" +# +# This template configuration was automatically generated, and will +# be automatically regenerated if removed. Please modify this file to +# speficy subdirectories and/or client access permissions. +# +# Once this file has been altered, automatic re-generation will stop. +# Remember to copy this file to all other cluster members after making +# changes, or your service will not operate correctly. +# +EOT +} + +sha1_addToFile() +{ + declare sha1line="# rgmanager-sha1 $(sha1sum "$1")" + echo $sha1line >> "$1" +} + +sha1_verify() +{ + declare sha1_new sha1_old + declare oldFile=$1 + + ocf_log debug "Checking: SHA1 checksum of config file $oldFile" + + sha1_new=`cat $oldFile | grep -v "# rgmanager-sha1" | sha1sum | sed 's/^\([a-z0-9]\+\) .*$/\1/'` + sha1_old=`tail -n 1 $oldFile | sed 's/^# rgmanager-sha1 \(.*\)$/\1/' | sed 's/^\([a-z0-9]\+\) .*$/\1/'` + + if [ $sha1_new = $sha1_old ]; then + ocf_log debug "Checking: SHA1 checksum > succeed" + return 0; + else + ocf_log debug "Checking: SHA1 checksum > failed - file changed" + return 1; + fi +} + +# +# Usage: ccs_connect +# Returns: $FAIL on failure, or a connection descriptor on success +# +ccs_connect() +{ + declare outp + + outp=$(ccs_test connect 2>&1) + if [ $? -ne 0 ]; then + ocf_log err "$outp" + return $FAIL + fi + + outp=${outp/*= /} + if [ -n "$outp" ]; then + echo $outp + return 0 + fi + + return 1 +} + +# +# Usage: ccs_disconnect descriptor +# +ccs_disconnect() +{ + declare outp + + [ -n "$1" ] || return $FAIL + outp=$(ccs_test disconnect $1 2>&1) + if [ $? -ne 0 ]; then + ocf_log warn "Disconnect CCS desc $1 failed: $outp" + return 1 + fi + return 0 +} + +# +# Usage: ccs_get desc key +# +ccs_get() +{ + declare outp + declare ccsfd=$1 + declare key + + [ -n "$1" ] || return $FAIL + [ -n "$2" ] || return $FAIL + + shift + key="$*" + + outp=$(ccs_test get $ccsfd "$key" 2>&1) + if [ $? -ne 0 ]; then + if [ "$outp" = "${outp/No data available/}" ]; then + ocf_log err "$outp ($key)" + return $FAIL + fi + + # no real error, just no data available + return 0 + fi + + outp=${outp/**/} + + echo $outp + + return 0 +} + +# +# Build a list of service IP keys; traverse refs if necessary +# Usage: get_service_ip_keys desc serviceName +# +get_service_ip_keys() +{ + declare ccsfd=$1 + declare svc=$2 + declare -i x y=0 + declare outp + declare key + + if [ $ccsfd -eq $FAIL ]; then + ocf_log err "Can not talk to ccsd: invalid descriptor $ccsfd" + return 1 + fi + + # + # Find service-local IP keys + # + x=1 + while : ; do + key="/cluster/rm/service[@name=\"$svc\"]/ip[$x]" + + # + # Try direct method + # + outp=$(ccs_get $ccsfd "$key/@address") + if [ $? -ne 0 ]; then + return 1 + fi + + # + # Try by reference + # + if [ -z "$outp" ]; then + outp=$(ccs_get $ccsfd "$key/@ref") + if [ $? -ne 0 ]; then + return 1 + fi + key="/cluster/rm/resources/ip[@address=\"$outp\"]" + fi + + if [ -z "$outp" ]; then + break + fi + + #ocf_log debug "IP $outp found @ $key" + + ip_keys[$y]="$key" + + ((y++)) + ((x++)) + done + + ocf_log debug "$y IP addresses found for $svc/$OCF_RESKEY_name" + + return 0 +} + +build_ip_list() +{ + declare -i ccsfd=$1 + declare ipaddrs ipaddr + declare -i x=0 + + while [ -n "${ip_keys[$x]}" ]; do + ipaddr=$(ccs_get $ccsfd "${ip_keys[$x]}/@address") + if [ -z "$ipaddr" ]; then + break + fi + + ipaddrs="$ipaddrs $ipaddr" + ((x++)) + done + + echo $ipaddrs +} \ No newline at end of file /cvs/cluster/cluster/rgmanager/src/resources/utils/messages.sh,v --> standard output revision 1.1 --- cluster/rgmanager/src/resources/utils/messages.sh +++ - 2006-08-31 13:52:21.758922000 +0000 @@ -0,0 +1,266 @@ +#!/bin/bash + +# +# Copyright Red Hat, Inc. 2006 +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2, or (at your option) any +# later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; see the file COPYING. If not, write to the +# Free Software Foundation, Inc., 675 Mass Ave, Cambridge, +# MA 02139, USA. +# +# Description: +# Catalog of log messages for resources agents +# +# Author(s): +# Marek Grac (mgrac at redhat.com) +# + +declare CLOG_INIT=100 +declare CLOG_SUCCEED=200 + +declare CLOG_FAILED=400 +declare CLOG_FAILED_TIMEOUT=401 +declare CLOG_FAILED_CCS=402 +declare CLOG_FAILED_NOT_FOUND=403 +declare CLOG_FAILED_INVALID=404 +declare CLOG_FAILED_NOT_READABLE=405 + +## +## Usage: +## clog_service_start %operation% +## +clog_service_start() +{ + case $1 in + $CLOG_INIT) + ocf_log info "Starting Service $OCF_RESOURCE_INSTANCE" + ;; + $CLOG_SUCCEED) + ocf_log debug "Starting Service $OCF_RESOURCE_INSTANCE > Succeed" + ;; + $CLOG_FAILED) + ocf_log error "Starting Service $OCF_RESOURCE_INSTANCE > Failed" + ;; + $CLOG_FAILED_TIMEOUT) + ocf_log error "Starting Service $OCF_RESOURCE_INSTANCE > Failed - Timeout Error" + ;; + esac + return 0 +} + +## +## Usage: +## clog_service_stop %operation% +## +clog_service_stop() +{ + case $1 in + $CLOG_INIT) + ocf_log info "Stopping Service $OCF_RESOURCE_INSTANCE" + ;; + $CLOG_SUCCEED) + ocf_log info "Stopping Service $OCF_RESOURCE_INSTANCE > Succeed" + ;; + $CLOG_FAILED) + ocf_log error "Stopping Service $OCF_RESOURCE_INSTANCE > Failed" + ;; + esac + return 0 +} + +## +## Usage: +## clog_service_status %operation% +## +clog_service_status() +{ + case $1 in + $CLOG_INIT) + ocf_log debug "Monitoring Service $OCF_RESOURCE_INSTANCE" + ;; + $CLOG_SUCCEED) + ocf_log debug "Monitoring Service $OCF_RESOURCE_INSTANCE > Service Is Running" + ;; + $CLOG_FAILED) + ocf_log error "Monitoring Service $OCF_RESOURCE_INSTANCE > Service Is Not Running" + ;; + $CLOG_FAILED_NOT_FOUND) + ocf_log error "Monitoring Service $OCF_RESOURCE_INSTANCE > Service Is Not Running - PID File Not Found" + ;; + esac + return 0 +} + +## +## Usage: +## clog_service_verify %operation% +## clog_service_verify $CLOG_FAILED %reason% +## +clog_service_verify() +{ + case $1 in + $CLOG_INIT) + ocf_log info "Verifying Configuration Of $OCF_RESOURCE_INSTANCE" + ;; + $CLOG_SUCCEED) + ocf_log debug "Verifying Configuration Of $OCF_RESOURCE_INSTANCE > Succeed" + ;; + $CLOG_FAILED) + if [ "x$2" = "x" ]; then + ocf_log error "Verifying Configuration Of $OCF_RESOURCE_INSTANCE > Failed" + else + ocf_log error "Verifying Configuration Of $OCF_RESOURCE_INSTANCE > Failed - $2" + fi + ;; + esac + return 0 +} + + +## +## Usage: +## clog_check_sha1 %operation% %filename% +## +clog_check_sha1() +{ + case $1 in + $CLOG_INIT) + ocf_log debug "Checking SHA1 Checksum Of File $1" + ;; + $CLOG_SUCCEED) + ocf_log debug "Checking SHA1 Checksum Of File > Succeed" + ;; + $CLOG_FAILED) + ocf_log debug "Checking SHA1 Checksum Of File > Failed - File Changed" + ;; + esac + return 0; +} + +## +## Usage: +## clog_check_file_exist %operation% %filename% +## +clog_check_file_exist() +{ + case $1 in + $CLOG_INIT) + ocf_log debug "Checking Existence Of File $2" + ;; + $CLOG_SUCCEED) + ocf_log debug "Checking Existence Of File $2 > Succeed" + ;; + $CLOG_FAILED) + ocf_log error "Checking Existence Of File $2 [$OCF_RESOURCE_INSTANCE] > Failed" + ;; + $CLOG_FAILED_INVALID) + ocf_log error "Checking Existence Of File $2 [$OCF_RESOURCE_INSTANCE] > Failed - Invalid Argument" + ;; + $CLOG_FAILED_NOT_FOUND) + ocf_log error "Checking Existence Of File $2 [$OCF_RESOURCE_INSTANCE] > Failed - File Doesn't Exist" + ;; + $CLOG_FAILED_NOT_READABLE) + ocf_log error "Checking Existence Of File $2 [$OCF_RESOURCE_INSTANCE] > Failed - File Is Not Readable" + ;; + esac + return 0; +} + +## +## Usage: +## clog_check_pid %operation% %filename% +## +clog_check_pid() +{ + case $1 in + $CLOG_INIT) + ocf_log debug "Checking Non-Existence Of PID File $2" + return 0 + ;; + $CLOG_SUCCEED) + ocf_log debug "Checking Non-Existence of PID File $2 > Succeed" + ;; + $CLOG_FAILED) + ocf_log error "Checking Non-Existence of PID File $2 [$OCF_RESOURCE_INSTANCE] > Failed - PID File Exists For $OCF_RESOURCE_INSTANCE" + ;; + esac + return 0; +} + +## +## Usage: +## clog_check_syntax %operation% %filename% +## +clog_check_syntax() +{ + case $1 in + $CLOG_INIT) + ocf_log debug "Checking Syntax Of The File $2" + ;; + $CLOG_SUCCEED) + ocf_log debug "Checking Syntax Of The File $2 > Succeed" + ;; + $CLOG_FAILED) + ocf_log error "Checking Syntax Of The File $2 [$OCF_RESOURCE_INSTANCE] > Failed" + ;; + esac + return 0; +} + +## +## Usage: +## clog_generate_config %operation% %old filename% %new filename% +## +clog_generate_config() +{ + case $1 in + $CLOG_INIT) + ocf_log debug "Generating New Config File $3 From $2" + ;; + $CLOG_SUCCEED) + ocf_log debug "Generating New Config File $3 From $2 > Succeed" + ;; + $CLOG_FAILED) + ocf_log error "Generating New Config File $3 From $2 [$OCF_RESOURCE_INSTANCE] > Failed" + ;; + esac + return 0; +} + +## +## Usage: +## clog_looking_for %operation% %resource% +## clog_looking_for %operation% "IP Addresses" +## clog_looking_for %operation% "Filesystems" +## +clog_looking_for() +{ + case $1 in + $CLOG_INIT) + ocf_log debug "Looking For $2" + ;; + $CLOG_SUCCEED) + ocf_log debug "Looking For $2 > Succeed - $3 $2 Found" + ;; + $CLOG_FAILED) + ocf_log error "Looking For $2 [$OCF_RESOURCE_INSTANCE] > Failed" + ;; + $CLOG_FAILED_CCS) + ocf_log error "Looking For $2 [$OCF_RESOURCE_INSTANCE] > Failed - Unable To Connect To \"ccs\"" + ;; + $CLOG_FAILED_NOT_FOUND) + ocf_log error "Looking For $2 [$OCF_RESOURCE_INSTANCE] > Failed - No $2 Found" + ;; + esac + return 0; +}