This file is indexed.

/usr/lib/ocf/resource.d/heartbeat/oralsnr 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
#!/bin/sh
#
# 
# oralsnr
#
# Description:	Manages an Oracle Listener as a High-Availability
#		resource
#
#
# Author:	Dejan Muhamedagic
# Support:	linux-ha@lists.linux-ha.org
# License:	GNU General Public License (GPL)
# Copyright:	(C) 2006 International Business Machines, Inc.
#
#		This code inspired by the DB2 resource script
#		written by Alan Robertson
#
# An example usage in /etc/ha.d/haresources: 
#       node1  10.0.0.170 oralsnr::sid::home::user::listener
#
# See usage() function below for more details...
#
# OCF instance parameters:
#	OCF_RESKEY_sid (mandatory; for the monitor op)
#	OCF_RESKEY_home (optional; else read it from /etc/oratab)
#	OCF_RESKEY_user (optional; user to run the listener)
#	OCF_RESKEY_listener (optional; defaults to LISTENER)
#
# Initialization:

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

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

SH=/bin/sh

usage() {
  methods=`oralsnr_methods`
  methods=`echo $methods | tr ' ' '|'`
  cat <<-!
	usage: $0 ($methods)

	$0 manages an Oracle Database instance as an HA resource.

	The 'start' operation starts the database.
	The 'stop' operation stops the database.
	The 'status' operation reports whether the database is running
	The 'monitor' operation reports whether the database seems to be working
	The 'validate-all' operation reports whether the parameters are valid
	The 'methods' operation reports on the methods $0 supports

	!
}

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

<longdesc lang="en">
Resource script for Oracle Listener. It manages an
Oracle Listener instance as an HA resource.
</longdesc>
<shortdesc lang="en">Manages an Oracle TNS listener</shortdesc>

<parameters>

<parameter name="sid" unique="1" required="1">
<longdesc lang="en">
The Oracle SID (aka ORACLE_SID). Necessary for the monitor op,
i.e. to do tnsping SID.
</longdesc>
<shortdesc lang="en">sid</shortdesc>
<content type="string" default="" />
</parameter>

<parameter name="home" unique="0">
<longdesc lang="en">
The Oracle home directory (aka ORACLE_HOME).
If not specified, then the SID should be listed in /etc/oratab.
</longdesc>
<shortdesc lang="en">home</shortdesc>
<content type="string" default="" />
</parameter>

<parameter name="user" unique="0">
<longdesc lang="en">
Run the listener as this user.
</longdesc>
<shortdesc lang="en">user</shortdesc>
<content type="string" default="" />
</parameter>

<parameter name="listener" unique="1">
<longdesc lang="en">
Listener instance to be started (as defined in listener.ora).
Defaults to LISTENER.
</longdesc>
<shortdesc lang="en">listener</shortdesc>
<content type="string" default="" />
</parameter>

</parameters>

<actions>
<action name="start" timeout="120" />
<action name="stop" timeout="120" />
<action name="status" timeout="60" />
<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
}


#
# methods: What methods/operations do we support?
#
oralsnr_methods() {
  cat <<-!
	start
	stop
	status
	monitor
	validate-all
	methods
	meta-data
	usage
	!
}


#	Gather up information about our oralsnr instance

ora_info() {
	ORACLE_SID=$1
	ORACLE_HOME=$2
	ORACLE_OWNER=$3

	# get ORACLE_HOME from /etc/oratab if not set
	[ x = "x$ORACLE_HOME" ] &&
		ORACLE_HOME=`awk -F: "/^$ORACLE_SID:/"'{print $2}' /etc/oratab`

	# there a better way to find out ORACLE_OWNER?
	[ x = "x$ORACLE_OWNER" ] &&
		ORACLE_OWNER=`ls -ld $ORACLE_HOME/. 2>/dev/null | awk 'NR==1{print $3}'`

	sqlplus=$ORACLE_HOME/bin/sqlplus
	lsnrctl=$ORACLE_HOME/bin/lsnrctl
	tnsping=$ORACLE_HOME/bin/tnsping
}

