Old sczbt_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 2007 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
26 #
27 #ident "%Z%%M% %I% %E% SMI"
28 #
29 # This script has the optional -f option:
30 # -f <filename> sources a user definable config file
31 # different from sczbt_config.
32
33 MYNAME=`basename ${0}`
34
35 typeset opt
36
37 while getopts 'f:' opt
38 do
39 case "${opt}" in
40 f) MYCONFIG=${OPTARG};;
41 *) echo "ERROR: ${MYNAME} Option ${OPTARG} unknown - early End. Only -f is valid"
42 exit 1;;
43 esac
44 done
45
46 # Sourcing the specified config file, either the default one,
47 # or the one supplied with -f
48
49 if [ -n "${MYCONFIG}" ] && [ -f "${MYCONFIG}" ]
50 then
51 echo "sourcing ${MYCONFIG} "
52 . ${MYCONFIG}
53 else
54 PKGCONF=`dirname $0`/sczbt_config
55 echo "sourcing ${PKGCONF}"
56 . ${PKGCONF}
57 fi
58
59 # constructing the parameter file
60
61 if [ ! -d ${PARAMETERDIR} ]; then
62 echo "The value given for PARAMETERDIR (${PARAMETERDIR}) in sczbt_config is not a directory!"
63 exit 1
64 fi
65
66 if [ ! -f ${PARAMETERDIR}/sczbt_${RS} ]; then
67 cat > ${PARAMETERDIR}/sczbt_${RS} <<EOF
68 #!/usr/bin/ksh
69 #
70 # Copyright 2007 Sun Microsystems, Inc. All rights reserved.
71 # Use is subject to license terms.
72 #
73 #
74 # Parameters for sczbt (Zone Boot)
75 #
76 # Zonename Name of the zone
77 # Zonebrand Brand of the zone. Current supported options are
78 # "native" (default), "lx" or "solaris8"
79 # Zonebootopt Zone boot options ("-s" requires that Milestone=single-user)
80 # Milestone SMF Milestone which needs to be online before the zone is
81 # considered as booted. This option is only used for the
82 # "native" Zonebrand.
83 # LXrunlevel Runlevel which needs to get reached before the zone is
84 # considered booted. This option is only used for the "lx"
85 # Zonebrand.
86 # SLrunlevel Solaris legacy runlevel which needs to get reached before the
87 # zone is considered booted. This option is only used for the
88 # "solaris8" Zonebrand.
89 # Mounts Mounts is a list of directories and their mount options,
90 # which are loopback mounted from the global zone into the
91 # newly booted zone. The mountpoint in the local zone can
92 # be different to the mountpoint from the global zone.
93 #
94 # The Mounts parameter format is as follows,
95 #
96 # Mounts="/<global zone directory>:/<local zone directory>:<mount options>"
97 #
98 # The following are valid examples for the "Mounts" variable
99 #
100 # Mounts="/globalzone-dir1:/localzone-dir1:rw"
101 # Mounts="/globalzone-dir1:/localzone-dir1:rw /globalzone-dir2:rw"
102 # The only required entry is the /<global zone directory>, the
103 # /<local zone directory> and <mount options> can be omitted.
104 #
105 # Omitting /<local zone directory> will make the local zone
106 # mountpoint the same as the global zone directory.
107 #
108 # Omitting <mount options> will not provide any mount options
109 # except the default options from the mount command.
110 #
111 # Note: You must manually create any local zone mountpoint
112 # directories that will be used within the Mounts variable,
113 # before registering this resource within Sun Cluster.
114 #
115
116 Zonename="${Zonename}"
117 Zonebrand="${Zonebrand}"
118 Zonebootopt="${Zonebootopt}"
119 Milestone="${Milestone}"
120 LXrunlevel="${LXrunlevel}"
121 SLrunlevel="${SLrunlevel}"
122 Mounts="${Mounts}"
123 EOF
124
125 else
126 echo "The parameterfile ${PARAMETERDIR}/sczbt_${RS} already exists! Will not overwrite and exit."
127 exit 1
128 fi
129
130
131 # Checking dependencies for SC_NETWORK=true
132
133 SC_NETWORK=`echo ${SC_NETWORK}|/usr/bin/tr [:upper:] [:lower:]`
134
135 if [ "${SC_NETWORK}" == "true" -a -z "${SC_LH}" ]
136 then
137 echo "Error: SC_LH is required with SC_NETWORK=true"
138 rm ${PARAMETERDIR}/sczbt_${RS}
139 exit 1
140 fi
141
142 # If the configured zone has set ip-type=exclusive, then assigning a
143 # SUNW.LogicalHostname to this zone is not possible.
144
145 IPTYPE=`/usr/sbin/zonecfg -z ${Zonename} info | /bin/grep "^ip-type:" | /bin/awk '{print $2}'`
146
147 if [ "${IPTYPE}" == "exclusive" ] && [ "${SC_NETWORK}" == "true" ]
148 then
149 echo "Error: The zone ${Zonename} has set ip-type=exclusive. This can not be combined with setting SC_NETWORK=true."
150 rm ${PARAMETERDIR}/sczbt_${RS}
151 exit 1
152 fi
153
154 # Checking dependencies for FAILOVER=true
155
156 FAILOVER=`echo ${FAILOVER}|/usr/bin/tr [:upper:] [:lower:]`
157
158 if [ "${FAILOVER}" == "true" -a -z "${HAS_RS}" ]
159 then
160 echo "Error: HAS_RS is required with FAILOVER=true"
161 rm ${PARAMETERDIR}/sczbt_${RS}
162 exit 1
163 fi
164
165 # Setting Resource_dependencies
166
167 if [ "${SC_LH}" ]
168 then
169 RESOURCE_DEPENDENCIES="-y Resource_dependencies=${SC_LH}"
170 else
171 RESOURCE_DEPENDENCIES=
172 fi
173
174 if [ "${HAS_RS}" ]
175 then
176 if [ "${RESOURCE_DEPENDENCIES}" ]
177 then
178 RESOURCE_DEPENDENCIES="$RESOURCE_DEPENDENCIES,${HAS_RS}"
179 else
180 RESOURCE_DEPENDENCIES="-y Resource_dependencies=${HAS_RS}"
181 fi
182 fi
183
184 if [ ${SC_NETWORK} == "true" ]; then
185
186 /usr/cluster/bin/scrgadm -a -j ${RS} -g ${RG} -t SUNW.gds \
187 -x Start_command="/opt/SUNWsczone/sczbt/bin/start_sczbt \
188 -R ${RS} -G ${RG} -P ${PARAMETERDIR} " \
189 -x Stop_command="/opt/SUNWsczone/sczbt/bin/stop_sczbt \
190 -R ${RS} -G ${RG} -P ${PARAMETERDIR}" \
191 -x Probe_command="/opt/SUNWsczone/sczbt/bin/probe_sczbt \
192 -R ${RS} -G ${RG} -P ${PARAMETERDIR}" \
193 -y Port_list=10000/tcp -y Network_resources_used=${SC_LH} \
194 -x Stop_signal=9 ${RESOURCE_DEPENDENCIES}
195
196 else
197
198 /usr/cluster/bin/scrgadm -a -j ${RS} -g ${RG} -t SUNW.gds \
199 -x Start_command="/opt/SUNWsczone/sczbt/bin/start_sczbt \
200 -R ${RS} -G ${RG} -P ${PARAMETERDIR}" \
201 -x Stop_command="/opt/SUNWsczone/sczbt/bin/stop_sczbt \
202 -R ${RS} -G ${RG} -P ${PARAMETERDIR}" \
203 -x Probe_command="/opt/SUNWsczone/sczbt/bin/probe_sczbt \
204 -R ${RS} -G ${RG} -P ${PARAMETERDIR}" \
205 -x Network_aware=false \
206 -x Stop_signal=9 ${RESOURCE_DEPENDENCIES}
207
208 fi
209
210 St=$?
211
212 if [ "${St}" -ne 0 ]; then
213 echo "Registration of resource ${RS} failed, please correct the wrong parameters."
214 echo "Removing parameterfile ${PARAMETERDIR}/sczbt_${RS} for resource ${RS}."
215 rm ${PARAMETERDIR}/sczbt_${RS}
216 exit 1
217 else
218 echo "Registration of resource ${RS} succeeded."
219 fi
220
221 # VALIDATE RESOURCE
222
223 /opt/SUNWsczone/sczbt/bin/validate_sczbt -R ${RS} -G ${RG} -P ${PARAMETERDIR}
224
225 St=$?
226
227 if [ "${St}" -ne 0 ]; then
228 echo "Validation of resource ${RS} failed, check the syslog for the wrong parameters."
229 echo "Removing resource ${RS} from the cluster configuration."
230
231 /usr/cluster/bin/scrgadm -r -j ${RS}
232 echo "Removing parameterfile ${PARAMETERDIR}/sczbt_${RS} for resource ${RS}."
233 rm ${PARAMETERDIR}/sczbt_${RS}
234
235 exit 1
236 else
237 echo "Validation of resource ${RS} succeeded."
238 fi
239
240 exit 0