... {toc}
h2. Introduction
h3. Purpose The purpose of this topic is to enable people to create and use SMF
Writing the SMF XML files and scripts. h3. Scope
h3. References
* [smf_method(5)|http://docs.sun.com/app/docs/doc/819-2252/smf-method-5?l=en&a=view] * [An SMF Manifest Cheatsheet|http://www.cuddletech.com/blog/pivot/entry.php?id=182] * [BigAdmin System Administration Portal Predictive Self-Healing|http://www.sun.com/bigadmin/content/selfheal] * [Predictive Self-Healing|http://www.sun.com/bigadmin/content/selfheal/sdev_intro.html] * /usr/share/lib/xml/dtd/service_bundle.dtd.1 * smf_method(5) * http://opensolaris.org/os/community/smf * [Creating an SMF service (Part 1)|http://blogs.sun.com/roller/page/yakshaving?entry=creating_an_smf_service_part] * [Creating an SMF service (Part 2)|http://blogs.sun.com/roller/page/yakshaving?anchor=creating_an_smf_service_part1] * [Creating an SMF service (Part 3)|http://blogs.sun.com/roller/page/yakshaving?entry=creating_an_smf_service_part2] * http://forum.sun.com/thread.jspa?forumID=241&threadID=26964 * [How to add a service to SMF|http://www.dcs.bbk.ac.uk/~gzoum01/howtos/smf.html] * [Securing MySQL using SMF - the Ultimate Manifest|http://blogs.sun.com/bobn/entry/securing_mysql_using_smf_the]
h4. smf mgmt * [Chapter 14 Managing Services (Overview)|http://docs.sun.com/app/docs/doc/817-1985/6mhm8o5rl?l=en&a=view] * [Chapter 15 Managing Services (Tasks)|http://docs.sun.com/app/docs/doc/817-1985/fddwo?l=en&a=view]
h4. scratch pad * [The Strange New World of the Solaris(TM) 10 Service Management Facility|http://samag.com/documents/s=9766/sam0506i/0506i.htm] * http://www.sun.com/software/solaris/availability.jsp * http://www.bosconet.org/pjohnson/blog/index.php/2005/09/20/solaris-10-is-so-quiet-when-it-boots/ * http://www.examcram2.com/articles/article.asp?p=440286&seqNum=14&rl=1 ** http://www.samag.com/documents/s=9766/sam0506i/0506i.htm ** [Chapter 9 Managing Services|http://docs.sun.com/app/docs/doc/817-1985/6mhm8o5n0?a=view]
h2. Procedures
h3. Adding a new SMF
# write the smf # verify the xml structure #* xmllint --valid ./tomcat.xml > /dev/null # import the smf # test the smf
h2. Directories
* */var/svc/manifest*: ** An SMF manifest is an XML file that contains a complete set of properties that are associated with a service or a service instance. ** Manifests should not be used to modify the properties of a service. The service configuration repository is the authoritative source of configuration information. ** To incorporate information from the manifest into the repository, you must either run svccfg import or allow the service to import the information during a system boot. ** See also: service_bundle(4) * */var/svc/profile*: http://docs.sun.com/app/docs/doc/819-2379/6n4m1vlbd?q=Service+Management+Facility&a=view * */etc/svc*: This is where the repositories are stored.
h2. Tools
h3. inetadm Provides the ability to observe or configure services controlled by inetd
h3. svcadm |Change milestone|svcadm milestone -d milestone/single-user:default|
h3. svccfg Provides the ability to display and manipulate the contents of the service configuration repository
svccfg -v import /var/svc/manifest/application/MyApp.xml
h3. svcprop Retrieves property values from the service configuration repository with a output format appropriate for use in shell scripts.
h3. svcs |-x| explain problems| |-xv| explain problems and show which services are dependent | |-d| Show services, this service depends on.| |-D| Show services that depends on this service.| |-p| list process related to service'|
h3. xmllint validate the xml structure.
xmllint --valid ./tomcat.xml > /dev/null
* Any errors will be listed. * exit code 0 zero when the structure is valid.
h3. boot boot -m milestone=<milestone>", to boot to the named milestone. <milestone> can be * single-user * multi-user * multi-user-server * all : the special milestones "all" (all enabled services online) * none : (no services at all). The "none" milestone can be very useful in repairing systems that have failures early in the boot process.
* *boot -m verbose*: for verbose boot.
h3. Adding new services to inetd.conf
The Internet services daemon, inetd(1M), has been rewritten as part of SMF. It stores all of its configuration data in the SMF database, rather than /etc/inet/inetd.conf, allowing the SMF tools to be used to control and observe inetd-based services. Most inetd-based services that ship with Solaris will no longer have entries in inetd.conf. To provide compatibility for services which haven't converted to SMF, entries can still be added to inetd.conf using the same syntax as always, and the new inetconv(1M) command will convert the new services to SMF services. inetconv should always be run after editing /etc/inet/inetd.conf; it can be run without any arguments.
h2. The profile XML file
h3. General * **: * **: * **:
h3. dependency
{noformat} <dependency name='multi-user' grouping='require_all' restart_on='error' type='service'> <service_fmri value='svc:/milestone/multi-user'/> </dependency> {noformat}
* *name*: Name of the dependency. ??? Can you choose this arbitrarily? Probably ** Can't contain '.' (dot/full stop char) * *grouping*: ** _exclude_all_: None of the FMRIs can be online. ** _optional_any_:All FMRIs must either be online, of failed to come online. So none of the can be starting. ** _require_all_: All FMRIs must be online. ** _require_any_: ??? If a single FMRI in this group is online, then we are good to go. * *restart_on*: The service in this profile is restarted if the dependency encounters one of the selected situations. ** _error_: restarts the service if the dependency is restarted due to a fault. ** _none_: Service will be independent of dependency actions. ** _refresh_: restart service if dependency 'refresh', 'restart' or encounters an error. ** _restart_: restarts the service if the dependency is restarted due to a fault. * *type*: ** _service_: another FMRI ** _path_: File path. *** value must start with 'file::/localhost' before the full path is written.
h4. Dependent on file {noformat} <dependency name='my_conf_fil' grouping='require_all' restart_on='none' type='path'> <service_fmri value='file://localhost/etc/my_conf.fil'/> </dependency> {noformat}
* The file is: /etc/my_conf.fil * There is no need to set restart_on to anything but 'none' SMF currently doesn't support onaything else on files.
h4. Dependent on Service
h4. Dependent on service not exist/active
h2. The scripts
* The shell script should include _/lib/svc/share/smf_include.sh_ to get access to the return vars. * call _smfPresent()_ 0 = not present, non-zero = present.
h1. Annotated Example
h2. Manifest {code:title=tomcat_smf.xml} <?xml version="1.0"?> <!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1"> <!-- Copyright 2004 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. ident "@(#)webmin.xml 1.1 04/11/11 SMI" Service manifest for the Webmin service. --> <service_bundle type='manifest' name='tomcat'> <service name='application/servers/tomcat' type='service' version='1'> <create_default_instance enabled='true' /> <single_instance/> <dependency name='filesystem' grouping='require_all' restart_on='none' type='service'> <service_fmri value='svc:/system/filesystem/local' /> </dependency> <dependency name='network' grouping='require_all' restart_on='none' type='service'> <service_fmri value='svc:/network/initial' /> </dependency> <dependency name='server_xml' grouping='require_all' restart_on='none' type='path'> <service_fmri value='file://localhost//opt/apache-tomcat-6.0.18/conf/server.xml'/> </dependency> <exec_method type='method' name='start' exec='/opt/apache-tomcat-6.0.18/bin/startup.sh' timeout_seconds='30' > <method_context> <method_credential user='tcat' group='bin' /> </method_context> </exec_method>
<exec_method type='method' name='stop' exec='/opt/apache-tomcat-6.0.18/bin/shutdown.sh' timeout_seconds='60' /> <stability value='Unstable' /> <template> <common_name> <loctext xml:lang='C'> Tomcat </loctext> </common_name> <!-- <documentation> <manpage title='webmin' section='1M' manpath='/usr/sfw/man' /> </documentation> --> </template> </service> </service_bundle> {code}
h3. XML lead-in {code} <?xml version="1.0"?> <!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1"> {code}
h3. Service_bundle {code} <service_bundle type='manifest' name='tomcat'> </service_bundle> {code}
h3. service {code} <service name='application/servers/tomcat' type='service' version='1'> </service> {code}
h3. Default creation enabled/disabled {code} <create_default_instance enabled='true' /> {code} Set to 'false' to ensure the service doesn't start until explicitly enabled.
h3. Instances single/multiple {code} <single_instance/> {code}
h3. Start command {code} <exec_method type='method' name='start' exec='/opt/apache-tomcat-6.0.18/bin/startup.sh' timeout_seconds='30' > <method_context> <method_credential user='tcat' group='bin' /> </method_context> </exec_method> {code}
h3. Stop command
h4. Stop script {code} <exec_method type='method' name='stop' exec='/opt/apache-tomcat-6.0.18/bin/shutdown.sh' timeout_seconds='60' /> {code}
h4. kill command {code} <exec_method type='method' name='stop' exec=':kill' timeout_seconds='60' />
{code}
h3. Stability of Manifest {code} <stability value='Unstable' /> {code}
h3. man page references etc. {code} <template> <common_name> <loctext xml:lang='C'> Tomcat </loctext> </common_name> <!-- <documentation> <manpage title='webmin' section='1M' manpath='/usr/sfw/man' /> </documentation> --> </template> {code}
h2. Start script {code} . /lib/svc/share/smf_include.sh /usr/local/bin/runme& {code}
h1. Trouble shooting
h2. Starting
h3. svc.startd could not set context for method: chdir: No such file or directory
* You are missing the home dir for the user you have set-up in the manifest. * Create the home dir and the 'svcadm clear' should take care of it.
{noformat} [ Apr 3 08:22:55 Executing start method ("/opt/apache-tomcat-6.0.18/bin/startup.sh") ] svc.startd could not set context for method: chdir: No such file or directory [ Apr 3 08:22:55 Method "start" exited with status 96 ] {noformat}
See also: Securing MySQL using SMF - the Ultimate Manifest
h2. Implementing the SMF XML
h3. svccfg: Multiple definitions for property type in property group network.
* Dependency name was used twice ** [General Solaris 10 Discussion - svccfg: Multiple definitions for property type in property group stop.|http://forums.sun.com/thread.jspa?threadID=5148273&tstart=4125]
{noformat} # svccfg -v import ./tomcat.xml svccfg: Multiple definitions for property type in property group network. {noformat}
{noformat}
<dependency name='network' grouping='require_all' restart_on='none' type='service'> <service_fmri value='svc:/network/initial' /> </dependency>
<dependency name='network' grouping='exclude_all' restart_on='none' type='service'> <service_fmri value='svc:/application/management/sma' /> </dependency> {noformat}
h3. Could not interpret user property
* svcsprop tomcat |