4
# Description: Manages a Websphere Application Server as an HA resource
8
# Support: linux-ha@lists.linux-ha.org
9
# License: GNU General Public License (GPL)
10
# Copyright: (C) 2006 International Business Machines China, Ltd., Inc.
13
# An example usage in /etc/ha.d/haresources:
14
# node1 10.0.0.170 WAS::/opt/IBM/WebSphere/AppServer/profiles/default/config/cells/Node01Cell/nodes/Node01/serverindex.xml
16
# See usage() function below for more details...
18
# OCF parameters are as below:
20
# (WAS profile name, used for the single server edition of WAS6)
22
#######################################################################
25
: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/resource.d/heartbeat}
26
. ${OCF_FUNCTIONS_DIR}/.ocf-shellfuncs
28
#######################################################################
30
WAS_DIR=/opt/IBM/WebSphere/AppServer
34
WAS_DIR=/usr/IBM/WebSphere/AppServer
36
STARTTIME=300 # 5 minutes
37
DEFAULT_WASPORTS="9080"
46
methods=`WAS_methods | grep -v methods`
47
methods=`echo $methods | tr ' ' '|'`
51
For the single server edition of WAS6, you have to set the following
57
$0 manages a Websphere Application Server 6(WAS6) as an HA resource
59
The 'start' operation starts WAS6.
60
The 'stop' operation stops WAS6.
61
The 'status' operation reports whether WAS6 is running
62
The 'monitor' operation reports whether the WAS6 seems to be working
63
(httpd also needs to be working for this case)
64
The 'validate-all' operation reports whether the OCF instance parameter (OCF_RESKEY_profileName ) is valid
65
The 'methods' operation reports on the methods $0 supports
67
This is known to work with the Single Server edition of Websphere.
69
The default profile name for the single server edition is:
72
The start and stop operations must be run as root.
74
The status operation will report a pid of "-" for the
75
WAS root process using unless it is run as root.
77
If you don't have xmllint on your system, parsing of WAS
78
configuration files is very primitive.
80
We run servlet/snoop on the seventh transport port listed in
81
the config file for the "monitor" operation.
89
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
90
<resource-agent name="WAS6">
91
<version>1.0</version>
94
Resource script for WAS6. It manages a Websphere Application Server (WAS6) as
97
<shortdesc lang="en">Manages a WebSphere Application Server 6 instance</shortdesc>
100
<parameter name="profile" unique="0" required="0">
102
The WAS profile name.
104
<shortdesc lang="en">profile name</shortdesc>
105
<content type="string" default="$DEFAULT" />
110
<action name="start" timeout="300" />
111
<action name="stop" timeout="300" />
112
<action name="status" depth="0" timeout="30" interval="10" />
113
<action name="monitor" depth="0" timeout="30" interval="10" />
114
<action name="validate-all" timeout="5" />
115
<action name="meta-data" timeout="5" />
116
<action name="methods" timeout="5" />
123
# Reformat the XML document in a sort of canonical form
124
# if we can. If we don't have xmllint, we just cat it out
125
# and hope for the best ;-)
131
XMLcat=`which xmllint 2>/dev/null`
133
[ "X${XMLcat}" = X -o ! -x "${XMLcat}" ]
137
XMLcat="$XMLcat --recover --format"
147
#This is a bit skanky, but it works anyway...
149
# It's not really skanky if we can find xmllint on the system, because it
150
# reformats tags so they are all on one line, which is all we we need...
153
# Get the numbers of the ports WAS should be listening on...
155
# If we don't have xmllint around, then the applicationserver and the
156
# port= specification have to be on the same line in the XML config file.
160
[0-9]*) echo "$1" | tr ',' '\012';;
162
xmlcat ${WAS_DIR}/profiles/${WAS_PROFILE_NAME}/config/cells/${WAS_CELL}/nodes/${WAS_NODE}/serverindex.xml |
164
sed -e 's%.*port= *"* *%%' \
165
-e 's%[^0-9][^0-9]*.*$%%'
166
# Delete up to port=, throw away optional quote and optional
168
# Throw away everything after the first non-digit.
169
# This should leave us the port number all by itself...
174
# We assume that the seventh port listed in the serverindex.xml
175
# is the one we should run servlet/snoop on.
178
GetWASPorts "$@" | sed -n '7p'
182
# Return information on the processname/id for the WAS ports
184
# pid/java is the expected output. Several lines, one per port...
197
PortCount=`expr $PortCount + 1`
199
netstat -ltnp 2>/dev/null| egrep -i "($pat) .*LISTEN" | sed 's%.*LISTEN *%%'
203
# Return the number of WAS ports which are open
205
CheckWASPortsInUse() {
206
count=`WASPortInfo "$@" | wc -l`
211
# Return the pid(s) of the processes that have WAS ports open
214
WASPortInfo "$@" | sort -u | cut -f1 -d/
218
# The version of ps that returns all processes and their (long) args
219
# It's only used by WAS_procs, which isn't used for anything ;-)
227
# The total set of WAS processes (single server only)
230
ps_long | grep -i "config=$1" | grep -i java | cut -d' ' -f1
236
# methods: What methods/operations do we support?
256
# Return WAS status (silently)
259
WASPorts=`GetWASPorts $1`
260
PortsInUse=`CheckWASPortsInUse $WASPorts`
268
# Report on WAS status to stdout...
270
WAS_report_status() {
271
WASPorts=`GetWASPorts $1`
272
PortCount=`echo $WASPorts | wc -w`
273
PortCount=`echo $PortCount`
274
PortsInUse=`CheckWASPortsInUse $WASPorts`
276
0) ocf_log debug "WAS: server $1 is stopped."; return $OCF_NOT_RUNNING;;
278
pids=`WASPIDs $WASPorts`
280
[ $PortsInUse -ge $PortCount ]
282
ocf_log debug "WAS: server $1 is running (pid" $pids "et al)."
284
ocf_log debug "WAS: server $1 is running (pid $pids et al) but not listening on all ports."
286
return $OCF_SUCCESS;;
291
# Monitor WAS - does it really seem to be working?
293
# For this we invoke the snoop applet via wget.
295
# This is actually faster than WAS_status above...
298
trap '[ -z "$tmpfile" || rmtempfile "$tmpfile"' 0
299
tmpfile=`maketempfile` || exit 1
300
SnoopPort=`GetWASSnoopPort $1`
301
output=`$WGET -nv -O$tmpfile http://localhost:$SnoopPort/snoop 2>&1`
307
grep -i 'user-agent.*Wget' $tmpfile >/dev/null
311
ocf_log "err" "WAS: $1: no user-agent from snoop application"
315
ocf_log "err" "WAS: $1: wget failure: $output"
328
# -logfile <filename>
331
# -script [<script filename >] [-background]
333
# -statusport <portnumber>
334
# -profileName <profile>
337
[ -x $WAS_BIN/startServer.sh ]
339
cmd="$WAS_BIN/startServer.sh server1 -profileName $1"
346
WAS_wait_4_start $STARTTIME "$@"
351
ocf_log "err" "WAS server $1 did not start correctly"
352
return $OCF_ERR_GENERIC
357
WAS_wait_4_start $STARTTIME "$@"
362
ocf_log "err" "WAS server $1 did not start correctly"
363
return $OCF_ERR_GENERIC
369
# Wait for WAS to actually start up.
371
# It seems to take between 30 and 60 seconds for it to
372
# start up on a trivial WAS instance.
379
[ $retries -lt $max ]
388
retries=`expr $retries + 1`
398
# They don't return good return codes...
399
# And, they seem to allow anyone to stop WAS (!)
401
[ -x $WAS_BIN/stopServer.sh ]
403
ocf_run $WAS_BIN/stopServer.sh server1 -profileName $1
405
WASPorts=`GetWASPorts $1`
406
kill `WASPIDs $WASPorts`
411
ocf_log "err" "WAS: $1 did not stop correctly"
413
return $OCF_ERR_GENERIC
421
# Check if the port is valid
424
ocf_is_decimal "$1" && [ $1 -gt 0 ]
428
if [ -x $WAS_BIN/startServer.sh ]; then
429
# $arg should be profile name
430
if [ ! -f ${WAS_DIR}/profiles/${arg}/config/cells/${WAS_CELL}/nodes/${WAS_NODE}/serverindex.xml ]; then
431
ocf_log err "profile [$arg] does not exist"
435
# $arg should specify a valid port number at the very least
436
local WASPorts=`GetWASPorts $arg`
437
if [ -z "$WASPorts" ]; then
438
ocf_log err "No port number specified in configuration file of profile [$arg]"
439
exit $OCF_ERR_CONFIGURED
443
local have_valid_port=false
444
for port in $WASPorts; do
445
if CheckPort $port; then
450
if [ "false" = "$have_valid_port" ]; then
451
ocf_log err "No valid port number specified in configuration file of profile [$arg]"
452
exit $OCF_ERR_CONFIGURED
455
elif [ -x $WAS_BIN/startupServer.sh ]; then
456
# $arg should be port number
457
if CheckPort "$arg"; then
458
ocf_log err "Port number is required but [$arg] is not valid port number"
462
# Do not know hot to validate_all
463
ocf_log warn "Do not know how to validate-all, assuming validation OK"
468
# 'main' starts here...
478
# These operations don't require OCF instance parameters to be set
494
# Supply default configuration parameter(s)
498
[ -z $OCF_RESKEY_profile ]
502
arg=$OCF_RESKEY_profile
506
[ ! -d ${WAS_DIR}/profiles/$arg ]
508
ocf_log "err" "WAS profile $arg does not exist!"
513
WAS_PROFILE_NAME=$arg
514
if [ "${WAS_PROFILE_NAME:=}" != "" ]; then
515
WAS_PROFILE_FSDB_SCRIPT=${WAS_DIR}/properties/fsdb/${WAS_PROFILE_NAME}.sh
518
if [ "${WAS_PROFILE_FSDB_SCRIPT:=}" != "" ] && [ -f ${WAS_PROFILE_FSDB_SCRIPT} ]; then
519
. ${WAS_PROFILE_FSDB_SCRIPT}
522
if [ "${WAS_USER_SCRIPT:=}" != "" ]; then
526
# What kind of method was invoked?
529
start) WAS_start $arg
535
status) WAS_report_status $arg
538
monitor) WAS_monitor $arg
541
validate-all) WAS_validate_all $arg
545
exit $OCF_ERR_UNIMPLEMENTED;;