Old control_pgs.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 # Method for the PostrgresSQL agents and the smf manifest
 30 #
 31 # This method is called by the GDS, manifest, by the optional probe script of the smf method.
 32 #
 33 # it is started with options and up to 2 parameters:
 34 #
 35 #
 36 # $1 start stop or probe
 37 # $2 is the smf service tag name. It is used only if the parameter $1 is probe
 38 #
 39 
 40 MYNAME=`basename ${0}`
 41 MYDIR=`dirname ${0}`
 42 
 43 . ${MYDIR}/../etc/config
 44 . ${MYDIR}/../lib/functions_static
 45 . ${MYDIR}/functions
 46 
 47 debug_message "Method: ${MYNAME} ${*} - Begin"
 48 ${SET_DEBUG}
 49 
 50 # get the options for gds and the zsh command, amend as appropriate
 51 
 52 while getopts 'R:G:P:' opt
 53 do
 54         case "${opt}" in
 55                 R)      RESOURCE=${OPTARG};;
 56                 G)      RESOURCEGROUP=${OPTARG};;
 57                 P)      PARFILE=${OPTARG};;
 58                 *)      exit 1;;
 59         esac
 60 done
 61 
 62 # if no option is set ($OPTIND is 1 in this case), use the smf properties
 63 
 64 if [ ${OPTIND} -gt 1 ]
 65 then
 66         shift $((${OPTIND} - 1))
 67 else
 68 
 69         . /lib/svc/share/smf_include.sh
 70         
 71         # Setting SMF_FMRI in case of validate and probe
 72         
 73         if [ -z "${SMF_FMRI}" ]
 74         then
 75                 SMF_FMRI=${2}   
 76         fi
 77 
 78         # getting the necessary parameters and filling the variables usually filled
 79         # in from options
 80 
 81         get_fmri_parameters
 82 fi
 83 
 84 # set some generic variables
 85 
 86 LOGFILE=/var/tmp/${RESOURCE}_logfile
 87 
 88 case ${1} in
 89 start)
 90 
 91         # start application PostrgresSQL
 92 
 93         # exit from start, if the options are wrong
 94 
 95         validate_options
 96         rc_val=${?}
 97         if [ ${rc_val} -ne 0 ]
 98         then
 99                 terminate ${1} ${rc_val}
100         fi
101         
102         rm ${LOGFILE} 2>/dev/null
103         
104         # check the content of the options 
105 
106         if validate
107         then
108 
109                 # source the parameter file before the actual start
110 
111                 . ${PARFILE}
112 
113                 start_pgs
114                 rc_val=${?}
115                 
116                 if [ ${rc_val} -eq 0 ]
117                 then
118                         log_message notice "start_command rc<${rc_val}>"
119                         debug_message "Method: ${MYNAME} - End (Exit 0)"
120                 else
121                         log_message err "start_command rc<${rc_val}>"
122                 fi
123         else
124                 debug_message "Method: ${MYNAME} - End (Exit 1)"
125                 rc_val=1
126         fi;;
127 stop)
128 
129         # stop application PostrgresSQL
130 
131         # exit from stop, if the options are wrong
132 
133         validate_options
134         rc_val=${?}
135         if [ ${rc_val} -ne 0 ]
136         then
137                 terminate ${1} ${rc_val}
138         fi
139 
140         # source the parameter file before the actual stop
141 
142         . ${PARFILE}
143         
144         stop_pgs
145         rc_val=${?}
146         
147         if [ "${rc_val}" -eq 0 ]
148         then
149                 log_message notice "stop_command rc<${rc_val}>"
150         else
151                 log_message err "stop_command rc<${rc_val}>"
152         fi
153         rc_val=0;;
154 
155 probe)
156 
157         # probe application PostrgresSQL
158 
159         # exit from probe, if the options are wrong
160 
161         validate_options
162         rc_val=${?}
163         if [ ${rc_val} -ne 0 ]
164         then
165                 terminate ${1} ${rc_val}
166         fi
167 
168         
169         # Perform a short parameter validation for the probe, if the validation
170         # fails the return code is taken from the return code of the 
171         # validate_probe function. 
172         # The parameter file is sourced in validate_probe.
173 
174         validate_probe
175         rc_val=${?}
176 
177         if [ ${rc_val} -eq 0 ]
178         then
179 
180                 # spin off a project based smf probe if necessary, do the probe with the check function otherwise
181         
182                 if [ "${Project}" != ":default" ] && [ -n "${SMF_FMRI}" ]
183                 then
184                         /usr/bin/newtask -p ${Project} ${MYDIR}/probe_smf_pgs ${SMF_FMRI}
185                         rc_val=$?
186                 else
187                         check_pgs
188                         rc_val=$?
189                 fi
190         fi;;
191 
192 validate)
193 
194         # validate the parameters for application PostrgresSQL
195 
196         validate_options
197         rc_val=${?}
198         if [ ${rc_val} -ne 0 ]
199         then
200                 terminate ${1} ${rc_val}
201         fi
202         
203         rm ${LOGFILE} 2>/dev/null
204         
205         if validate
206         then
207                 rc_val=0
208         else
209                 rc_val=1
210         fi;;
211         
212 esac
213 
214 # terminate with the right return code, either with an smf specific or the gds/zsh based
215 # return code
216 
217 debug_message "Method: ${MYNAME} ${*} - End terminating"
218 terminate ${1} ${rc_val}