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 "@(#)pgs_smf_register.ksh 1.9 08/05/06 SMI" 29 30 MYDIR=/opt/SUNWscPostgreSQL 31 MYFILE= 32 MYCONFIG= 33 MANIFEST_DIR=/var/svc/manifest/application/sczone-agents 34 35 MYNAME=`basename ${0}` 36 37 . ${MYDIR}/etc/config 38 . ${MYDIR}/lib/functions_static 39 . ${MYDIR}/bin/functions 40 41 42 ############################################################# 43 # create_xml() 44 # 45 # This function creates the xml manifest that will get called 46 # by SMF, i.e. svcadm enable <service> . This allows the SMF 47 # service to be called in a zone by the 48 # 49 # Sun Cluster Data Service for Solaris Container 50 # - sczsmf component 51 # 52 ############################################################# 53 54 create_xml() 55 { 56 MYDIR=$1 57 MYFILE=$2 58 59 if [ ! -d "${MANIFEST_DIR}" ] 60 then 61 mkdir -p ${MANIFEST_DIR} 62 fi 63 64 cat > ${MANIFEST_DIR}/${MYFILE}.xml <<-EOF 65 <?xml version="1.0"?> 66 <!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1"> 67 68 <!-- 69 Copyright 2008 Sun Microsystems, Inc. All rights reserved. 70 Use is subject to license terms. 71 72 --> 73 74 <service_bundle type='manifest' name='${MYFILE}'> 75 76 <service 77 name='application/sczone-agents' 78 type='service' 79 version='1'> 80 81 <!-- 82 Common dependencies for the service 83 --> 84 85 <dependency name='pgs_services' 86 grouping='require_all' 87 restart_on='none' 88 type='service'> 89 <service_fmri value='svc:/milestone/multi-user-server'/> 90 <service_fmri value='svc:/network/loopback'/> 91 </dependency> 92 93 <instance name='${MYFILE}' enabled='false'> 94 95 96 <exec_method 97 type='method' 98 name='start' 99 exec='${MYDIR}/bin/control_pgs start' 100 timeout_seconds='300' > 101 <method_context project='${PROJECT}' > 102 <method_credential user='${USER}' /> 103 </method_context> 104 </exec_method> 105 106 <exec_method 107 type='method' 108 name='stop' 109 exec='${MYDIR}/bin/control_pgs stop' 110 timeout_seconds='300' > 111 <method_context project='${PROJECT}' > 112 <method_credential user='${USER}' /> 113 </method_context> 114 </exec_method> 115 116 <!-- 117 Instance specific parameters 118 --> 119 120 <!-- 121 122 This manifest does not restart on coredumps or abnormal process termination. 123 PostgreSQL has its own restart capabilities, to restart child postmaster processes. 124 If the parent postmaster dies, the whole process tree will disappear.. 125 Due to this fact it is sufficient, to restart on an empty process tree and on HW error. 126 127 For additional information start with man svc.startd 128 129 --> 130 131 <property_group name='startd' type='framework'> 132 <propval name='ignore_error' type='astring' value='core,signal' /> 133 </property_group> 134 135 <property_group name='parameters' type='general'> 136 <propval name='Resource' type='astring' value='${RS}'/> 137 <propval name='Resource_group' type='astring' value='${RG}'/> 138 <propval name='Parameter_File' type='astring' value='${PFILE}'/> 139 </property_group> 140 141 </instance> 142 143 <stability value='Evolving' /> 144 145 <template> 146 <common_name> 147 <loctext xml:lang='C'> 148 Application PostgresSql 149 </loctext> 150 </common_name> 151 </template> 152 </service> 153 154 </service_bundle> 155 156 EOF 157 } 158 159 typeset opt 160 161 while getopts 'f:' opt 162 do 163 case "${opt}" in 164 f) MYCONFIG=${OPTARG};; 165 *) exit 1;; 166 esac 167 done 168 169 # Sourcing the specified config file, either the default one, 170 # or the one supplied with -f 171 172 if [ -n "${MYCONFIG}" ] && [ -f "${MYCONFIG}" ] 173 then 174 echo "sourcing ${MYCONFIG}" 175 . ${MYCONFIG} 176 else 177 PKGCONF=`dirname $0`/pgs_config 178 echo "sourcing ${PKGCONF}" 179 . ${PKGCONF} 180 fi 181 182 # checking and initializing user and project, if they are not set 183 184 if [ -z "${PROJECT}" ] 185 then 186 PROJECT=:default 187 fi 188 189 if [ -z "${USER}" ] 190 then 191 USER=root 192 fi 193 194 195 MYFILE=${RS} 196 197 if create_xml $MYDIR $MYFILE 198 then 199 printf "${MANIFEST_DIR}/${MYFILE}.xml successfully created\n" 200 else 201 printf "${MANIFEST_DIR}/${MYFILE}.xml failed\n" 202 exit 1 203 fi 204 205 if /usr/sbin/svccfg validate ${MANIFEST_DIR}/${MYFILE}.xml 206 then 207 printf "${MANIFEST_DIR}/${MYFILE}.xml successfully validated\n" 208 else 209 exit 1 210 fi 211 212 if /usr/sbin/svccfg import ${MANIFEST_DIR}/${MYFILE}.xml 213 then 214 printf "${MANIFEST_DIR}/${MYFILE}.xml successfully imported\n" 215 else 216 exit 1 217 fi 218 219 # create the parameter file 220 221 if create_pfile 222 then 223 echo "creation of the parameter file ${PFILE} successful" 224 else 225 echo "creation of the parameter file ${PFILE} unsuccessful" 226 exit 1 227 fi 228 229 # Validate the parameters of the Postgres Resource 230 231 if ${MYDIR}/bin/control_pgs validate svc:/application/sczone-agents:${RS} 232 then 233 echo " validation of the PostrgeSQL smf service svc:/application/sczone-agents:${RS} successful" 234 else 235 echo " validation of the PostrgeSQL smf service svc:/application/sczone-agents:${RS} failed, fix the errors and retry" 236 exit 1 237 fi 238 239 exit 0 240