Go to main content

Developing System Services in Oracle® Solaris 11.3

Exit Print View

Updated: September 2018
 
 

Creating an SMF Service Using the Service Bundle Generator Tool

You can use the svcbundle service bundle generator tool to create a simple service or to start a more complex service. For more information, see the svcbundle(1M) man page. You can use the service bundle DTD and other service manifests to complete a more complex service.

How to Create an SMF Service Using svcbundle


Note -  Do not use this procedure if you are creating a periodic service. See How to Create a Periodic Service Using svcbundle.
  1. Determine the service model.

    By default, svcbundle creates a transient service. Determine whether the start method script for this service starts any long-running daemon and therefore this service is a contract service. See Service Models in Managing System Services in Oracle Solaris 11.3, the model property in the svcbundle(1M) man page, and the startd/duration property in the svc.startd(1M) man page for information about service models.

  2. Copy the script to the standard location.

    The service in this example uses a custom script named ex_svc as the start method. Copy this script to /lib/svc/method/ex_svc.

  3. Create an initial manifest.

    In this example, the service name is site/ex_svc. This service is a transient service and does not need a stop method.

    $ svcbundle -o /tmp/ex_svc.xml -s service-name=site/ex_svc \
    -s start-method=/lib/svc/method/ex_svc

    If this service were a contract service, you would specify contract or daemon as the value of the model or duration property, as in -s model=contract.

  4. Make any necessary changes to the manifest.

    Verify that the content of the /tmp/ex_svc.xml manifest is what you need. You might need to add a dependency or adjust the method timeout, for example. Add comments to describe what the service does and how the properties of the service are used.

  5. Verify that the manifest is valid.

    Use the svccfg validate command to ensure the service manifest is valid.

    $ svccfg validate /tmp/ex_svc.xml
  6. Copy the manifest to the standard directory.
    $ cp /tmp/ex_svc.xml /lib/svc/manifest/site/ex_svc.xml
  7. Import the manifest and start the service.
    $ svcadm restart manifest-import
  8. List the new service.

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

    $ svcs ex-svc
Example 1  Automatically Installing a Generated Manifest

If you do not need to make any changes to the new service manifest, you can use the -i option to install the manifest as soon as it is created. The svcbundle command will write the manifest to /lib/svc/manifest/site and restart the manifest-import service. Any existing file with the same name in the /lib/svc/manifest/site directory will be overwritten.

$ svcbundle -i -s service-name=site/ex_svc \
-s start-method=/lib/svc/method/ex_svc