1 # 2 # CDDL HEADER START 3 # 4 # The contents of this file are subject to the terms of the 5 # Common Development and Distribution License (the License). 6 # You may not use this file except in compliance with the License. 7 # 8 # You can obtain a copy of the license at usr/src/CDDL.txt 9 # or http://www.opensolaris.org/os/licensing. 10 # See the License for the specific language governing permissions 11 # and limitations under the License. 12 # 13 # When distributing Covered Code, include this CDDL HEADER in each 14 # file and include the License file at usr/src/CDDL.txt. 15 # If applicable, add the following below this CDDL HEADER, with the 16 # fields enclosed by brackets [] replaced with your own identifying 17 # information: Portions Copyright [yyyy] [name of copyright owner] 18 # 19 # CDDL HEADER END 20 # 21 22 # 23 # Copyright 2007 Sun Microsystems, Inc. All rights reserved. 24 # Use is subject to license terms. 25 # 26 #ident "@(#)functions.ksh 1.7 07/08/07 SMI" 27 # 28 29 PKG=SUNWscsag 30 METHOD=`basename $0` 31 LOGFILE=/var/tmp/${RESOURCE}_logfile 32 33 SCLOGGER=/usr/cluster/lib/sc/scds_syslog 34 SCHA_RESOURCE_GET=/usr/cluster/bin/scha_resource_get 35 SCHA_RESOURCEGROUP_GET=/usr/cluster/bin/scha_resourcegroup_get 36 PMFADM=/usr/cluster/bin/pmfadm 37 TASK_COMMAND="" 38 39 debug_message() 40 { 41 # 42 # Output a debug message to syslog if required 43 # 44 45 if [ "$DEBUG" = "$RESOURCE" -o "$DEBUG" = "ALL" ] 46 then 47 SET_DEBUG="set -x" 48 49 DEBUG_TEXT=$1 50 51 scds_syslog -p daemon.debug -t $(syslog_tag) -m \ 52 "%s" "$DEBUG_TEXT" 53 else 54 SET_DEBUG= 55 fi 56 } 57 58 if [ \( -f /opt/${PKG}/etc/settings \) -a \( "${USE_SETTINGS_FILE}" = "TRUE" \) ] 59 then 60 . /opt/${PKG}/etc/settings 61 if [ -z "${GATEWAY_DIR}" ]; then 62 debug_message "File /opt/${PKG}/etc/settings has not been ammended!" 63 fi 64 else 65 debug_message "File /opt/${PKG}/etc/settings is not getting used." 66 fi 67 68 if [ \( -n "${SagUser}" \) -a \( -n "${SagPwd}" \) ] 69 then 70 SAGCREDS="-SagUser ${SagUser} -SagPwd ${SagPwd}" 71 else 72 SAGCREDS="" 73 fi 74 75 # load SAG variables 76 . ${GATEWAY_DIR}/bin/sag_env.ksh 77 78 preamble="su - ${User} -c " 79 80 syslog_tag() 81 { 82 # 83 # Data Service message format 84 # 85 86 $SET_DEBUG 87 88 print "SC[${PKG:-??}.${METHOD:-??}]:${RESOURCEGROUP:-??}:${RESOURCE:-??}" 89 } 90 91 scds_syslog() 92 { 93 # 94 # Log a message 95 # 96 97 $SET_DEBUG 98 99 $SCLOGGER "$@" & 100 } 101 102 log_message() 103 { 104 # 105 # Output a message to syslog as required 106 # 107 108 debug_message "Function: log_message - Begin" 109 $SET_DEBUG 110 111 if [ -s "${LOGFILE}" ] 112 then 113 PRIORITY=$1 114 HEADER=$2 115 116 # 117 # Ensure the while loop only reads a closed file 118 # 119 120 strings ${LOGFILE} > ${LOGFILE}.copy 121 while read MSG_TXT 122 do 123 scds_syslog -p daemon.${PRIORITY} -t $(syslog_tag) -m \ 124 "%s - %s" \ 125 "${HEADER}" "${MSG_TXT}" 126 done < ${LOGFILE}.copy 127 128 cat /dev/null > ${LOGFILE} > /dev/null 129 cat /dev/null > ${LOGFILE}.copy 130 fi 131 132 debug_message "Function: log_message - End" 133 } 134 135 standard_resource_get() 136 { 137 debug_message "Function: standard_resource_get - Begin" 138 $SET_DEBUG 139 140 PROPERTY=$1 141 142 ${SCHA_RESOURCE_GET} -R ${RESOURCE} -G ${RESOURCEGROUP} -O ${PROPERTY} 143 144 s1=$? 145 146 if [ "${s1}" -ne 0 ]; then 147 debug_message "standard_resource_get - Retrievment of property ${PROPERTY} returned ${s1}" 148 fi 149 150 debug_message "Function: standard_resource_get - End" 151 return ${s1} 152 } 153 154 standard_resourcegroup_get() 155 { 156 debug_message "Function: standard_resourcegroup_get - Begin" 157 $SET_DEBUG 158 159 PROPERTY=$1 160 161 ${SCHA_RESOURCEGROUP_GET} -R ${RESOURCE} -G ${RESOURCEGROUP} -O ${PROPERTY} 162 163 s1=$? 164 165 if [ "${s1}" -ne 0 ]; then 166 debug_message "standard_resource_get - Retrievment of property ${PROPERTY} returned ${s1}" 167 fi 168 169 debug_message "Function: standard_resourcegroup_get - End" 170 171 return ${s1} 172 } 173 174 srm_function() 175 { 176 USER=$1 177 178 debug_message "Function: srm_function - Begin" 179 $SET_DEBUG 180 181 182 # 183 # If Solaris 8 just return 184 # 185 186 if [ `/usr/bin/uname -r` = "5.8" ]; 187 then 188 return 0 189 fi 190 191 # 192 # Retrieve RESOURCE_PROJECT_NAME 193 # 194 195 RESOURCE_PROJECT_NAME=`standard_resource_get RESOURCE_PROJECT_NAME` 196 197 # 198 # Retrieve RG_PROJECT_NAME if RESOURCE_PROJECT_NAME is not set 199 # 200 201 if [ -z "${RESOURCE_PROJECT_NAME}" ]; then 202 203 RESOURCE_PROJECT_NAME=`standard_resourcegroup_get RG_PROJECT_NAME` 204 fi 205 206 # 207 # Return if no projects are defined 208 # 209 210 if [ -z "${RESOURCE_PROJECT_NAME}" ]; then 211 return 0 212 fi 213 214 # 215 # Validate that $USER belongs to the project defined by 216 # ${RESOURCE_PROJECT_NAME} 217 # 218 219 PROJ_MEMBER=`/usr/bin/projects ${USER} | /usr/bin/grep -w ${RESOURCE_PROJECT_NAME}` 220 221 if [ -z "${PROJ_MEMBER}" ]; 222 then 223 scds_syslog -p daemon.error -t $(syslog_tag) -m \ 224 "srm_function - The user %s does not belongs to project %s" \ 225 "${USER}" "${RESOURCE_PROJECT_NAME}" 226 return 1 227 else 228 debug_message "srm_function - User ${USER} belongs to project ${RESOURCE_PROJECT_NAME}" 229 fi 230 231 # 232 # Set TASK_COMMAND 233 # 234 235 TASK_COMMAND="/usr/bin/newtask -p ${RESOURCE_PROJECT_NAME}" 236 237 debug_message "Function: srm_function - End" 238 239 return 0 240 } 241 242 validate_options() 243 { 244 # 245 # Ensure all options are set 246 # 247 248 ${SET_DEBUG} 249 250 debug_message "Function: validate_options - Begin" 251 252 for i in RESOURCE RESOURCEGROUP User GATEWAY_DIR 253 do 254 case $i in 255 RESOURCE) 256 if [ -z ${RESOURCE} ]; then 257 scds_syslog -p daemon.err -t $(syslog_tag) -m \ 258 "ERROR: Option -%s not set" "R" 259 exit 1 260 fi;; 261 262 RESOURCEGROUP) 263 if [ -z ${RESOURCEGROUP} ]; then 264 scds_syslog -p daemon.err -t $(syslog_tag) -m \ 265 "ERROR: Option -%s not set" "G" 266 exit 1 267 fi;; 268 269 User) 270 if [ -z ${User} ]; then 271 scds_syslog -p daemon.err -t $(syslog_tag) -m \ 272 "ERROR: Option -%s not set" "U" 273 exit 1 274 fi;; 275 276 GATEWAY_DIR) 277 if [ -z ${GATEWAY_DIR} ]; then 278 scds_syslog -p daemon.err -t $(syslog_tag) -m \ 279 "ERROR: Option -%s not set" "D" 280 exit 1 281 fi;; 282 esac 283 done 284 285 debug_message "Function: validate_options - End" 286 } 287 288 validate() 289 { 290 # 291 # Validate sag 292 # 293 filename=$1 294 debug_message "Function: validate - Begin" 295 $SET_DEBUG 296 297 rc_validate=0 298 299 # 300 # Validate that ${filename} exists 301 # 302 303 if [ ! -f "${filename}" ] 304 then 305 scds_syslog -p daemon.err -t $(syslog_tag) -m \ 306 "Validate - file %s does not exist" \ 307 "${filename}" 308 rc_validate=1 309 else 310 debug_message "Validate - ${filename} exists" 311 fi 312 313 # 314 # More validate checks here 315 # 316 317 debug_message "Function: validate - End" 318 } 319 320 start_sag() 321 { 322 # 323 # Start sag 324 # 325 326 debug_message "Function: start_sag - Begin" 327 $SET_DEBUG 328 329 rc_start_command=0 330 331 # make sure there is a pid left for pmf until start_sag() does finish 332 START_TIMEOUT=`${SCHA_RESOURCE_GET} -O START_TIMEOUT -R ${RESOURCE} -G ${RESOURCEGROUP}` 333 sleep ${START_TIMEOUT} & 334 335 # disable pmf tag 336 if ${PMFADM} -q ${RESOURCEGROUP},${RESOURCE},0.svc 337 then 338 ${PMFADM} -s ${RESOURCEGROUP},${RESOURCE},0.svc 339 fi 340 341 # give 95% of the START_TIMEOUT to sag_bootstrap 342 MAX_SAG_START_TIMEOUT=`expr ${START_TIMEOUT} \* 95 \/ 100` 343 344 # Starting SAG with sag_bootstrap. According to Swift this is 345 # working for version 5.0 and 6.0. 346 ${preamble} "${GATEWAY_DIR}/bin/sag_bootstrap -sagstart -timeout ${MAX_SAG_START_TIMEOUT} start" > $LOGFILE 2>&1 347 rc_start_command=$? 348 if [ ${rc_start_command} != 0 ]; then 349 # execution of bootstrap failed... bailing out 350 debug_message "SWIFTAlliance Gateway failed to start with returncode ${rc_start_command}" 351 return 100 352 fi 353 354 # depend on the probe to actually test the app running 355 356 debug_message "Function: start_sag - End" 357 } 358 359 stop_sag() 360 { 361 # 362 # Stop sag 363 # 364 365 debug_message "Function: stop_sag - Begin" 366 $SET_DEBUG 367 368 rc_stop_command=0 369 370 ${preamble} "${SAG_HOME}/bin/sag_bootstrap stop" > $LOGFILE 2>&1 371 rc_stop_command=$? 372 if [ ${rc_stop_command} != 0 ]; then 373 debug_message "SWIFTAlliance Gateway failed to stop with returncode ${rc_start_command}" 374 # bootstrap returned fault : rc -> 102 375 return 102 376 fi 377 378 # make sure the dummy sleep started in start_sag() did already 379 # finish, otherwise kill it. 380 if ${PMFADM} -q ${RESOURCEGROUP},${RESOURCE},0.svc 381 then 382 ${PMFADM} -s ${RESOURCEGROUP},${RESOURCE},0.svc KILL 2> /dev/null 383 fi 384 385 debug_message "Function: stop_sag - End" 386 } 387 388 check_sag() 389 { 390 # 391 # Probe sag 392 # 393 394 debug_message "Function: check_sag - Begin" 395 $SET_DEBUG 396 397 if pgrep -u root -f "start_sag .*-R ${RESOURCE} " >/dev/null 398 then 399 rc_check_command=100 400 return 100 401 else 402 rc_check_command=0 403 fi 404 405 ################ 406 ## 407 ## probing consists of a few checks 408 ## provided by swift to perform the checks 409 ## 410 ################ 411 ${preamble} "${SAG_HOME}/bin/sag_system ${SAGCREDS} -- status system | grep started" >/dev/null 2>&1 412 retcode=$? 413 if [ ${retcode} != 0 ]; then 414 debug_message "sag_system did not return status started on first check!" 415 ${preamble} "${SAG_HOME}/bin/sag_system ${SAGCREDS} -- status system | grep partial" >/dev/null 2>&1 416 if [ $? != 0 ]; then 417 debug_message "sag_system did not return status partial on second check!" 418 rc_check_command=1 419 return 100 420 else 421 # clear the state ... running ... 422 debug_message "sag_system did return status partial." 423 fi 424 fi 425 426 debug_message "Function: check_sag - End" 427 } 428