testoraenv() {
	#	Let's make sure a few important things are set...
	if [ x = "x$ORACLE_HOME" ]; then
		ocf_log info "ORACLE_HOME not set"
		return $OCF_ERR_CONFIGURED
	fi
	if [ x = "x$ORACLE_OWNER" ]; then
		ocf_log info "ORACLE_OWNER not set"
		return $OCF_ERR_CONFIGURED
	fi
	#	and some important things are there
	if [ ! -x "$sqlplus" ]; then
		ocf_log info "$sqlplus does not exist"
		return $OCF_ERR_INSTALLED
	fi
	if [ ! -x "$lsnrctl" ]; then
		ocf_log err "$lsnrctl does not exist"
		return $OCF_ERR_INSTALLED
	fi
	if [ ! -x "$tnsping" ]; then
		ocf_log err "$tnsping does not exist"
		return $OCF_ERR_INSTALLED
	fi
	return 0
}

setoraenv() {
	LD_LIBRARY_PATH=$ORACLE_HOME/lib
	LIBPATH=$ORACLE_HOME/lib
	TNS_ADMIN=$ORACLE_HOME/network/admin
	PATH=$ORACLE_HOME/bin:$ORACLE_HOME/dbs:$PATH
	export ORACLE_SID ORACLE_HOME ORACLE_OWNER TNS_ADMIN
	export LD_LIBRARY_PATH LIBPATH
}
dumporaenv() {
cat<<EOF
PATH=$ORACLE_HOME/bin:$ORACLE_HOME/dbs:$PATH
ORACLE_SID=$ORACLE_SID
ORACLE_HOME=$ORACLE_HOME
ORACLE_OWNER=$ORACLE_OWNER
LD_LIBRARY_PATH=$ORACLE_HOME/lib
LIBPATH=$ORACLE_HOME/lib
TNS_ADMIN=$ORACLE_HOME/network/admin
export ORACLE_SID ORACLE_HOME ORACLE_OWNER TNS_ADMIN
export LD_LIBRARY_PATH LIBPATH
EOF
}

#
#	Run commands as the Oracle owner...
#
runasdba() {
	if [ "$US" = "$ORACLE_OWNER" ]; then
		$SH
	else
		(
		echo ". $envtmpf"
		cat
		) | su - $ORACLE_OWNER
	fi
}

#
# oralsnr_start: Start the Oracle listener instance
#

oralsnr_start() {
	if tnsping; then
		: nothing to be done, we can leave right now
		ocf_log info "Listener $listener already running"
		return $OCF_SUCCESS
	fi
	output=`echo $lsnrctl start $listener | runasdba`
	if tnsping; then
		: cool, we are up and running
		ocf_log info "Listener $listener running: $output"
		return $OCF_SUCCESS
	else
		ocf_log err "Listener $listener appears to have started, but is not running properly: $output"
		ocf_log err "Probable Oracle configuration error"
		ocf_log err "Oracle $tnsping output: `$tnsping $ORACLE_SID`"
		return $OCF_ERR_GENERIC
	fi
}

#
# oralsnr_stop: Stop the Oracle instance
#
oralsnr_stop() {
	if is_oralsnr_up; then
		output=`echo $lsnrctl stop $listener | runasdba`
	else
		ocf_log info "Listener $listener already stopped"
		return $OCF_SUCCESS
	fi
	oralsnr_kill  # kill the procs if they hanged
	if is_oralsnr_up; then
		ocf_log err "Listener $listener not stopped: $output"
		return $OCF_ERR_GENERIC
	else
		ocf_log info "Listener $listener stopped: $output"
		return $OCF_SUCCESS
	fi
}
# kill the listener procs
# give them 10 secs to exit cleanly (5 times 2)
oralsnr_kill() {
	oraprocs=`eval $procs | awk '{print $1}'`
	if [ -z "$oraprocs" ]; then
		ocf_log debug "All oralsnr processes are already stopped."
		return
	fi
	killprocs TERM $oraprocs
	for i in 1 2 3 4 5; do
		if [ -z "`eval $procs | awk '{print $1}'`" ]; then
			ocf_log debug "All oralsnr processes are killed."
			return
		fi
		sleep 2
	done
	killprocs KILL `eval $procs | awk '{print $1}'`
}
killprocs() {
	sig=$1
	shift 1
	# Record stderr
	kill -s $sig $* >/dev/null
}

