| 1 |
#!/bin/sh |
| 2 |
# |
| 3 |
# |
| 4 |
# oralsnr |
| 5 |
# |
| 6 |
# Description: Manages an Oracle Listener as a High-Availability |
| 7 |
# resource |
| 8 |
# |
| 9 |
# |
| 10 |
# Author: Dejan Muhamedagic |
| 11 |
# Support: [email protected] |
| 12 |
# License: GNU General Public License (GPL) |
| 13 |
# Copyright: (C) 2006 International Business Machines, Inc. |
| 14 |
# |
| 15 |
# This code inspired by the DB2 resource script |
| 16 |
# written by Alan Robertson |
| 17 |
# |
| 18 |
# An example usage in /etc/ha.d/haresources: |
| 19 |
# node1 10.0.0.170 oralsnr::sid::home::user::listener |
| 20 |
# |
| 21 |
# See oralsnr_usage() function below for more details... |
| 22 |
# |
| 23 |
# OCF instance parameters: |
| 24 |
# OCF_RESKEY_sid (mandatory; for the monitor op) |
| 25 |
# OCF_RESKEY_home (optional; else read it from /etc/oratab) |
| 26 |
# OCF_RESKEY_user (optional; user to run the listener) |
| 27 |
# OCF_RESKEY_listener (optional; defaults to LISTENER) |
| 28 |
# |
| 29 |
# Initialization: |
| 30 |
|
| 31 |
: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat} |
| 32 |
. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs |
| 33 |
. ${OCF_FUNCTIONS_DIR}/ora-common.sh |
| 34 |
|
| 35 |
# Parameter defaults |
| 36 |
|
| 37 |
OCF_RESKEY_sid_default="" |
| 38 |
OCF_RESKEY_home_default="" |
| 39 |
OCF_RESKEY_user_default="" |
| 40 |
OCF_RESKEY_listener_default="LISTENER" |
| 41 |
|
| 42 |
: ${OCF_RESKEY_sid=${OCF_RESKEY_sid_default}} |
| 43 |
: ${OCF_RESKEY_home=${OCF_RESKEY_home_default}} |
| 44 |
: ${OCF_RESKEY_user=${OCF_RESKEY_user_default}} |
| 45 |
: ${OCF_RESKEY_listener=${OCF_RESKEY_listener_default}} |
| 46 |
|
| 47 |
####################################################################### |
| 48 |
|
| 49 |
SH=/bin/sh |
| 50 |
|
| 51 |
oralsnr_usage() { |
| 52 |
methods=`oralsnr_methods` |
| 53 |
methods=`echo $methods | tr ' ' '|'` |
| 54 |
cat <<-! |
| 55 |
usage: $0 ($methods) |
| 56 |
|
| 57 |
$0 manages an Oracle Database instance as an HA resource. |
| 58 |
|
| 59 |
The 'start' operation starts the database. |
| 60 |
The 'stop' operation stops the database. |
| 61 |
The 'status' operation reports whether the database is running |
| 62 |
The 'monitor' operation reports whether the database seems to be working |
| 63 |
The 'validate-all' operation reports whether the parameters are valid |
| 64 |
The 'methods' operation reports on the methods $0 supports |
| 65 |
|
| 66 |
! |
| 67 |
} |
| 68 |
|
| 69 |
oralsnr_meta_data() { |
| 70 |
cat <<END |
| 71 |
<?xml version="1.0"?> |
| 72 |
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd"> |
| 73 |
<resource-agent name="oralsnr" version="1.0"> |
| 74 |
<version>1.0</version> |
| 75 |
|
| 76 |
<longdesc lang="en"> |
| 77 |
Resource script for Oracle Listener. It manages an |
| 78 |
Oracle Listener instance as an HA resource. |
| 79 |
</longdesc> |
| 80 |
<shortdesc lang="en">Manages an Oracle TNS listener</shortdesc> |
| 81 |
|
| 82 |
<parameters> |
| 83 |
|
| 84 |
<parameter name="sid" unique="1" required="1"> |
| 85 |
<longdesc lang="en"> |
| 86 |
The Oracle SID (aka ORACLE_SID). Necessary for the monitor op, |
| 87 |
i.e. to do tnsping SID. |
| 88 |
</longdesc> |
| 89 |
<shortdesc lang="en">sid</shortdesc> |
| 90 |
<content type="string" default="${OCF_RESKEY_sid_default}" /> |
| 91 |
</parameter> |
| 92 |
|
| 93 |
<parameter name="home" unique="0"> |
| 94 |
<longdesc lang="en"> |
| 95 |
The Oracle home directory (aka ORACLE_HOME). |
| 96 |
If not specified, then the SID should be listed in /etc/oratab. |
| 97 |
</longdesc> |
| 98 |
<shortdesc lang="en">home</shortdesc> |
| 99 |
<content type="string" default="${OCF_RESKEY_home_default}" /> |
| 100 |
</parameter> |
| 101 |
|
| 102 |
<parameter name="user" unique="0"> |
| 103 |
<longdesc lang="en"> |
| 104 |
Run the listener as this user. |
| 105 |
</longdesc> |
| 106 |
<shortdesc lang="en">user</shortdesc> |
| 107 |
<content type="string" default="${OCF_RESKEY_user_default}" /> |
| 108 |
</parameter> |
| 109 |
|
| 110 |
<parameter name="listener" unique="1"> |
| 111 |
<longdesc lang="en"> |
| 112 |
Listener instance to be started (as defined in listener.ora). |
| 113 |
Defaults to LISTENER. |
| 114 |
</longdesc> |
| 115 |
<shortdesc lang="en">listener</shortdesc> |
| 116 |
<content type="string" default="${OCF_RESKEY_listener_default}" /> |
| 117 |
</parameter> |
| 118 |
|
| 119 |
<parameter name="tns_admin" required="0" unique="0"> |
| 120 |
<longdesc lang="en"> |
| 121 |
Full path to the directory that contains the Oracle |
| 122 |
listener tnsnames.ora configuration file. The shell |
| 123 |
variable TNS_ADMIN is set to the value provided. |
| 124 |
</longdesc> |
| 125 |
<shortdesc lang="en"> |
| 126 |
Full path to the directory containing tnsnames.ora |
| 127 |
</shortdesc> |
| 128 |
<content type="string"/> |
| 129 |
</parameter> |
| 130 |
|
| 131 |
</parameters> |
| 132 |
|
| 133 |
<actions> |
| 134 |
<action name="start" timeout="120s" /> |
| 135 |
<action name="stop" timeout="120s" /> |
| 136 |
<action name="status" timeout="60s" /> |
| 137 |
<action name="monitor" depth="0" timeout="30s" interval="10s" /> |
| 138 |
<action name="validate-all" timeout="5s" /> |
| 139 |
<action name="meta-data" timeout="5s" /> |
| 140 |
<action name="methods" timeout="5s" /> |
| 141 |
</actions> |
| 142 |
</resource-agent> |
| 143 |
END |
| 144 |
} |
| 145 |
|
| 146 |
|
| 147 |
# |
| 148 |
# methods: What methods/operations do we support? |
| 149 |
# |
| 150 |
oralsnr_methods() { |
| 151 |
cat <<-! |
| 152 |
start |
| 153 |
stop |
| 154 |
status |
| 155 |
monitor |
| 156 |
validate-all |
| 157 |
methods |
| 158 |
meta-data |
| 159 |
usage |
| 160 |
! |
| 161 |
} |
| 162 |
|
| 163 |
# |
| 164 |
# Run commands as the Oracle owner... |
| 165 |
# |
| 166 |
runasdba() { |
| 167 |
if [ "$US" = "$ORACLE_OWNER" ]; then |
| 168 |
$SH |
| 169 |
else |
| 170 |
( |
| 171 |
echo ". $ORA_ENVF" |
| 172 |
cat |
| 173 |
) | su -s $SH - $ORACLE_OWNER |
| 174 |
fi |
| 175 |
} |
| 176 |
|
| 177 |
# |
| 178 |
# oralsnr_start: Start the Oracle listener instance |
| 179 |
# |
| 180 |
|
| 181 |
oralsnr_start() { |
| 182 |
if is_proc_running && test_tnsping; then |
| 183 |
: nothing to be done, we can leave right now |
| 184 |
ocf_log info "Listener $listener already running" |
| 185 |
return $OCF_SUCCESS |
| 186 |
fi |
| 187 |
output=`echo lsnrctl start $listener | runasdba` |
| 188 |
if test_tnsping; then |
| 189 |
: cool, we are up and running |
| 190 |
ocf_log info "Listener $listener running: $output" |
| 191 |
return $OCF_SUCCESS |
| 192 |
else |
| 193 |
ocf_exit_reason "Listener $listener appears to have started, but is not running properly: $output" |
| 194 |
ocf_log err "Probable Oracle configuration error" |
| 195 |
return $OCF_ERR_GENERIC |
| 196 |
fi |
| 197 |
} |
| 198 |
|
| 199 |
# |
| 200 |
# oralsnr_stop: Stop the Oracle instance |
| 201 |
# |
| 202 |
oralsnr_stop() { |
| 203 |
if is_proc_running; then |
| 204 |
output=`echo lsnrctl stop $listener | runasdba` |
| 205 |
else |
| 206 |
ocf_log info "Listener $listener already stopped" |
| 207 |
return $OCF_SUCCESS |
| 208 |
fi |
| 209 |
ocf_stop_processes TERM $PROCS_CLEANUP_TIME `proc_pids` # kill the procs if they hanged |
| 210 |
if is_proc_running; then |
| 211 |
ocf_exit_reason "Listener $listener not stopped: $output" |
| 212 |
return $OCF_ERR_GENERIC |
| 213 |
else |
| 214 |
ocf_log info "Listener $listener stopped: $output" |
| 215 |
return $OCF_SUCCESS |
| 216 |
fi |
| 217 |
} |
| 218 |
|
| 219 |
# |
| 220 |
# is_proc_running: is the listener running? |
| 221 |
# |
| 222 |
is_proc_running() { |
| 223 |
show_procs | grep "." > /dev/null |
| 224 |
} |
| 225 |
# the following two should be run only if the process is running |
| 226 |
test_listener() { |
| 227 |
local output |
| 228 |
output=`lsnrctl status $listener` |
| 229 |
if echo "$output" | tail -1 | grep -qs 'completed successfully' |
| 230 |
then |
| 231 |
return $OCF_SUCCESS |
| 232 |
else |
| 233 |
ocf_exit_reason "$listener status failed: $output" |
| 234 |
return $OCF_ERR_GENERIC |
| 235 |
fi |
| 236 |
} |
| 237 |
# and does it work? |
| 238 |
test_tnsping() { |
| 239 |
local output |
| 240 |
output=`tnsping $ORACLE_SID` |
| 241 |
if echo "$output" | tail -1 | grep -qs '^OK'; then |
| 242 |
return $OCF_SUCCESS |
| 243 |
else |
| 244 |
ocf_exit_reason "tnsping $ORACLE_SID failed: $output" |
| 245 |
return $OCF_ERR_GENERIC |
| 246 |
fi |
| 247 |
} |
| 248 |
|
| 249 |
# |
| 250 |
# oralsnr_monitor: Can we connect to the listener? |
| 251 |
# |
| 252 |
oralsnr_monitor() { |
| 253 |
if is_proc_running; then |
| 254 |
test_listener && test_tnsping |
| 255 |
else |
| 256 |
return $OCF_NOT_RUNNING |
| 257 |
fi |
| 258 |
} |
| 259 |
|
| 260 |
oralsnr_status() { |
| 261 |
if is_proc_running |
| 262 |
then |
| 263 |
echo Listener $listener is running |
| 264 |
exit $OCF_SUCCESS |
| 265 |
else |
| 266 |
echo Listener $listener is stopped |
| 267 |
exit $OCF_NOT_RUNNING |
| 268 |
fi |
| 269 |
} |
| 270 |
|
| 271 |
oralsnr_getconfig() { |
| 272 |
ora_common_getconfig "$OCF_RESKEY_sid" "$OCF_RESKEY_home" "$OCF_RESKEY_user" "$OCF_RESKEY_tns_admin" |
| 273 |
listener=${OCF_RESKEY_listener} |
| 274 |
} |
| 275 |
|
| 276 |
oralsnr_validate_all() { |
| 277 |
ora_common_validate_all |
| 278 |
} |
| 279 |
|
| 280 |
# used in ora-common.sh |
| 281 |
show_procs() { |
| 282 |
ps -U "$ORACLE_OWNER" -o pid,user,args | |
| 283 |
grep '[t]nslsnr' | grep -i -w "$listener" |
| 284 |
} |
| 285 |
proc_pids() { show_procs | awk '{print $1}'; } |
| 286 |
PROCS_CLEANUP_TIME="10" |
| 287 |
|
| 288 |
OCF_REQUIRED_PARAMS="sid" |
| 289 |
OCF_REQUIRED_BINARIES="lsnrctl tnsping" |
| 290 |
ocf_rarun $* |
| 291 |
|
| 292 |
# |
| 293 |
# vim:tabstop=4:shiftwidth=4:textwidth=0:wrapmargin=0 |