Old pgs_smf_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
28 #ident "%Z%%M% %I% %E% 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 2006 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 <service_fmri value='svc:/network/physical'/>
92 </dependency>
93
94 <instance name='${MYFILE}' enabled='false'>
95
96
97 <exec_method
98 type='method'
99 name='start'
100 exec='${MYDIR}/bin/control_pgs start'
101 timeout_seconds='300' >
102 <method_context project='${PROJECT}' >
103 <method_credential user='${USER}' />
104 </method_context>
105 </exec_method>
106
107 <exec_method
108 type='method'
109 name='stop'
110 exec='${MYDIR}/bin/control_pgs stop'
111 timeout_seconds='300' >
112 <method_context project='${PROJECT}' >
113 <method_credential user='${USER}' />
114 </method_context>
115 </exec_method>
116
117 <!--
118 Instance specific parameters
119 -->
120
121 <!--
122
123 This manifest does not restart on coredumps or abnormal process termination.
124 PostgreSQL has its own restart capabilities, to restart child postmaster processes.
125 If the parent postmaster dies, the whole process tree will disappear..
126 Due to this fact it is sufficient, to restart on an empty process tree and on HW error.
127
128 For additional information start with man svc.startd
129
130 -->
131
132 <property_group name='startd' type='framework'>
133 <propval name='ignore_error' type='astring' value='core,signal' />
134 </property_group>
135
136 <property_group name='parameters' type='general'>
137 <propval name='Resource' type='astring' value='${RS}'/>
138 <propval name='Resource_group' type='astring' value='${RG}'/>
139 <propval name='Parameter_File' type='astring' value='${PFILE}'/>
140 </property_group>
141
142 </instance>
143
144 <stability value='Evolving' />
145
146 <template>
147 <common_name>
148 <loctext xml:lang='C'>
149 Application PostgresSql
150 </loctext>
151 </common_name>
152 </template>
153 </service>
154
155 </service_bundle>
156
157 EOF
158 }
159
160 typeset opt
161
162 while getopts 'f:' opt
163 do
164 case "${opt}" in
165 f) MYCONFIG=${OPTARG};;
166 *) exit 1;;
167 esac
168 done
169
170 # Sourcing the specified config file, either the default one,
171 # or the one supplied with -f
172
173 if [ -n "${MYCONFIG}" ] && [ -f "${MYCONFIG}" ]
174 then
175 echo "sourcing ${MYCONFIG}"
176 . ${MYCONFIG}
177 else
178 PKGCONF=`dirname $0`/pgs_config
179 echo "sourcing ${PKGCONF}"
180 . ${PKGCONF}
181 fi
182
183 # checking and initializing user and project, if they are not set
184
185 if [ -z "${PROJECT}" ]
186 then
187 PROJECT=:default
188 fi
189
190 if [ -z "${USER}" ]
191 then
192 USER=root
193 fi
194
195
196 MYFILE=${RS}
197
198 if create_xml $MYDIR $MYFILE
199 then
200 printf "${MANIFEST_DIR}/${MYFILE}.xml successfully created\n"
201 else
202 printf "${MANIFEST_DIR}/${MYFILE}.xml failed\n"
203 exit 1
204 fi
205
206 if /usr/sbin/svccfg validate ${MANIFEST_DIR}/${MYFILE}.xml
207 then
208 printf "${MANIFEST_DIR}/${MYFILE}.xml successfully validated\n"
209 else
210 exit 1
211 fi
212
213 if /usr/sbin/svccfg import ${MANIFEST_DIR}/${MYFILE}.xml
214 then
215 printf "${MANIFEST_DIR}/${MYFILE}.xml successfully imported\n"
216 else
217 exit 1
218 fi
219
220 # create the parameter file
221
222 if create_pfile
223 then
224 echo "creation of the parameter file ${PFILE} successful"
225 else
226 echo "creation of the parameter file ${PFILE} unsuccessful"
227 exit 1
228 fi
229
230 # Validate the parameters of the Postgres Resource
231
232 if ${MYDIR}/bin/control_pgs validate svc:/application/sczone-agents:${RS}
233 then
234 echo " validation of the PostrgeSQL smf service svc:/application/sczone-agents:${RS} successful"
235 else
236 echo " validation of the PostrgeSQL smf service svc:/application/sczone-agents:${RS} failed, fix the errors and retry"
237 exit 1
238 fi
239
240 exit 0