#
# is_oralsnr_up: is listener process running?
# oralsnr_status: is the listener running?
#
is_oralsnr_up() {
	[ x != "x`eval $procs`" ]
}
oralsnr_status() {
	output=`$lsnrctl status $listener`
	echo "$output" | tail -1 | grep -qs 'completed successfully'
	RET=$?
	if [ $RET -ne 0 ]; then
		ocf_log info "$listener status failed: $output"
	fi
	return $RET
}
# and does it work?
tnsping() {
	output=`$tnsping $ORACLE_SID`
	echo "$output" | tail -1 | grep -qs '^OK'
	RET=$?
	if [ $RET -ne 0 ]; then
		ocf_log info "$tnsping $ORACLE_SID failed: $output"
	fi
	return $RET
}

#
# oralsnr_monitor: Can we connect to the listener?
#
oralsnr_monitor() {
	if oralsnr_status && tnsping
	then
		: good
		#ocf_log info "Listener $listener running"
		return $OCF_SUCCESS
	else
		ocf_log info "Listener $listener not running"
		return $OCF_NOT_RUNNING
	fi
}

#
#	'main' starts here...
#

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

# These operations don't require OCF instance parameters to be set
case "$1" in
  meta-data)	meta_data
		exit $OCF_SUCCESS;;

  usage) 	usage
		exit $OCF_SUCCESS;;

  methods)	oralsnr_methods
		exit $?;;

  *);;
esac

if [ x = "x$OCF_RESKEY_sid" ]
then
  ocf_log err "Please set OCF_RESKEY_sid to the Oracle SID !"
  exit $OCF_ERR_ARGS
fi

ora_info "$OCF_RESKEY_sid" "$OCF_RESKEY_home" "$OCF_RESKEY_user"

LSB_STATUS_STOPPED=3
testoraenv
rc=$?
if [ $rc -ne 0 ]; then
	ocf_log info "Oracle environment for SID $ORACLE_SID does not exist"
	case "$1" in
		stop) exit $OCF_SUCCESS;;
		monitor) exit $OCF_NOT_RUNNING;;
		status) exit $LSB_STATUS_STOPPED;;
		*)
			ocf_log err "Oracle environment for SID $ORACLE_SID broken"
			exit $rc
		;;
	esac
fi

setoraenv # important: set the environment for the SID
envtmpf=`mktemp`
dumporaenv > $envtmpf
chmod 644 $envtmpf
trap "rm -f $envtmpf" EXIT

#
# default listener is "LISTENER"
#
listener=${OCF_RESKEY_listener:-"LISTENER"}
# how to get listener processes
procs="ps -e -o pid,args | grep '[t]nslsnr' | grep -w $listener"

US=`id -u -n`
if [ $US != root -a $US != $ORACLE_OWNER ]
then
  ocf_log err "$0 must be run as root or $ORACLE_OWNER"
  exit $OCF_ERR_PERM
fi

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

  start)	oralsnr_start
		exit $?;;

  stop)		oralsnr_stop
		exit $?;;

  status)	if oralsnr_status
		then
		  echo Listener $listener is running
		  exit $OCF_SUCCESS
		else
		  echo Listener $listener is stopped
		  exit $OCF_NOT_RUNNING
		fi
		;;

  monitor)	oralsnr_monitor
		exit $?;;

  validate-all)	# OCF_RESKEY_sid was already checked by ora_info(),
		# just exit successfully here.
		exit $OCF_SUCCESS;;

  *)		oralsnr_methods
		exit $OCF_ERR_UNIMPLEMENTED;;
esac

#
# vim:tabstop=4:shiftwidth=4:textwidth=0:wrapmargin=0