This file is indexed.

/usr/lib/ocf/resource.d/heartbeat/WAS is in resource-agents 1:3.9.2-5ubuntu4.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
#!/bin/sh
#
# 
# WAS
#
# Description:	Manages a Websphere Application Server as an HA resource
#
#
# Author:	Alan Robertson
# 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 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 WAS)
#		OCF_RESKEY_port
#		  (WAS-<snoop>-port-number, used for the advanced edition of WAS)

#######################################################################
# Initialization:

: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs

#######################################################################

WASDIR=/opt/WebSphere/AppServer
if
  [ ! -d $WASDIR ]
then
  WASDIR=/usr/WebSphere/AppServer
fi
STARTTIME=300	#	5 minutes
DEFAULT_WASPORTS="9080"
#
#
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-<snoop>-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 <transports/> tag.

	We run servlet/snoop on the first transport port listed in
	the config file for the "monitor" operation.

	END
}

meta_data() {
	cat <<END
<?xml version="1.0"?>
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
<resource-agent name="WAS">
<version>1.0</version>

<longdesc lang="en">
Resource script for WAS. It manages a Websphere Application Server (WAS) as 
an HA resource.
</longdesc>
<shortdesc lang="en">Manages a WebSphere Application Server instance</shortdesc>

<parameters>
<parameter name="config" unique="0" required="0">
<longdesc lang="en">
The WAS-configuration file.
</longdesc>
<shortdesc lang="en">configration file</shortdesc>
<content type="string" default="$DEFAULT" />
</parameter>

<parameter name="port" unique="0">
<longdesc lang="en">
The WAS-(snoop)-port-number.
</longdesc>
<shortdesc lang="en">port</shortdesc>
<content type="integer" default="$DEFAULT_WASPORTS" />
</parameter>
</parameters>

<actions>
<action name="start" timeout="300" />
<action name="stop" timeout="300" />
<action name="status" depth="0" timeout="30" interval="10" />
<action name="monitor" depth="0" timeout="30" interval="10" />
<action name="validate-all" timeout="5" />
<action name="meta-data" timeout="5" />
<action name="methods" timeout="5" />
</actions>
</resource-agent>
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...
#
#<transports xmi:type="applicationserver:HTTPTransport" xmi:id="HttpTransport_1" hostname="*" port="9080"/>
#<transports xmi:type="applicationserver:HTTPTransport" xmi:id="HttpTransport_2" hostname="*" port="9443" sslEnabled="true"/>
#<transports xmi:type="applicationserver:HTTPTransport" xmi:id="HttpTransport_3" hostname="*" port="9090" external="false"/>
#
# 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 $1 | grep -i 'transports.*applicationserver:HTTPTransport' |
	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 <transports/>
#	is the one we should run servlet/snoop on.
#
GetWASSnoopPort() {
	GetWASPorts "$@" | head -n1
}

#
#	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:$SnoopPort/servlet/snoop 2>&1`
  rc=$?
  if
    [ $rc -eq 0 ]
  then
    if
      grep -i 'user-agent.*Wget' $tmpfile >/dev/null
    then
      : OK
    else
      ocf_log "err" "WAS: $1: no user-agent from snoop application"
      rc=$OCF_ERR_GENERIC
    fi
  else
    ocf_log "err" "WAS: $1: wget failure: $output"
    rc=$OCF_ERR_GENERIC
  fi
  return $rc
}

#
#	Start WAS instance
#
WAS_start() {
# Launch Arguments:
#
#      -configFile      <configFile>
#      -nodeName        <nodeName>
#      -serverName      <serverName>
#      -oltEnabled
#      -oltHost         <hostname>
#      -oltPort         <port>
#      -debugEnabled
#      -jdwpPort        <port>
#      -debugSource     <sourcePath>
#      -serverTrace     <traceString>
#      -serverTraceFile <traceFile>
#      -script          [<scriptFile>]
#      -platform        <platformName>
#      -noExecute
#      -help
  if
    [ -x $WASBIN/startServer.sh ]
  then
    cmd="$WASBIN/startServer.sh -configFile $1"
  else
    cmd="$WASBIN/startupServer.sh"
  fi
    
  if
    ocf_run $cmd
  then
    if
      WAS_wait_4_start $STARTTIME "$@"
    then
      #true
      return $OCF_SUCCESS
    else
      ocf_log "err" "WAS server $1 did not start correctly"
      return $OCF_ERR_GENERIC
    fi
  else
    #false
    return $OCF_ERR_GENERIC
  fi
}

