/usr/lib/ocf/resource.d/heartbeat/oralsnr is in resource-agents 1:3.9.3+git20121009-3ubuntu2.
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 | #!/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 oralsnr_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
. ${OCF_FUNCTIONS_DIR}/ora-common.sh
#######################################################################
SH=/bin/sh
oralsnr_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
!
}
oralsnr_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
!
}
#
# Run commands as the Oracle owner...
#
runasdba() {
if [ "$US" = "$ORACLE_OWNER" ]; then
$SH
else
(
echo ". $ORA_ENVF"
cat
) | su - $ORACLE_OWNER
fi
}
#
# oralsnr_start: Start the Oracle listener instance
#
oralsnr_start() {
if is_proc_running && test_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 test_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"
return $OCF_ERR_GENERIC
fi
}
#
# oralsnr_stop: Stop the Oracle instance
#
oralsnr_stop() {
if is_proc_running; then
output=`echo lsnrctl stop $listener | runasdba`
else
ocf_log info "Listener $listener already stopped"
return $OCF_SUCCESS
fi
ocf_stop_processes TERM $PROCS_CLEANUP_TIME `proc_pids` # kill the procs if they hanged
if is_proc_running; 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
}
#
# is_proc_running: is the listener running?
#
is_proc_running() {
show_procs | grep "." > /dev/null
}
# the following two should be run only if the process is running
test_listener() {
local output
output=`lsnrctl status $listener`
if echo "$output" | tail -1 | grep -qs 'completed successfully'
then
return $OCF_SUCCESS
else
ocf_log err "$listener status failed: $output"
return $OCF_ERR_GENERIC
fi
}
# and does it work?
test_tnsping() {
local output
output=`tnsping $ORACLE_SID`
if echo "$output" | tail -1 | grep -qs '^OK'; then
return $OCF_SUCCESS
else
ocf_log err "tnsping $ORACLE_SID failed: $output"
return $OCF_ERR_GENERIC
fi
}
#
# oralsnr_monitor: Can we connect to the listener?
#
oralsnr_monitor() {
if is_proc_running; then
test_listener && test_tnsping
else
return $OCF_NOT_RUNNING
fi
}
oralsnr_status() {
if is_proc_running
then
echo Listener $listener is running
exit $OCF_SUCCESS
else
echo Listener $listener is stopped
exit $OCF_NOT_RUNNING
fi
}
oralsnr_getconfig() {
ora_common_getconfig "$OCF_RESKEY_sid" "$OCF_RESKEY_home" "$OCF_RESKEY_user"
listener=${OCF_RESKEY_listener:-"LISTENER"}
}
oralsnr_validate_all() {
ora_common_validate_all
}
# used in ora-common.sh
show_procs() {
ps -e -o pid,user,args |
grep '[t]nslsnr' | grep -w "$listener" | grep -w "$ORACLE_OWNER"
}
proc_pids() { show_procs | awk '{print $1}'; }
PROCS_CLEANUP_TIME="10"
OCF_REQUIRED_PARAMS="sid"
OCF_REQUIRED_BINARIES="lsnrctl tnsping"
ocf_rarun $*
#
# vim:tabstop=4:shiftwidth=4:textwidth=0:wrapmargin=0
|