Go to main content

Developing System Services in Oracle® Solaris 11.4

Exit Print View

Updated: November 2020
 
 

Creating a Periodic Service Using the Service Bundle Generator Tool

When you use the svcbundle command to create a periodic service, you must specify the period property as well as both the service-name and start-method properties. By default, svcbundle creates a transient service. When you specify -s period, svcbundle creates a periodic service.

How to Create a Periodic Service Using svcbundle

  1. Copy the start method to the standard location.

    In this example, the start method for this service is named periodic-ex. Copy this executable to /lib/svc/method/periodic-ex.

  2. Create an initial manifest.

    In this example, the service name is site/periodic-example. Specify a period for the start method scheduling. Do not specify any of the following properties: bundle-type, duration, model, rc-script, refresh-method, or stop-method.

    $ svcbundle -o /tmp/periodic-example.xml -s service-name=site/periodic-example \
    > -s start-method=/lib/svc/method/periodic-ex -s timeout=180 \
    > -s period=3600 -s delay=15 -s jitter=5 

    When you specify the period property, svcbundle creates a periodic_method element, which causes the restarter for the service to be set to the periodic restarter when the manifest is imported. The value of the period property becomes the value of the period attribute of the periodic_method element. The value of the start-method property becomes the value of the exec attribute of the periodic_method element.

  3. Make any necessary changes to the manifest.

    The /tmp/periodic-example.xml manifest is shown in Example 4, Example Periodic Service Manifest.

    Verify that the content of the /tmp/periodic-example.xml manifest is what you need. You might want to make changes such as add a method_context element in the periodic_method element.

    Add comments and fill out template elements to describe what the service does and how the properties of the service are used.

  4. Verify that the service manifest is valid.
    $ svccfg validate /tmp/periodic-example.xml
  5. Copy the manifest to the standard directory.
    $ cp /tmp/periodic-example.xml /lib/svc/manifest/site/periodic-example.xml
  6. Import the manifest and start the service.
    $ svcadm restart manifest-import
  7. List the new service.

    Verify that the new service exists and is in the expected state.

    $ svcs periodic-example
    $ svcs -l periodic-example
    $ svcprop -p periodic periodic-example:default
Example 4  Example Periodic Service Manifest

The example in this procedure produced the following manifest:

<?xml version="1.0" ?>
<!DOCTYPE service_bundle
  SYSTEM '/usr/share/lib/xml/dtd/service_bundle.dtd.1'>
<!--
    Manifest created by svcbundle (2020-Oct-01 16:28:06-0700)
-->
<service_bundle name="site/periodic-example" type="manifest">
    <service name="site/periodic-example" version="1" type="service">
        <!--
            The following dependency keeps us from starting until the
            multi-user milestone is reached.
        -->
        <dependency name="multi_user_dependency" grouping="require_all"
            restart_on="none" type="service">
            <service_fmri value="svc:/milestone/multi-user"/>
        </dependency>
        <periodic_method delay="15" jitter="5" recover="false"
            persistent="false" timeout_seconds="180"
            exec="/lib/svc/method/periodic-ex" period="3600"/>
        <instance name="default" enabled="true"/>
        <template>
            <common_name>
                <!--
                    Replace loctext content with a short name for the
                    service.
                -->
                <loctext xml:lang="C">
                        site/periodic-example
                </loctext>
            </common_name>
            <description>
                <!--
                    Replace loctext content with a brief description of the
                    service
                -->
                <loctext xml:lang="C">
                        The site/periodic-example service.
                </loctext>
            </description>
        </template>
    </service>
</service_bundle>