#
#	Wait for WAS to actually start up.
#
#	It seems to take between 30 and 60 seconds for it to
#	start up on a trivial WAS instance.
#
WAS_wait_4_start() {
  max=$1
  retries=0
  shift
  while
    [ $retries -lt $max ]
  do
    if
      WAS_status "$@"
    then
      return $OCF_SUCCESS
    else
      sleep 1
    fi
    retries=`expr $retries + 1`
  done
  WAS_status "$@"
}
  

#
#	Shut down WAS
#
WAS_stop() {
  # They don't return good return codes...
  # And, they seem to allow anyone to stop WAS (!)
  if
    [ -x $WASBIN/stopServer.sh ]
  then
    ocf_run $WASBIN/stopServer.sh -configFile $1
  else
    WASPorts=`GetWASPorts $1`
    kill `WASPIDs $WASPorts`
  fi
  if
    WAS_status $1
  then
    ocf_log "err" "WAS: $1 did not stop correctly"
    #false
    return $OCF_ERR_GENERIC
  else
    #true
    return $OCF_SUCCESS
  fi
}

#
#	Check if the port is valid
#
CheckPort() {
  ocf_is_decimal "$1" && [ $1 -gt 0 ]
}

WAS_validate_all() {
  if [ -x $WASBIN/startServer.sh ]; then
  # $arg should be config file
	if [ ! -f "$arg" ]; then
	    ocf_log err "Configuration file [$arg] does not exist"
	    exit $OCF_ERR_ARGS
	fi

  # $arg should specify a valid port number at the very least
	local WASPorts=`GetWASPorts $arg`
	if [ -z "$WASPorts" ]; then
	    ocf_log err "No port number specified in configuration file [$arg]"
	    exit $OCF_ERR_CONFIGURED
	fi

	local port
	local have_valid_port=false
	for port in $WASPorts; do
	    if CheckPort $port; then
		have_valid_port=true
		break
	    fi
	done
	if [ "false" = "$have_valid_port" ]; then
	    ocf_log err "No valid port number specified in configuration file [$arg]"
	    exit $OCF_ERR_CONFIGURED
	fi
	   
  elif [ -x $WASBIN/startupServer.sh ]; then
  # $arg should be port number
	if CheckPort "$arg"; then 
	    ocf_log err "Port number is required but [$arg] is not valid port number"
	    exit $OCF_ERR_ARGS
	fi
  else
  # Do not know hot to validate_all
	ocf_log warn "Do not know how to validate-all, assuming validation OK"
	return $OCF_SUCCESS
  fi
}
#
#	'main' starts here...
#

if
  ( [ $# -ne 1 ] )
then
  usage
  exit $OCF_ERR_ARGS
fi

#
#	Supply default configuration parameter(s)
#

if
  ( [ -z $OCF_RESKEY_config ] && [ -z $OCF_RESKEY_port ] )
then
  if
    [ -f $DEFAULT ]
  then
    arg=$DEFAULT
  else
    arg=$DEFAULT_WASPORTS
  fi
elif
  [ ! -z $OCF_RESKEY_config ]  
then
  arg=$OCF_RESKEY_config
else
  arg=$OCF_RESKEY_port
fi

if
  [ ! -f $arg ]
then
  case $arg in
    [0-9]*)	;;	# ignore port numbers...
    *)		ocf_log "err" "WAS configuration file $arg does not exist!"
  		usage
  		exit $OCF_ERR_ARGS;;
  esac
fi
  

# What kind of method was invoked?
case "$1" in

  meta-data)	meta_data
		exit $OCF_SUCCESS;;

  start)	WAS_start $arg
		exit $?;;

  stop)		WAS_stop $arg
		exit $?;;

  status)	WAS_report_status $arg
		exit $?;;

  monitor)	WAS_monitor $arg
		exit $?;;

  validate-all)	WAS_validate_all $arg
		exit $?;;

  methods)	WAS_methods
		exit $?;;

  usage)	usage
		exit $OCF_SUCCESS;;

  *)		usage
		exit $OCF_ERR_UNIMPLEMENTED;;
esac