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 SUNCsc_template/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 <packagename>/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 2008 Sun Microsystems, Inc. All rights reserved. 24 # Use is subject to license terms. 25 # 26 # ident "@(#)README 1.2 08/02/12 SMI" 27 # 28 29 SUNCsc_template - Template for writing GDS based Suncluster Data Services. 30 31 Version 1.0 14.11.2007 32 33 34 Here are just some guidelines for using this template: 35 36 1. This SC3.x Data Service template is setup to work with GDS. 37 Subsequently this is the callback behavior with SC3.x 38 39 RGM -> GDS -> "control_xxx <options> start" | "control_xxx <options> stop" 40 | "control_xxx <options> probe" 41 42 2. There are lots of debug messages within this template that 43 are there to help you. The debug message flow is as 44 follows, ie here's what a unsuccessful start_xxx does 45 46 daemon.debug "Method: ${MYNAME} - Begin" 47 daemon.debug "Function: validate - Begin" 48 daemon.err "Validate - file %s does not exist" 49 daemon.debug "Function: validate - End" 50 daemon.debug "Method: ${MYNAME} - End (Exit 1)" 51 52 3. If possible please try to EXIT (return to caller) from the 53 control_xxx script. 54 55 Doing this will ensure that your debug messages 56 "Begin" and "End" 57 58 4. Turning debug on just requires that you edit the SUNCscxxx/etc/config 59 file. Either enter the resource name for debug on just 60 the resource, a "," separated list of resources, or ALL for all resources, 61 if you are running multiple instances that use this data service. 62 63 5. When printing out messages, you'll see in the SUNCscxxx/lib/funtions_static 64 file that there is a wrapper function called log_message 65 which in turn uses scds_syslog. If using scds_syslog 66 try to use %s to substitute any variables. An example 67 of this can be found in the function debug_message. 68 69 6. If you produce documentation for your data service and also 70 want to document the messages and their msgid's you'll need 71 need to do this outside of your scripts, eg. 72 73 echo "Validate - file %s does not exist" | msgid 74 75 will generate the following 76 77 600366 Validate - file %s does not exist 78 79 Please be aware that if this msgid is in use, you can check 80 the SC3.x Error Message Guide to see if it's in use, then 81 you MUST modify your message, ie 82 83 echo "Validate - file %s does not exist " | msgid 84 ^ 85 will generate the following (Note the space) 86 87 409456 Validate - file %s does not exist 88 89 This is only feasible in a sun cluster environment, because the necessary 90 scds_syslog binary is unavailable if no cluster is installed. In this case, 91 the logger command is used which generates the msgid 702911 only. 92 93 7. Adding more options to either the 94 control_xxx, just requires some more lines from you, 95 96 control_xxx 97 98 while getopts 'R:G:C' opt 99 do 100 case "${opt}" in 101 R) RESOURCE=${OPTARG};; 102 G) RESOURCEGROUP=${OPTARG};; 103 C) CONFIG_FILE=${OPTARG};; 104 *) logger -p daemon.err \ 105 "ERROR: ${MYNAME} Option ${OPTARG} unknown" 106 exit 1;; 107 esac 108 done 109 110 111 ./bin/functions - validate_options 112 113 validate_options() 114 { 115 debug_message "Function: validate_options - Begin" 116 ${SET_DEBUG} 117 # 118 # Ensure all options are set 119 # 120 121 MYNAME=`basename $0` 122 123 rc_validate_options=0 124 125 for i in RESOURCE RESOURCEGROUP CONFIG_FILE 126 do 127 case $i in 128 RESOURCE) 129 if [ -z ${RESOURCE} ]; then 130 logger -p daemon.err \ 131 "ERROR: ${MYNAME} Option -R not set" 132 rc_validate_options=1 133 fi;; 134 135 RESOURCEGROUP) 136 if [ -z ${RESOURCEGROUP} ]; then 137 logger -p daemon.err \ 138 "ERROR: ${MYNAME} Option -G not set" 139 rc_validate_options=1 140 fi;; 141 142 CONFIG_FILE) 143 if [ -z ${CONFIG_FILE} ]; then 144 logger -p daemon.err \ 145 "ERROR: ${MYNAME} Option -C not set" 146 rc_validate_options=1 147 fi;; 148 149 esac 150 done 151 152 debug_message "Function: validate_options - End" 153 return ${rc_validate_options} 154 155 } 156 157 8. If you want to use the built-in start dependency follow the guidelines 158 in the start_xxx() function. 159 160 9. If you want to use the built-in restart dependency follow the guidelines 161 in the check_xxx() function. 162 163 10. Do not change the exit codes. They are there for a purpose and required 164 by GDS to function. 165 166 11. Personalize the scripts and the functions. 167 If your package and the scripts should not be named xxx, execute the rename 168 script in the tools directory 169 tools/rename <new_name> 170 171 From this moment all reference in this readme to xxx_ or _xxx should be 172 read as 173 <new_name>_ or _<new_name> 174 175 12. When creating the package edit the Make_package/etc/pkginfo file and 176 change PKG, NAME and DESC entries in that file. 177 178 If you don't want your package to be named as SUNCscxxx change the 179 directory SUNCscxxx to SUNCsc<new_name>. 180 181 Run the Make_package in the directory Make_package/bin. 182 You have to be in that directory when running the command. 183 184 13. In order to work properly on Solaris 10 with Zones, if you use 185 /usr/bin/ps or /usr/bin/pgrep within the agent, you should 186 call the function zone_function() and call ps/pgrep like 187 188 zone_function 189 190 /usr/bin/pgrep ${PZONEOPT} <whatever you else want to call> 191 192 This will set option "-z <zonename>" if the agent is used on 193 a Solaris 10 system, else ${PZONEOPT} is empty. 194 If you have additional code special to Solaris 10, you can set it 195 within zone_function() as well. 196 197 14. If your application does not leave a process behind, you need to remove 198 the hashes between the lines "### "disabling pmf" code begin" and 199 "### "disabling pmf" code end". 200 201 An occurrence of this scenario are applications which just trigger an 202 pre-spawned daemon to start and stop something or "Applications" which just 203 manipulate flat files. 204 205 15. How to make your agent runnable in a local zone. 206 207 It is important, that the zone inherits at least the /opt/agent_name 208 directory of the global zone, otherwise it will not have the agent code. 209 IMPORTANT this can only be defined at zone creation, so it may be better to 210 inherit /opt. 211 212 Having the code in the local zone is not enough. The necessary resources 213 needs to be configured in the global zone. You have two options: 214 215 1. use the zsh script component of the Sun Cluster HA Container agent. 216 2. use the smf component with an optional boot script. 217 218 The zsh component is the simplest approach, it has the drawback/benefit, 219 that it does not react on pmf restarts. 220 In this case configure the start stop and probe script with the options -S 221 and -P. The tradeoff, is that a failure detection happens only after the 222 probe interval. 223 Another tradeoff is that you have to disable your resource every time you 224 want to to change an option of the start, stop and probe script. 225 Handling the resource manager project has to be done in the code of the 226 start, stop and probe script. 227 228 If you need a process based restart use the smf component. SMF offers an 229 immediate process restart and in addition online configurable properties. 230 The tradeoff is the additional complexity of the smf manifest, the benefit 231 is the additional flexibility you get with smf and the faster detection of 232 vanishing process trees. 233 234 Handeling user credentials and the resource manager project for start and 235 stop is a built in capability of smf services. The probe runs under the 236 root user, but the probe_smf_xxx script is fired under the right project. 237 238 The template delivers the xxx_smf_register script, the xxx_smf_remove and 239 the control_xxx method. 240 241 The control_xxx script is the start and stop method for all the instances 242 of your agent. You need to modify the control_xxx to extract the properties 243 you specified in the manifest. These properties needs to be used as options 244 for the start stop and probe command. 245 246 The xxx_smf_register script generates the manifest file under: 247 /local/svc/manifest/application/sczone-agents/$RS.xml and imports the 248 manifest under 249 250 svc:/application/sczone-agents:$RS 251 252 $RS is the resource name, so you will have one smf manifast/resource per 253 cluster resource. 254 255 The values for properties are sourced from the config file you need to 256 register for a resource in a global zone. These properties are stored in 257 the smf repository for the service svc:/application/sczone-agents:$RS. 258 259 To specify the properties you need to modify the property group parameters. 260 261 <property_group name='parameters' type='general'> 262 <propval name='Resource' type='astring' value='$RS'/> 263 <propval name='Resource_group' type='astring' value='$RG'/> 264 </property_group> 265 266 You can amend the manifest with all the options useful for your agent. To 267 achieve this you need to modify the SUNCscxxx/util/xxx_smf_register file. 268 269 The xxx_smf_register script can be called directly. It takes the -f option 270 for an alternate config file. 271 272 The xxx_smf_remove script removes the manifest and the smf service in the 273 specified zone. 274 275 Summary: 276 To use the zsh component, modify the local_zone function in the xxx_register 277 script and configure the start stop and probe command of your agent with 278 all the necessary options. 279 It is done via xxx_register -z zsh, it registers the smf_xxx method as the 280 start stop and probe command with the necessary options. 281 282 To use the smf component, rename and modify the xxx_smf_register and the 283 xxx_smf_remove script, then call xxx_register script with -z smf in the 284 global zone to configure the smf component in the global zone. 285 286 To remove the smf manifest and its related smf service call xxx_smf_remove 287 after the shutdown of the Sun Cluster Container smf resource. Specify the 288 -f filename option if you used an alternate config file. 289 290 A validation of your configuration can be done for a smf service with 291 control_xxx validate FMRI or with control_xxx -R resource .. validate. 292 293 All the three scripts use the xxx_config file if no -f option is specified. 294 295 296 16. Optional config file 297 the xxx_register, xxx_smf_register and xxx_smf_remove script take the -f 298 option. Use -f filename to specify an alternate config file. 299 300 17. This template is supplied as-is, if you have any comments please 301 email ha-clusters-discuss@opensolaris.org. 302