SMF Short Cuts

by Henry Pepper

Introduction

Purpose

The purpose of this topic is to enable people to create and use SMF

Writing the SMF XML files and scripts.

Scope

References

smf mgmt

scratch pad

Procedures

Adding a new SMF

  1. write the smf
  2. verify the xml structure
    • xmllint --valid ./tomcat.xml > /dev/null
  3. import the smf
  4. test the smf

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.

Tools

inetadm

Provides the ability to observe or configure services controlled by inetd

svcadm

Change milestone svcadm milestone -d milestone/single-user:default

svccfg

Provides the ability to display and manipulate the contents of the service configuration repository

svccfg -v import /var/svc/manifest/application/MyApp.xml

svcprop

Retrieves property values from the service configuration repository with a output format appropriate for use in shell scripts.

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'

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.

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.

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.

The profile XML file

General

  • **:
  • **:
  • **:

dependency

    <dependency name='multi-user'
                    grouping='require_all'
                    restart_on='error'
                    type='service'>
                        <service_fmri value='svc:/milestone/multi-user'/>
                </dependency>
  • 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.

Dependent on file

    <dependency name='my_conf_fil'
                    grouping='require_all'
                    restart_on='none'
                    type='path'>
                        <service_fmri value='file://localhost/etc/my_conf.fil'/>
                </dependency>
  • 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.

Dependent on Service

Dependent on service not exist/active

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.

Annotated Example

Manifest

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>

XML lead-in

<?xml version="1.0"?>
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">

Service_bundle

<service_bundle type='manifest' name='tomcat'>
</service_bundle>

service

  <service name='application/servers/tomcat' type='service' version='1'>
  </service>

Default creation enabled/disabled

      <create_default_instance enabled='true' />

Set to 'false' to ensure the service doesn't start until explicitly enabled.

Instances single/multiple

      <single_instance/>

Start command

      <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>

Stop command

Stop script

      <exec_method 
         type='method'
         name='stop'
         exec='/opt/apache-tomcat-6.0.18/bin/shutdown.sh' 
         timeout_seconds='60' />

kill command

      <exec_method
        type='method'
        name='stop'
        exec=':kill'
        timeout_seconds='60' />

Stability of Manifest

      <stability value='Unstable' /> 

man page references etc.

      <template>
        <common_name>
          <loctext xml:lang='C'> Tomcat </loctext>
        </common_name>
        <!-- <documentation>  
               <manpage title='webmin' section='1M' manpath='/usr/sfw/man' />  
             </documentation> -->
      </template>

Start script

. /lib/svc/share/smf_include.sh
/usr/local/bin/runme&

Trouble shooting

Starting

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.
[ 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 ]

See also: Securing MySQL using SMF - the Ultimate Manifest

Implementing the SMF XML

svccfg: Multiple definitions for property type in property group network.

# svccfg -v import ./tomcat.xml
svccfg: Multiple definitions for property type in property group network.
      <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>

Could not interpret user property

Earn BigAdmin Bucks!

Earn BigAdmin Bucks!

Earn BigAdmin Bucks for Your Content

After you have added new content to the BigAdmin Wiki, go to BigAdmin and submit a link to your content.

This makes sure your content is included in the BigAdmin feeds as well as credits you with BigAdmin Bucks so you can earn some swag!
Look below for the recent BigAdmin Buck entries.

Labels

smf smf Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.

Sign up or Log in to add a comment or watch this page.


The individuals who post here are part of the extended Sun Microsystems community and they might not be employed or in any way formally affiliated with Sun Microsystems. The opinions expressed here are their own, are not necessarily reviewed in advance by anyone but the individual authors, and neither Sun nor any other party necessarily agrees with them.

Copyright 1994-2009 Sun Microsystems, Inc.
Powered by Atlassian Confluence
Sun Guidelines on Public Discourse Privacy Policy Terms of Use Trademarks Site Map Employment Investor Relations Contact