From mboxrd@z Thu Jan 1 00:00:00 1970 From: mgrac@sourceware.org Date: 10 Oct 2006 14:10:39 -0000 Subject: [Cluster-devel] cluster/rgmanager/src/resources/utils config-u ... Message-ID: <20061010141039.17618.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 Branch: RHEL4 Changes by: mgrac at sourceware.org 2006-10-10 14:10:38 Added files: rgmanager/src/resources/utils: config-utils.sh httpd-parse-config.pl messages.sh ra-skelet.sh tomcat-parse-config.pl Log message: Utilities for Resource Agents Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/rgmanager/src/resources/utils/config-utils.sh.diff?cvsroot=cluster&only_with_tag=RHEL4&r1=NONE&r2=1.6.2.1 http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/rgmanager/src/resources/utils/httpd-parse-config.pl.diff?cvsroot=cluster&only_with_tag=RHEL4&r1=NONE&r2=1.1.2.1 http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/rgmanager/src/resources/utils/messages.sh.diff?cvsroot=cluster&only_with_tag=RHEL4&r1=NONE&r2=1.3.2.1 http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/rgmanager/src/resources/utils/ra-skelet.sh.diff?cvsroot=cluster&only_with_tag=RHEL4&r1=NONE&r2=1.5.2.1 http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/rgmanager/src/resources/utils/tomcat-parse-config.pl.diff?cvsroot=cluster&only_with_tag=RHEL4&r1=NONE&r2=1.1.2.1 /cvs/cluster/cluster/rgmanager/src/resources/utils/config-utils.sh,v --> standard output revision 1.6.2.1 --- cluster/rgmanager/src/resources/utils/config-utils.sh +++ - 2006-10-10 14:10:39.045361000 +0000 @@ -0,0 +1,299 @@ +#!/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 RA_COMMON_pid_dir=/var/run/cluster +declare RA_COMMON_conf_dir=/etc/cluster + +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. 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 +} + +generate_name_for_pid_file() +{ + declare filename=$(basename $0) + + echo "$RA_COMMON_pid_dir/$(basename $0 | sed 's/^\(.*\)\..*/\1/')/$OCF_RESOURCE_INSTANCE.pid" + + return 0; +} + +generate_name_for_pid_dir() +{ + declare filename=$(basename $0) + + echo "$RA_COMMON_pid_dir/$(basename $0 | sed 's/^\(.*\)\..*/\1/')/$OCF_RESOURCE_INSTANCE" + + return 0; +} + +generate_name_for_conf_dir() +{ + declare filename=$(basename $0) + + echo "$RA_COMMON_conf_dir/$(basename $0 | sed 's/^\(.*\)\..*/\1/')/$OCF_RESOURCE_INSTANCE" + + return 0; +} + +create_pid_directory() +{ + declare program_name="$(basename $0 | sed 's/^\(.*\)\..*/\1/')" + declare dirname="$RA_COMMON_pid_dir/$program_name" + + if [ -d "$dirname" ]; then + return 0; + fi + + chmod 711 "$RA_COMMON_pid_dir" + mkdir -p "$dirname" + + if [ "$program_name" = "mysql" ]; then + chown mysql.root "$dirname" + elif [ "$program_name" = "tomcat-5" ]; then + chown tomcat.root "$dirname" + fi + + return 0; +} + +create_conf_directory() +{ + declare dirname="$1" + + if [ -d "$dirname" ]; then + return 0; + fi + + mkdir -p "$dirname" + + return 0; +} + +check_pid_file() { + declare pid_file="$1" + + if [ -z "$pid_file" ]; then + return 1; + fi + + if [ ! -e "$pid_file" ]; then + return 0; + fi + + if [ ! -d /proc/`cat "$pid_file"` ]; then + rm "$pid_file" + ocf_log debug "PID File \"$pid_file\" Was Removed - PID Does Not Exist"; + return 0; + fi + + return 1; +} \ No newline at end of file /cvs/cluster/cluster/rgmanager/src/resources/utils/httpd-parse-config.pl,v --> standard output revision 1.1.2.1 --- cluster/rgmanager/src/resources/utils/httpd-parse-config.pl +++ - 2006-10-10 14:10:39.135159000 +0000 @@ -0,0 +1,65 @@ +#!/usr/bin/perl -w + +## +## This script removes sections from the +## Apache httpd.conf file. This is quite useful because we +## don't have any direct access to the parsed configuration +## file of the httpd server. +## +## Usage: ./httpd-parse-config.pl -Dfoo1 -Dfoo2 < httpd.conf +## where fooX are defines as passed to the httpd server +## +## Note: All whitespace characters@the beginning and end +## of lines are removed. +## +use strict; + +my @defines = (); +## Default behaviour is to show all lines when we are not +## in the sections. +my @show = (1); + +sub testIfDefine($) { + my $param = $1; + my $positiveTest = 1; + if ($param =~ /^!(.*)$/) { + $param = $1; + $positiveTest = 0; + } + + foreach my $def (@defines) { + if ($def eq $param) { + return $positiveTest; + } + } + + return (1-$positiveTest); +} + +foreach my $arg (@ARGV) { + if ($arg =~ /^-D(.*)$/) { + push(@defines, $1); + } +} + +## Parse config file and remove IfDefine sections +while (my $line = ) { + chomp($line); + $line =~ s/^\s*(.*?)\s*$/$1/; + if ($line =~ //) { + if (testIfDefine($1) == 1) { + if ($show[$#show] == 1) { + push (@show, 1); + } else { + push (@show, 0); + } + } else { + push (@show, 0); + } + } elsif ($line =~ /<\/IfDefine>/) { + pop(@show); + } elsif ($show[$#show] == 1) { + print $line, "\n"; + } +} + /cvs/cluster/cluster/rgmanager/src/resources/utils/messages.sh,v --> standard output revision 1.3.2.1 --- cluster/rgmanager/src/resources/utils/messages.sh +++ - 2006-10-10 14:10:39.232362000 +0000 @@ -0,0 +1,272 @@ +#!/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" + ;; + $CLOG_FAILED_NOT_STOPPED) + ocf_log error "Stopping Service $OCF_RESOURCE_INSTANCE > Failed - Application Is Still Running" + ;; + 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 debug "Verifying Configuration Of $OCF_RESOURCE_INSTANCE" + ;; + $CLOG_SUCCEED) + ocf_log debug "Verifying Configuration Of $OCF_RESOURCE_INSTANCE > Succeed" + ;; + $CLOG_FAILED_NOT_CHILD) + ocf_log error "Service $OCF_RESOURCE_INSTANCE Is Not A Child Of A Service" + ;; + $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; +} /cvs/cluster/cluster/rgmanager/src/resources/utils/ra-skelet.sh,v --> standard output revision 1.5.2.1 --- cluster/rgmanager/src/resources/utils/ra-skelet.sh +++ - 2006-10-10 14:10:39.313550000 +0000 @@ -0,0 +1,87 @@ +#!/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) +# +status_check_pid() +{ + declare pid_file="$1" + + if [ -z "$pid_file" ]; then + clog_check_file_exist $CLOG_FAILED_INVALID "$pid_file" + return $OCF_ERR_GENERIC + fi + + if [ ! -e "$pid_file" ]; then + clog_check_file_exist $CLOG_FAILED "$pid_file" + return $OCF_ERR_GENERIC + fi + + if [ ! -d /proc/`cat "$pid_file"` ]; then + return $OCF_ERR_GENERIC + fi + + return 0 +} + +stop_generic() +{ + declare pid_file="$1" + declare kill_timeout="$2" + declare pid; + declare count=0; + + if [ ! -e "$pid_file" ]; then + clog_check_file_exist $CLOG_FAILED_NOT_FOUND "$pid_file" + return $OCF_ERR_GENERIC + fi + + if [ -z "$kill_timeout" ]; then + kill_timeout=20 + fi + + read pid < "$pid_file" + + # @todo: PID is not running -> error? + if [ ! -d "/proc/$pid_file" ]; then + return 0; + fi + + kill -TERM "$pid" + + if [ $? -ne 0 ]; then + return $OCF_ERR_GENERIC + fi + + until [ `ps --pid "$pid" &> /dev/null; echo $?` = '1' ] || [ $count -gt $kill_timeout ] + do + sleep 1 + let count=$count+1 + done + + if [ $count -gt $kill_timeout ]; then + clog_service_stop $CLOG_FAILED_NOT_STOPPED + return $OCF_ERR_GENERIC + fi + + return 0; +} /cvs/cluster/cluster/rgmanager/src/resources/utils/tomcat-parse-config.pl,v --> standard output revision 1.1.2.1 --- cluster/rgmanager/src/resources/utils/tomcat-parse-config.pl +++ - 2006-10-10 14:10:39.394782000 +0000 @@ -0,0 +1,45 @@ +#!/usr/bin/perl -w + +## +## This script replace IP addresses on which tomcat server +## should listen. Tomcat can't listen on every IP because that +## way we can run only on instance. +## +## Usage: ./tomcat-parse-config.pl ip1 ip2 < /etc/tomcat/server.xml +## where ipXX defines an IP address [eg. 127.0.0.1 134.45.11.1] +## +## +use strict; + +while (my $line = ) { + chomp ($line); + + if ($line =~ /(.*?)/) == 0) { + $content .= $tmp . "\n"; + $tmp = ; + chomp($tmp); + } + + if ($tmp =~ /(.*?)>(.*)/) { + $content .= $1 . ">\n"; + $rest = $2; + chomp($rest); + } + + print $start; + foreach my $arg (@ARGV) { + $content =~ s/\s+address=".*?"/ /; + $content =~ s/Connector /Connector address="$arg" /; + print $content; + } + print $rest; + } else { + print $line,"\n"; + } +}