Sdiff pgs_register.ksh


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 28 #ident "%Z%%M% %I% %E% SMI" 29 30 # 31 # This script takes 1 options. 32 # -f filename states a config file different from pgs_config. 33 # This file will be sourced instead of pgs_config if -f filename is specified 34 # 35 36 37 # Set generic variables: 38 39 BINDIR=/opt/SUNWscPostgreSQL/bin 40 UTILDIR=/opt/SUNWscPostgreSQL/util 41 SMFUTILDIR=/opt/SUNWsczone/sczsmf/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 8 or 9 56 57 RESOURCEGROUP=${RG} 58 59 if ! create_pfile 60 then 61 return 1 62 fi 63 64 # define your start, stop, probe an validate command 65 66 start_command="${BINDIR}/control_pgs -R ${RS} -G ${RG} -P ${PFILE} start" 67 stop_command="${BINDIR}/control_pgs -R ${RS} -G ${RG} -P ${PFILE} stop" 68 probe_command="${BINDIR}/control_pgs -R ${RS} -G ${RG} -P ${PFILE} probe" 69 validate_command="${BINDIR}/control_pgs -R ${RS} -G ${RG} -P ${PFILE} validate" 70 71 # register your resource 72 73 if /usr/cluster/bin/scrgadm -pvv -t SUNW.gds | /usr/bin/grep Validate_command>/dev/null 2>&1 74 then 75 76 # register in 3.2 style 77 78 if [ -n "${LH}" ] 79 then 80 /usr/cluster/bin/scrgadm -a -j ${RS} -g ${RG} -t SUNW.gds \ 81 -x Start_command="${start_command}" \ 82 -x Stop_command="${stop_command}" \ 83 -x Probe_command="${probe_command}" \ 84 -x Validate_command="${validate_command}" \ 85 -y Port_list=${PORT}/tcp -y Network_resources_used=${LH} \ 86 -x Stop_signal=9 -y Retry_interval=900 \ 87 -y Resource_dependencies=${HAS_RS} 88 89 St=$? 90 else
128 129 fi 130 131 if [ "${St}" -ne 0 ]; then 132 ${ECHO} "Registration of resource ${RS} failed, please correct the wrong parameters." 133 134 return 1 135 else 136 ${ECHO} "Registration of resource ${RS} succeeded." 137 fi 138 139 # validate the resource only, if the validation is not present 140 141 if ! /usr/cluster/bin/scrgadm -pvv -t SUNW.gds | /usr/bin/grep Validate_command>/dev/null 2>&1 142 then 143 144 # VALIDATE RESOURCE 145 146 ${ECHO} "Validate resource ${RS} in resourcegroup ${RG}" 147 148 # determine whether the resource runs in the global zone or in a prepared zone 149 # and set the zcommand to the appropriate zlogin comand 150 151 zcommand= 152 rgs_zone=$(rgs_zonename) 153 if [ -n "${rgs_zone}" ] 154 then 155 zcommand="/usr/sbin/zlogin ${rgs_zone} " 156 fi 157 158 # validate the contents of the parameter file 159 160 ${zcommand} ${BINDIR}/control_pgs -R ${RS} -G ${RG} -P ${PFILE} validate 161 162 St=$? 163 164 if [ "${St}" -ne 0 ]; then 165 ${ECHO} "Validation of resource ${RS} failed, please correct the wrong parameters." 166 ${ECHO} "Removing resource ${RS} from the cluster configuration." 167 168 /usr/cluster/bin/scrgadm -r -j ${RS} 169 170 return 1 171 else 172 ${ECHO} "Validation of resource ${RS} succeeded." 173 fi 174 fi 175 176 return 0 177 178 } 179 180 local_zone_smf() 181 { 182 183 # function to register a smf resource 184 185 SERVICE_TAG=svc:/application/sczone-agents:${RS} 186 187 if [ ! -f ${SMFUTILDIR}/sczsmf_config ] 188 then 189 ${ECHO} ${SMFUTILDIR}/sczsmf_config does not exist. Make sure, that \ 190 Sun Cluster HA for Solaris container is intalled in the global zone 191 return 1 192 fi 193 194 # prepare the config file 195 196 cp ${SMFUTILDIR}/sczsmf_config ${SMFUTILDIR}/sczsmf_config.work 197 cat << EOF > ${SMFUTILDIR}/sczsmf_config 198 199 # 200 # Copyright 2007 Sun Microsystems, Inc. All rights reserved. 201 # Use is subject to license terms. 202 # 203 # This file will be sourced in by sczsmf_register and the parameters 204 # listed below will be used. 205 # 206 # These parameters can be customized in (key=value) form 207 # 208 # RS - Name of the resource 209 # RG - Name of the resource group containing RS 210 # SCZBT_RS - Name of the SC Zone boot resource 211 # ZONE - Name of the Zone 212 # 213 # For SERVICE, RECURSIVE and STATE, refer to the svcadm(1M)
283 ${ECHO} "Registering the zone smf resource" 284 ksh ${SMFUTILDIR}/sczsmf_register 285 ret_code=${?} 286 if [ ${ret_code} -eq 0 ] 287 then 288 ${ECHO} "set the Retry_interval to 900" 289 /usr/cluster/bin/scrgadm -c -j ${RS} -y Retry_interval=900 290 fi 291 mv ${SMFUTILDIR}/sczsmf_config.work ${SMFUTILDIR}/sczsmf_config 292 else 293 ${ECHO} "The registration of the manifest did not complete, fix the errors and retry" 294 ret_code=0 295 fi 296 297 /usr/sbin/zlogin ${ZONE} /usr/bin/rm /tmp/pgs_config.work 298 299 return ${ret_code} 300 301 } 302 303 304 MYCONFIG= 305 ZONETYPE=global 306 307 typeset opt 308 309 while getopts 'f:' opt 310 do 311 case "${opt}" in 312 f) MYCONFIG=${OPTARG};; 313 *) ${ECHO} "ERROR: ${MYNAME} Option ${OPTARG} unknown - early End. Only -f is valid" 314 exit 1;; 315 esac 316 done 317 318 # Sourcing the specified config file, either the default one, 319 # or the one supplied with -f 320 321 if [ -n "${MYCONFIG}" ] && [ -f "${MYCONFIG}" ] 322 then 323 ${ECHO} "sourcing ${MYCONFIG} and create a working copy under ${UTILDIR}/pgs_config.work" 324 cp ${MYCONFIG} ${UTILDIR}/pgs_config.work 325 . ${MYCONFIG} 326 else 327 PKGCONF=`dirname $0`/pgs_config 328 ${ECHO} "sourcing ${PKGCONF}" 329 . ${PKGCONF} 330 fi 331 332 # Registering the resource 333 334 if [ -n "${ZONE}" ] 335 then 336 local_zone_smf 337 else 338 global_zone 339 fi 340 341 if [ -f ${UTILDIR}/pgs_config.work ] 342 then 343 ${ECHO} " remove the working copy ${UTILDIR}/pgs_config.work" 344 rm ${UTILDIR}/pgs_config.work 345 fi 346 347 exit 0


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 pgs_config. 33 # This file will be sourced instead of pgs_config if -f filename is specified 34 # 35 36 37 # Set generic variables: 38 39 BINDIR=/opt/SUNWscPostgreSQL/bin 40 UTILDIR=/opt/SUNWscPostgreSQL/util 41 SMFUTILDIR=/opt/SUNWsczone/sczsmf/util 42 DIRNAME=/usr/bin/dirname 43 ECHO=/usr/bin/echo 44 STTY=/usr/bin/stty 45 46 MYNAME=`basename ${0}` 47 MYDIR=`dirname ${0}` 48 49 . ${MYDIR}/../etc/config 50 . ${MYDIR}/../lib/functions_static 51 . ${MYDIR}/../bin/functions 52 53 54 global_zone() 55 { 56 # function to register a resource in the Solaris 10 global zone or on Solaris 8 or 9 57 58 RESOURCEGROUP=${RG} 59 60 if ! create_pfile 61 then 62 return 1 63 fi 64 65 # define your start, stop, probe an validate command 66 67 start_command="${BINDIR}/control_pgs -R ${RS} -G ${RG} -P ${PFILE} start" 68 stop_command="${BINDIR}/control_pgs -R ${RS} -G ${RG} -P ${PFILE} stop" 69 probe_command="${BINDIR}/control_pgs -R ${RS} -G ${RG} -P ${PFILE} probe" 70 validate_command="${BINDIR}/control_pgs -R ${RS} -G ${RG} -P ${PFILE} validate" 71 72 # determine whether the resource runs in the global zone or in a zone node 73 # and set the zcommand to the appropriate zlogin comand 74 75 zcommand= 76 rgs_zone=$(rgs_zonename) 77 if [ -n "${rgs_zone}" ] 78 then 79 zcommand="${ZLOGIN} ${rgs_zone} " 80 fi 81 82 # create the <resorce name>-phrase if required 83 84 if [ -n "${SSH_PASSDIR}" ] 85 then 86 if ! store_passphrase 87 then 88 return 1 89 fi 90 fi 91 92 # register your resource 93 94 if /usr/cluster/bin/scrgadm -pvv -t SUNW.gds | /usr/bin/grep Validate_command>/dev/null 2>&1 95 then 96 97 # register in 3.2 style 98 99 if [ -n "${LH}" ] 100 then 101 /usr/cluster/bin/scrgadm -a -j ${RS} -g ${RG} -t SUNW.gds \ 102 -x Start_command="${start_command}" \ 103 -x Stop_command="${stop_command}" \ 104 -x Probe_command="${probe_command}" \ 105 -x Validate_command="${validate_command}" \ 106 -y Port_list=${PORT}/tcp -y Network_resources_used=${LH} \ 107 -x Stop_signal=9 -y Retry_interval=900 \ 108 -y Resource_dependencies=${HAS_RS} 109 110 St=$? 111 else
149 150 fi 151 152 if [ "${St}" -ne 0 ]; then 153 ${ECHO} "Registration of resource ${RS} failed, please correct the wrong parameters." 154 155 return 1 156 else 157 ${ECHO} "Registration of resource ${RS} succeeded." 158 fi 159 160 # validate the resource only, if the validation is not present 161 162 if ! /usr/cluster/bin/scrgadm -pvv -t SUNW.gds | /usr/bin/grep Validate_command>/dev/null 2>&1 163 then 164 165 # VALIDATE RESOURCE 166 167 ${ECHO} "Validate resource ${RS} in resourcegroup ${RG}" 168 169 # validate the contents of the parameter file 170 171 ${zcommand} ${BINDIR}/control_pgs -R ${RS} -G ${RG} -P ${PFILE} validate 172 173 St=$? 174 175 if [ "${St}" -ne 0 ]; then 176 ${ECHO} "Validation of resource ${RS} failed, please correct the wrong parameters." 177 ${ECHO} "Removing resource ${RS} from the cluster configuration." 178 179 /usr/cluster/bin/scrgadm -r -j ${RS} 180 181 return 1 182 else 183 ${ECHO} "Validation of resource ${RS} succeeded." 184 fi 185 fi 186 187 return 0 188 189 } 190 191 local_zone_smf() 192 { 193 194 # function to register a smf resource 195 196 SERVICE_TAG=svc:/application/sczone-agents:${RS} 197 198 if [ ! -f ${SMFUTILDIR}/sczsmf_config ] 199 then 200 ${ECHO} ${SMFUTILDIR}/sczsmf_config does not exist. Make sure, that \ 201 Sun Cluster HA for Solaris container is intalled in the global zone 202 return 1 203 fi 204 205 206 # create the <resorce name>-phrase if required 207 208 zcommand="${ZLOGIN} ${ZONE} " 209 210 # create the <resorce name>-phrase if required 211 212 if [ -n "${SSH_PASSDIR}" ] 213 then 214 if store_passphrase 215 then 216 ${zcommand} ${CHOWN} ${USER} ${SSH_PASSDIR}/${RS}-phrase 217 else 218 return 1 219 fi 220 fi 221 222 223 # prepare the config file 224 225 cp ${SMFUTILDIR}/sczsmf_config ${SMFUTILDIR}/sczsmf_config.work 226 cat << EOF > ${SMFUTILDIR}/sczsmf_config 227 228 # 229 # Copyright 2007 Sun Microsystems, Inc. All rights reserved. 230 # Use is subject to license terms. 231 # 232 # This file will be sourced in by sczsmf_register and the parameters 233 # listed below will be used. 234 # 235 # These parameters can be customized in (key=value) form 236 # 237 # RS - Name of the resource 238 # RG - Name of the resource group containing RS 239 # SCZBT_RS - Name of the SC Zone boot resource 240 # ZONE - Name of the Zone 241 # 242 # For SERVICE, RECURSIVE and STATE, refer to the svcadm(1M)
312 ${ECHO} "Registering the zone smf resource" 313 ksh ${SMFUTILDIR}/sczsmf_register 314 ret_code=${?} 315 if [ ${ret_code} -eq 0 ] 316 then 317 ${ECHO} "set the Retry_interval to 900" 318 /usr/cluster/bin/scrgadm -c -j ${RS} -y Retry_interval=900 319 fi 320 mv ${SMFUTILDIR}/sczsmf_config.work ${SMFUTILDIR}/sczsmf_config 321 else 322 ${ECHO} "The registration of the manifest did not complete, fix the errors and retry" 323 ret_code=0 324 fi 325 326 /usr/sbin/zlogin ${ZONE} /usr/bin/rm /tmp/pgs_config.work 327 328 return ${ret_code} 329 330 } 331 332 store_passphrase() 333 { 334 335 # create the <resorce name>-phrase 336 337 ${zcommand} ${TEST} ${SSH_PASSDIR} 338 if [ ${?} -ne 0 ] 339 then 340 ${ECHO} "The directory ${SSH_PASSDIR} which is necessary to store the passphrase file does not exist" 341 return 1 342 343 fi 344 ${zcommand} ${RM} ${SSH_PASSDIR}/${RS}-phrase 2>/dev/null 345 ${zcommand} ${TOUCH} ${SSH_PASSDIR}/${RS}-phrase 346 ${zcommand} ${CHMOD} 600 ${SSH_PASSDIR}/${RS}-phrase 347 if [ -n "${zcommand}" ] 348 then 349 ${zcommand} ${ECHO} ${passphrase} \>\>${SSH_PASSDIR}/${RS}-phrase 350 else 351 ${ECHO} ${passphrase} >>${SSH_PASSDIR}/${RS}-phrase 352 fi 353 ${zcommand} ${CHMOD} 400 ${SSH_PASSDIR}/${RS}-phrase 354 return 0 355 356 } 357 358 MYCONFIG= 359 ZONETYPE=global 360 361 typeset opt 362 363 while getopts 'f:' opt 364 do 365 case "${opt}" in 366 f) MYCONFIG=${OPTARG};; 367 *) ${ECHO} "ERROR: ${MYNAME} Option ${OPTARG} unknown - early End. Only -f is valid" 368 exit 1;; 369 esac 370 done 371 372 # Sourcing the specified config file, either the default one, 373 # or the one supplied with -f 374 375 if [ -n "${MYCONFIG}" ] && [ -f "${MYCONFIG}" ] 376 then 377 ${ECHO} "sourcing ${MYCONFIG} and create a working copy under ${UTILDIR}/pgs_config.work" 378 cp ${MYCONFIG} ${UTILDIR}/pgs_config.work 379 . ${MYCONFIG} 380 else 381 PKGCONF=`dirname $0`/pgs_config 382 ${ECHO} "sourcing ${PKGCONF}" 383 . ${PKGCONF} 384 fi 385 386 # getting the passphrase if required 387 388 if [ -n "${SSH_PASSDIR}" ] 389 then 390 391 ${ECHO} "Enter the passphrase of your PostgreSQL user." 392 ${STTY} -echo 393 read passphrase 394 ${STTY} echo 395 if [ -z "${passphrase}" ] 396 then 397 ${ECHO} "The passphrase is missing, rerun the pgs_register script" 398 exit 1 399 fi 400 ${ECHO} "Verify your passphrase" 401 ${STTY} -echo 402 read passphrase2 403 ${STTY} echo 404 if [ "${passphrase}" != "${passphrase2}" ] 405 then 406 ${ECHO} "The passphrase verification does not match, rerun the pgs_register script" 407 exit 1 408 fi 409 410 fi 411 412 # Registering the resource 413 414 if [ -n "${ZONE}" ] 415 then 416 local_zone_smf 417 else 418 global_zone 419 fi 420 421 if [ -f ${UTILDIR}/pgs_config.work ] 422 then 423 ${ECHO} " remove the working copy ${UTILDIR}/pgs_config.work" 424 rm ${UTILDIR}/pgs_config.work 425 fi 426 427 exit 0