New rolechg_register.ksh
1 #!/usr/bin/ksh
2 #
3 # CDDL HEADER START
4 #
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the License).
7 # You may not use this file except in compliance with the License.
8 #
9 # You can obtain a copy of the license at usr/src/CDDL.txt
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
13 #
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/CDDL.txt.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets [] replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
19 #
20 # CDDL HEADER END
21 #
22
23 #
24 # Copyright 2008 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
26 #
27
28 # ident "%Z%%M% %I% %E% SMI"
29
30 #
31 # This script takes 1 options.
32 # -f filename states a config file different from rolechg_config.
33 # This file will be sourced instead of rolechg_config if -f filename is specified
34 #
35
36
37 # Set generic variables:
38
39 BINDIR=/opt/SUNWscPostgreSQL/rolechg/bin
40 UTILDIR=/opt/SUNWscPostgreSQL/rolechg/util
41 SMFUTILDIR=/opt/SUNWsczone/sczsmf/rolechg/util
42 DIRNAME=/usr/bin/dirname
43 ECHO=/usr/bin/${ECHO}
44
45 MYNAME=`basename ${0}`
46 MYDIR=`dirname ${0}`
47
48 . ${MYDIR}/../etc/config
49 . ${MYDIR}/../../lib/functions_static
50 . ${MYDIR}/../bin/functions
51
52
53 global_zone()
54 {
55 # function to register a resource in the Solaris 10 global zone or on Solaris 9
56
57 # define your start, stop, probe an validate command
58
59 start_command="${BINDIR}/control_rolechg -R ${RS} -G ${RG} -H ${STDBY_HOST} -P ${STDBY_PFILE} -T ${TRIGGER} -W ${WAIT} start"
60 stop_command="${BINDIR}/control_rolechg -R ${RS} -G ${RG} -H ${STDBY_HOST} -P ${STDBY_PFILE} -T ${TRIGGER} -W ${WAIT} stop"
61 probe_command="${BINDIR}/control_rolechg -R ${RS} -G ${RG} -H ${STDBY_HOST} -P ${STDBY_PFILE} -T ${TRIGGER} -W ${WAIT} probe"
62 validate_command="${BINDIR}/control_rolechg -R ${RS} -G ${RG} -H ${STDBY_HOST} -P ${STDBY_PFILE} -T ${TRIGGER} -W ${WAIT} validate"
63
64 # set the LOCAL_NODE dependencies to the standby database and if defined to the primary
65 # database resources.
66
67 DEP=${STDBY_RS}{ANY_NODE}
68
69 if [ -n "${PRI_RS}" ]
70 then
71 DEP=${DEP},${PRI_RS}{ANY_NODE}
72 fi
73
74 # register your resource
75
76
77 if [ -n "${LH}" ]
78 then
79 /usr/cluster/bin/scrgadm -a -j ${RS} -g ${RG} -t SUNW.gds \
80 -x Start_command="${start_command}" \
81 -x Stop_command="${stop_command}" \
82 -x Probe_command="${probe_command}" \
83 -x Validate_command="${validate_command}" \
84 -y Port_list=${PORT}/tcp \
85 -x Stop_signal=9 -y Retry_interval=900 \
86 -y Resource_dependencies=${HAS_RS},${LH} \
87 -y Resource_dependencies_weak=${DEP}
88
89 St=$?
90 else
91 /usr/cluster/bin/scrgadm -a -j ${RS} -g ${RG} -t SUNW.gds \
92 -x Start_command="${start_command}" \
93 -x Stop_command="${stop_command}" \
94 -x Probe_command="${probe_command}" \
95 -x Validate_command="${validate_command}" \
96 -x Network_aware=false \
97 -x Stop_signal=9 -y Retry_interval=900 \
98 -y Resource_dependencies=${HAS_RS} \
99 -y Resource_dependencies_weak=${DEP}
100
101 St=$?
102 fi
103
104 if [ "${St}" -ne 0 ]; then
105 ${ECHO} "Registration of resource ${RS} failed, please correct the wrong parameters."
106
107 return 1
108 else
109 ${ECHO} "Registration of resource ${RS} succeeded."
110 fi
111
112 return 0
113
114 }
115
116 MYCONFIG=
117 ZONETYPE=global
118
119 typeset opt
120
121 while getopts 'f:' opt
122 do
123 case "${opt}" in
124 f) MYCONFIG=${OPTARG};;
125 *) ${ECHO} "ERROR: ${MYNAME} Option ${OPTARG} unknown - early End. Only -f is valid"
126 exit 1;;
127 esac
128 done
129
130 # Sourcing the specified config file, either the default one,
131 # or the one supplied with -f
132
133 if [ -n "${MYCONFIG}" ] && [ -f "${MYCONFIG}" ]
134 then
135 ${ECHO} "sourcing ${MYCONFIG} and create a working copy under ${UTILDIR}/rolechg_config.work"
136 /usr/bin/cp ${MYCONFIG} ${UTILDIR}/rolechg_config.work
137 . ${MYCONFIG}
138 else
139 PKGCONF=`dirname $0`/rolechg_config
140 ${ECHO} "sourcing ${PKGCONF}"
141 . ${PKGCONF}
142 fi
143
144 # Registering the resource
145
146 global_zone
147
148
149 if [ -f ${UTILDIR}/rolechg_config.work ]
150 then
151 ${ECHO} " remove the working copy ${UTILDIR}/rolechg_config.work"
152 ${RM} ${UTILDIR}/rolechg_config.work
153 fi
154
155 exit 0