Go to main content

Developing System Services in Oracle® Solaris 11.4

Exit Print View

Updated: November 2020
 
 

Service Development Best Practices

Follow the guidelines described in this section as you develop your service.

Service Method Best Practices

Follow the guidelines described in this section as you develop your service start method or other service methods.

Use SMF Method Exit and Useful Exit Reason

Services are expected to return a successful status when they have completed initialization and are ready to provide the service.

To exit your start method, use smf_method_exit(); do not use exit(). The smf_method_exit() interface requires the following arguments:

  • One of the method exit codes defined in /lib/svc/share/smf_exit_codes.sh or in the smf_method(7) man page

  • A short explanation of the reason for exiting

  • A longer explanation of the reason for exiting

Make sure that error messages are informative, including guidance for resolving the problem. You might need to capture messages or other information from commands called by your method. If your method is an existing executable, you might want to call that executable inside a method script to improve the exit messaging. The system administrator will see these messages in the service log file.

See the smf_method_exit(3SCF) man page for more information.

Use Dependencies, Avoid Using Timeouts

Do not exit your start method until initialization of the service is complete. If you exit your start method before service initialization is complete, services that depend on this service cannot be started.

Set appropriate values for timeout_seconds properties to avoid failing solely because more time is needed to complete the method tasks.

Do not use timeout_seconds values or any other kind of timeout or wait to allow enough time for dependencies to reach the online state. Instead, declare dependencies appropriately. In addition to allowing enough time for dependencies to start, if a service on which this service has a require dependency fails, then this service should fail with appropriate messages and not continue to wait for the failed dependency to start. Again, appropriately declared dependency elements are the correct implementation. See Showing Service Dependencies in Managing System Services in Oracle Solaris 11.4 and the "Dependencies" section of the smf(7) man page.

Provide Documentation

Provide appropriate template information as described in the smf_template(7) man page. Administrators can use the svccfg describe command to view this information.

  • Provide a short common name for the service as described in "Service and Instance Common Names" in the smf_template(7) man page.

  • Reference appropriate man pages (manpage element) or stable URLs (doc_link element) for more information.

  • Provide names, descriptions, choices, and constraints for property groups and properties that are specific to this service.

Validate the Service Manifest

Use the svccfg validate command to validate your service manifest.

If the svccfg validate command fails with the error "Required property group missing," you might be attempting to validate a partial manifest. Specification of a single service can be spread across multiple manifests. To avoid this error, make sure all manifests for a multiple-manifest service specify the include property in the service_bundle element as described in Creating a Service Using Multiple Manifests.

Use Standard Locations

Copy your service manifests and profiles to standard locations with standard ownership and permissions. Do not use non-standard locations for manifest and profile files. See Service Bundles in Managing System Services in Oracle Solaris 11.4 or Figure 1, Table 1, Standard Locations of Service Development Files for manifest and profile standard locations.

When you create a service for your own use, use site at the beginning of the service name (svc:/site/service-name:instance-name), and place the manifest in /lib/svc/manifest/site.

To test your service, place the manifest and any associated profiles in the correct standard locations and restart the manifest-import service. See Chapter 5, Configuring Multiple Systems in Managing System Services in Oracle Solaris 11.4 and Repairing an Instance That Is Degraded, Offline, or in Maintenance in Managing System Services in Oracle Solaris 11.4 for related information.