-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgogrid
executable file
·177 lines (155 loc) · 6.5 KB
/
gogrid
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
#!/bin/bash
### This script sets the oracle environment variables for the grid infrastructure, based upon the settings in the /etc/oratab file and the configuration in the Grid Infrastructure.
### It can be used on every (linux) setup where the GI is installed (rac, rac one node, oracle restart).
### To use it you source the script and optionally pass +ASM or -MGMTDB to set the environments for grid infrastructure and the ASM or the MGMTDB instances. If no parameter is given, +ASM is assumed.
### The script expects the oraenv script to be in the /usr/local/bin directory and the oratab file in /etc/. If not change the _ORAENV and _ORATAB variable in the beginning of the script
###
### It should not be used to setup the env variables for intances outside the GI home (so other then +ASM or -MGMTDB).
### Use the godb script for this instead
###
###
### The environment variable set are:
### - ORA_DBNAME: Oracle database name (not when +ASM is specified and ASM is not used)
### - ORACLE_UNQNAME: The oracle db unique name (not when +ASM is specified and ASM is not used)
### - ORACLE_SID: The oracle instance name on this node (not when +ASM is specified and ASM is not used)
### - ORACLE_BASE: The oracle db base directory for the given db
### - ORACLE_HOME: The oracle home directory for the given db
### - PATH: Removes the existing $ORACLE_HOME/bin from the PATH and adds the new $ORACLE_HOME/bin to it
### location of the oraenv script, normally in /usr/local/bin, but can differ
_ORAENV=/usr/local/bin/oraenv
### location of the oratab, normally in /etc, but can differ
_ORATAB=/etc/oratab
### location of the local registry
_OLRLOC=/etc/oracle/olr.loc
### location of the ocr
_OCRLOC=/etc/oracle/ocr.loc
rval=0
### abuse a while loop to avoid a complicated if then construct when testing for errors, as exit can not be used in a sourced script (would kill the current shell)
while true
do
### check the passed db_target
if [ "$1" == "" ]
then
### no target given, assume ASM
db_target="+ASM"
else
### check if target is valid
if [ $1 == "+ASM" ] || [ $1 == "-MGMTDB" ]
then
db_target=$1
else
rval=1
echo "usage gogrid [target]"
echo "where optional target is either +ASM or -MGMTDB"
echo "if no target is given, +ASM is assumed"
break
fi
fi
### determine if this an oracle restart configuration (TRUE) or a rac (FALSE)
_IS_RESTART=$(grep local_only ${_OCRLOC} | cut -d'=' -f2)
### general part to set the clusterware home, path and ld_library_path
OLDHOME=${ORACLE_HOME}
ORACLE_HOME=`awk -F'=' '/^crs_home=/ {print $2}' ${_OLRLOC}`
export ORACLE_HOME
unset ORA_DBNAME
unset ORACLE_UNQNAME
### the following was nicked from the oraenv script and resets the LD_LIBRARY_PATH and PATH variables
###Reset LD_LIBRARY_PATH
case ${LD_LIBRARY_PATH:-""} in
*$OLDHOME/lib*) LD_LIBRARY_PATH=`echo $LD_LIBRARY_PATH | \
sed "s;$OLDHOME/lib;$ORACLE_HOME/lib;g"` ;;
*$ORACLE_HOME/lib*) ;;
"") LD_LIBRARY_PATH=$ORACLE_HOME/lib ;;
*) LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH ;;
esac
export LD_LIBRARY_PATH
case "$OLDHOME" in
"") OLDHOME=$PATH ;; #This makes it so that null OLDHOME can't match
esac #anything in next case statement
case "$PATH" in
*$OLDHOME/bin*) PATH=`echo $PATH | \
sed "s;$OLDHOME/bin;$ORACLE_HOME/bin;g"` ;;
*$ORACLE_HOME/bin*) ;;
*:) PATH=${PATH}$ORACLE_HOME/bin: ;;
"") PATH=$ORACLE_HOME/bin ;;
*) PATH=$PATH:$ORACLE_HOME/bin ;;
esac
export PATH
### set the ORACLE_BASE (unset it first otherwise the orabase utility will just return the current value)
unset ORACLE_BASE
ORACLE_BASE=`$ORACLE_HOME/bin/orabase`
export ORACLE_BASE
if [ ${db_target} == "+ASM" ]
then
if [ "${_IS_RESTART}" == "TRUE" ]
then
### check if an ASM resource exists
_ASM_NAME=$(${ORACLE_HOME}/bin/crsctl stat res -w "TYPE = ora.asm.type" | grep NAME | cut -d'.' -f2 | tr "[a-z]" "[A-Z]")
if [ -z ${_ASM_NAME} ]
then
### no ASM
unset ORACLE_SID
else
ORACLE_SID=+${_ASM_NAME}
ORA_DBNAME=${ORACLE_SID}
ORACLE_UNQNAME=${ORA_DBNAME}
export ORA_DBNAME ORACLE_UNQNAME ORACLE_SID
fi
else
### check if this is a flex cluster (returns 0 if this is a flex cluster)
_IS_FLEX=$(${ORACLE_HOME}/bin/crsctl get cluster mode status | grep -v flex -c)
### if this is a flex cluster
if [ ${_IS_FLEX} -eq 0 ]
then
### check if there is an ASM instance running on this node
ORACLE_SID=$(${ORACLE_HOME}/bin/srvctl status asm -detail | grep "on node $(hostname --short)" | cut -d' ' -f3)
if [ "${ORACLE_SID}" == "" ]
then
### no ASM instance found running on this host, either clusterware without ASM or only ASM proxy running here
unset ORACLE_SID
else
ORA_DBNAME=+ASM
ORACLE_UNQNAME=${ORA_DBNAME}
export ORA_DBNAME ORACLE_UNQNAME ORACLE_SID
fi
else
### this is a standard cluster
### check if an ASM resource exists
_ASM_NAME=$(${ORACLE_HOME}/bin/crsctl stat res -w "TYPE = ora.asm.type" | grep NAME | cut -d'.' -f2 | tr "[a-z]" "[A-Z]")
if [ -z ${_ASM_NAME} ]
then
### no ASM
unset ORACLE_SID
else
### get the number of this node to create the instance name
_NODE_NR=$(${ORACLE_HOME}/bin/olsnodes -n -l | cut -f2)
ORA_DBNAME=+${_ASM_NAME}
ORACLE_UNQNAME=${ORA_DBNAME}
ORACLE_SID=${ORA_DBNAME}${_NODE_NR}
export ORA_DBNAME ORACLE_UNQNAME ORACLE_SID
fi
fi
fi
else
### if not +ASM, then it must be -MGMTDB
### must get first a system with mgmtdb to test with
ORACLE_SID=$(${ORACLE_HOME}/bin/srvctl status mgmtdb | grep "on node $(hostname --short)" | cut -d' ' -f2)
if [ "${ORACLE_SID}" == "" ]
then
### either mgmtdb is not configured or not active on this node
unset ORACLE_SID
echo "Either there is no MGMTDB configured or the instance is currently not running on this node"
rval=2
else
ORA_DBNAME=ORACLE_SID
ORACLE_UNQNAME=${ORA_DBNAME}
export ORA_DBNAME ORACLE_UNQNAME ORACLE_SID
fi
fi
### all went ok, break out of the loop
break
done
### Cleanup
unset db_target
### return rval
return ${rval}