From 6c74fdab276cecf3d3113288167b00ececd90cc1 Mon Sep 17 00:00:00 2001 From: bizhiyuan Date: Wed, 28 Feb 2024 16:49:16 +0800 Subject: [PATCH] Add WAS8 ocf script to support WAS8 server --- heartbeat/Makefile.am | 1 + heartbeat/WAS8 | 615 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 616 insertions(+) create mode 100644 heartbeat/WAS8 diff --git a/heartbeat/Makefile.am b/heartbeat/Makefile.am index 6bd18f2480..b9c7ce8a77 100644 --- a/heartbeat/Makefile.am +++ b/heartbeat/Makefile.am @@ -86,6 +86,7 @@ ocf_SCRIPTS = AoEtarget \ VirtualDomain \ WAS \ WAS6 \ + WAS8 \ WinPopup \ Xen \ Xinetd \ diff --git a/heartbeat/WAS8 b/heartbeat/WAS8 new file mode 100644 index 0000000000..67804f7416 --- /dev/null +++ b/heartbeat/WAS8 @@ -0,0 +1,615 @@ +#!/bin/sh +# +# +# WAS +# +# Description: Manages a Websphere Application Server as an HA resource +# +# +# Author: Bi Zhi Yuan +# Support: users@clusterlabs.org +# License: GNU General Public License (GPL) +# Copyright: (C) 2006 International Business Machines China, Ltd., Inc. +# +# +# An example usage in /etc/ha.d/haresources: +# node1 10.0.0.170 WAS::/opt/WebSphere/ApplicationServer/config/server-cfg.xml +# +# See usage() function below for more details... +# +# OCF parameters are as below: +# OCF_RESKEY_config +# (WAS-configuration file, used for the single server edition of WAS8) +# OCF_RESKEY_port +# (WAS--port-number, used for the advanced edition of WAS8) +# OCF_RESKEY_server_name +# (WAS server name, used for the advanced edition of WAS8) +# OCF_RESKEY_profile_name +# (WAS profile name, used for the single server edition of WAS8) + +####################################################################### +# Initialization: + +: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat} +. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs + +####################################################################### + +WASDIR=/opt/IBM/WebSphere/AppServer +if + [ ! -d $WASDIR ] +then + WASDIR=/usr/WebSphere/AppServer +fi +STARTTIME=300 # 5 minutes +DEFAULT_WASPORTS="9080" +DEFAULT_WAS_SERVER_NAME="server1" +DEFAULT_WAS_PROFILE_NAME="AppSrv01" +WASBIN=$WASDIR/bin +DEFAULT=$WASDIR/config/server-cfg.xml + +# Print usage message +# +usage() { + methods=`WAS_methods | grep -v methods` + methods=`echo $methods | tr ' ' '|'` + cat <<-END + usage: $0 ($methods) + + For the single server edition of WAS, you have to set the following + enviroment virable: + OCF_RESKEY_config + (WAS-configuration file) + + For the advanced edition of WAS, you have to set the following + enviroment virable: + OCF_RESKEY_port + (WAS--port-number) + + $0 manages a Websphere Application Server (WAS) as an HA resource + + The 'start' operation starts WAS. + The 'stop' operation stops WAS. + The 'status' operation reports whether WAS is running + The 'monitor' operation reports whether the WAS seems to be working + (httpd also needs to be working for this case) + The 'validate-all' operation reports whether the OCF instance parameter (OCF_RESKEY_config or OCF_RESKEY_port) is valid + The 'methods' operation reports on the methods $0 supports + + This is known to work with the Single Server edition of Websphere, + and is believed to work with the Advanced edition too. + Since the Advanced Edition has no configuration file (it's in a the + database) you need to give a port number instead of a + configuration file for this config parameter. + + The default configuration file for the single server edition is: + $DEFAULT + + The default snoop-port for the advanced edition is: $DEFAULT_WASPORTS + + The start and stop operations must be run as root. + + The status operation will report a pid of "-" for the + WAS root process using unless it is run as root. + + If you don't have xmllint on your system, parsing of WAS + configuration files is very primitive. + In this case, the port specification we need from the XML + config file has to be on the same line as the + first part of the tag. + + We run servlet/snoop on the first transport port listed in + the config file for the "monitor" operation. + + END +} + +meta_data() { + cat < + + +1.0 + + +Resource script for WAS. It manages a Websphere Application Server (WAS) as +an HA resource. + +Manages a WebSphere Application Server instance + + + + +The WAS-configuration file. + +configration file + + + + + +The WAS-(snoop)-port-number. + +port + + + + + +The WAS server-name. + +serverName + + + + + +The WAS profile-name. + +profileName + + + + + + + + + + + + + + + +END +} + +# +# Reformat the XML document in a sort of canonical form +# if we can. If we don't have xmllint, we just cat it out +# and hope for the best ;-) +# +xmlcat() { + if + [ "X$XMLcat" = X ] + then + XMLcat=`which xmllint 2>/dev/null` + if + [ "X${XMLcat}" = X -o ! -x "${XMLcat}" ] + then + XMLcat=cat + else + XMLcat="$XMLcat --recover --format" + fi + fi + for j in "$@" + do + ${XMLcat} "$j" + done +} + +# +# This is a bit skanky, but it works anyway... +# +# It's not really skanky if we can find xmllint on the system, because it +# reformats tags so they are all on one line, which is all we we need... +# + +# +# Get the numbers of the ports WAS should be listening on... +# +# If we don't have xmllint around, then the applicationserver and the +# port= specification have to be on the same line in the XML config file. +# +GetWASPorts() { + case $1 in + [0-9]*) echo "$1" | tr ',' '\012';; + *) + xmlcat ${WASDIR}/profiles/${WAS_PROFILE_NAME}/config/cells/${WAS_CELL}/nodes/${WAS_NODE}/serverindex.xml | + grep port= | + sed -e 's%.*port= *"* *%%' \ + -e 's%[^0-9][^0-9]*.*$%%' + # Delete up to port=, throw away optional quote and optional + # white space. + # Throw away everything after the first non-digit. + # This should leave us the port number all by itself... + esac +} + +# +# We assume that the first port listed in the +# is the one we should run servlet/snoop on. +# +GetWASSnoopPort() { + GetWASPorts "$@" | sed -n '8p' +} + +# +# Return information on the processname/id for the WAS ports +# +# pid/java is the expected output. Several lines, one per port... +# +# +WASPortInfo() { + pat="" + once=yes + PortCount=0 + for j in $* + do + case $pat in + "") pat="$j";; + *) pat="$pat|$j";; + esac + PortCount=`expr $PortCount + 1` + done + netstat -ltnp 2>/dev/null| egrep -i "($pat) .*LISTEN" | sed 's%.*LISTEN *%%' +} + +# +# Return the number of WAS ports which are open +# +CheckWASPortsInUse() { + count=`WASPortInfo "$@" | wc -l` + echo $count +} + +# +# Return the pid(s) of the processes that have WAS ports open +# +WASPIDs() { + WASPortInfo "$@" | sort -u | cut -f1 -d/ +} + +# +# The version of ps that returns all processes and their (long) args +# It's only used by WAS_procs, which isn't used for anything ;-) +# +ps_long() { + ps axww +} + + +# +# The total set of WAS processes (single server only) +# +WAS_procs() { + ps_long | grep -i "config=$1" | grep -i java | cut -d' ' -f1 +} + + + +# +# methods: What methods/operations do we support? +# +WAS_methods() { + cat <<-! + start + stop + status + methods + validate-all + meta-data + usage + ! + if + have_binary $WGET + then + echo monitor + fi +} + +# +# Return WAS status (silently) +# +WAS_status() { + WASPorts=`GetWASPorts $1` + PortsInUse=`CheckWASPortsInUse $WASPorts` + case $PortsInUse in + 0) false;; + *) true;; + esac +} + +# +# Report on WAS status to stdout... +# +WAS_report_status() { + WASPorts=`GetWASPorts $1` + PortCount=`echo $WASPorts | wc -w` + PortCount=`echo $PortCount` + PortsInUse=`CheckWASPortsInUse $WASPorts` + case $PortsInUse in + 0) ocf_log debug "WAS: server $1 is stopped."; return $OCF_NOT_RUNNING;; + *) + pids=`WASPIDs $WASPorts` + if + [ $PortsInUse -ge $PortCount ] + then + ocf_log debug "WAS: server $1 is running (pid" $pids "et al)." + else + ocf_log debug "WAS: server $1 is running (pid $pids et al) but not listening on all ports." + fi + return $OCF_SUCCESS;; + esac +} + +# +# Monitor WAS - does it really seem to be working? +# +# For this we invoke the snoop applet via wget. +# +# This is actually faster than WAS_status above... +# +WAS_monitor() { + trap '[ -z "$tmpfile" ] || rmtempfile "$tmpfile"' 0 + tmpfile=`maketempfile` || return 1 + + SnoopPort=`GetWASSnoopPort $1` + output=`$WGET -nv -O$tmpfile http://localhost:9080/snoop 2>&1` + rc=$? + if + [ $rc -eq 0 ] + then + ocf_log "info" "WAS monitor succeeded" + return $OCF_SUCCESS + else + ocf_log "err" "WAS: $1: wget failure: $output" + rc=$OCF_NOT_RUNNING + fi + + return $rc +} + +# +# Start WAS instance +# +WAS_start() { +# Launch Arguments: +# +# -nowait +# -quiet +# -logfile +# -replacelog +# -trace +# -script [