JavaScript is required to for searching.
Skip Navigation Links
Exit Print View
man pages section 5: Standards, Environments, and Macros     Oracle Solaris 11.1 Information Library
search filter icon
search icon

Document Information

Preface

Introduction

Standards, Environments, and Macros

acl(5)

ad(5)

advance(5)

adv_cap_1000fdx(5)

adv_cap_1000hdx(5)

adv_cap_100fdx(5)

adv_cap_100hdx(5)

adv_cap_10fdx(5)

adv_cap_10hdx(5)

adv_cap_asym_pause(5)

adv_cap_autoneg(5)

adv_cap_pause(5)

adv_rem_fault(5)

ANSI(5)

architecture(5)

ars(5)

ascii(5)

attributes(5)

audit_binfile(5)

audit_flags(5)

audit_remote(5)

audit_syslog(5)

availability(5)

brands(5)

C++(5)

C(5)

cancellation(5)

cap_1000fdx(5)

cap_1000hdx(5)

cap_100fdx(5)

cap_100hdx(5)

cap_10fdx(5)

cap_10hdx(5)

cap_asym_pause(5)

cap_autoneg(5)

cap_pause(5)

cap_rem_fault(5)

charmap(5)

compile(5)

condition(5)

crypt_bsdbf(5)

crypt_bsdmd5(5)

crypt_sha256(5)

crypt_sha512(5)

crypt_sunmd5(5)

crypt_unix(5)

CSI(5)

datasets(5)

device_clean(5)

dhcp(5)

dhcp_modules(5)

environ(5)

eqnchar(5)

extendedFILE(5)

extensions(5)

fedfs(5)

filesystem(5)

fmri(5)

fnmatch(5)

formats(5)

fsattr(5)

grub(5)

gss_auth_rules(5)

hal(5)

iconv_1250(5)

iconv_1251(5)

iconv(5)

iconv_646(5)

iconv_852(5)

iconv_8859-1(5)

iconv_8859-2(5)

iconv_8859-5(5)

iconv_dhn(5)

iconv_koi8-r(5)

iconv_mac_cyr(5)

iconv_maz(5)

iconv_pc_cyr(5)

iconv_unicode(5)

ieee802.11(5)

ieee802.3(5)

ipfilter(5)

ipkg(5)

isalist(5)

ISO(5)

kerberos(5)

krb5_auth_rules(5)

krb5envvar(5)

KSSL(5)

kssl(5)

labels(5)

largefile(5)

ldap(5)

lf64(5)

lfcompile(5)

lfcompile64(5)

link_duplex(5)

link_rx_pause(5)

link_tx_pause(5)

link_up(5)

locale(5)

locale_alias(5)

lp_cap_1000fdx(5)

lp_cap_1000hdx(5)

lp_cap_100fdx(5)

lp_cap_100hdx(5)

lp_cap_10fdx(5)

lp_cap_10hdx(5)

lp_cap_asym_pause(5)

lp_cap_autoneg(5)

lp_cap_pause(5)

lp_rem_fault(5)

man(5)

mansun(5)

me(5)

mech_spnego(5)

mm(5)

ms(5)

MT-Level(5)

mutex(5)

MWAC(5)

mwac(5)

nfssec(5)

NIS+(5)

NIS(5)

nis(5)

nwam(5)

openssl(5)

pam_allow(5)

pam_authtok_check(5)

pam_authtok_get(5)

pam_authtok_store(5)

pam_deny(5)

pam_dhkeys(5)

pam_dial_auth(5)

pam_krb5(5)

pam_krb5_migrate(5)

pam_ldap(5)

pam_list(5)

pam_passwd_auth(5)

pam_pkcs11(5)

pam_rhosts_auth(5)

pam_roles(5)

pam_sample(5)

pam_smbfs_login(5)

pam_smb_passwd(5)

pam_tsol_account(5)

pam_tty_tickets(5)

pam_unix_account(5)

pam_unix_auth(5)

pam_unix_cred(5)

pam_unix_session(5)

pam_user_policy(5)

pam_zfs_key(5)

pkcs11_kernel(5)

pkcs11_kms(5)

pkcs11_softtoken(5)

pkcs11_tpm(5)

pkg(5)

POSIX.1(5)

POSIX.2(5)

POSIX(5)

privileges(5)

prof(5)

pthreads(5)

RBAC(5)

rbac(5)

regex(5)

regexp(5)

resource_controls(5)

sgml(5)

smf(5)

smf_bootstrap(5)

smf_method(5)

smf_restarter(5)

smf_security(5)

smf_template(5)

solaris10(5)

solaris(5)

solbook(5)

stability(5)

standard(5)

standards(5)

step(5)

sticky(5)

suri(5)

SUS(5)

SUSv2(5)

SUSv3(5)

SVID3(5)

SVID(5)

tecla(5)

teclarc(5)

term(5)

threads(5)

trusted_extensions(5)

vgrindefs(5)

wbem(5)

xcvr_addr(5)

xcvr_id(5)

xcvr_inuse(5)

XNS4(5)

XNS(5)

XNS5(5)

XPG3(5)

XPG4(5)

XPG4v2(5)

XPG(5)

zones(5)

smf_method

- service management framework conventions for methods

Description

The class of services managed by svc.startd(1M) in the service management framework, smf(5), consists of applications that fit a simple fork(2)-exec(2) model. The svc.startd(1M) master daemon and other restarters support the fork(2)-exec(2) model, potentially with additional capabilities. The svc.startd(1M) daemon and other restarters require that the methods which activate, manipulate, or examine a service instance follow the conventions described in this manual page.

Invocation form

The form of a method invocation is not dictated by convention. In some cases, a method invocation might consist of the direct invocation of the daemon or other binary executable that provides the service. For cases in which an executable script or other mediating executable is used, the convention recommends the form:

/path/to/method_executable abbr_method_name

The abbr_method_name used for the recommended form is a supported method such as start or stop. The set of methods supported by a restarter is given on the related restarter page. The svc.startd(1M) daemon supports start, stop, and refresh methods.

A restarter might define other kinds of methods beyond those referenced in this page. The conventions surrounding such extensions are defined by the restarter and might not be identical to those given here.

Environment Variables

The restarter provides four environment variables to the method that determine the context in which the method is invoked.

SMF_FMRI

The service fault management resource identifier (FMRI) of the instance for which the method is invoked.

SMF_METHOD

The full name of the method being invoked, such as start or stop.

SMF_RESTARTER

The service FMRI of the restarter that invokes the method

SMF_ZONENAME

The name of the zone in which the method is running. This can also be obtained by using the zonename(1) command.

These variables should be removed from the environment prior to the invocation of any persistent process by the method. A convenience shell function, smf_clear_env, is given for service authors who use Bourne-compatible shell scripting to compose service methods in the include file described below.

The method context can cause other environment variables to be set as described below.

Method Definition

A method is defined minimally by three properties in a propertygroup of type method.

These properties are:

exec (astring)

Method executable string.

timeout_seconds (count)

Number of seconds before method times out. See the Timeouts section for more detail.

type (astring)

Method type. Currently always set to method.

A Method Context can be defined to further refine the execution environment of the method. See the Method Context section for more information.

Method Tokens

When defined in the exec string of the method by the restarter svc.startd, a set of tokens are parsed and expanded with appropriate value. Other restarters might not support method tokens. The delegated restarter for inet services, inetd(1M), does not support the following method expansions.

%%

%

%r

Name of the restarter, such as svc.startd

%m

The full name of the method being invoked, such as start or stop.

%s

Name of the service

%i

Name of the instance

%f

FMRI of the instance

%{prop[:,]}

Value(s) of a property. The prop might be a property FMRI, a property group name and a property name separated by a /, or a property name in the application property group. These values can be followed by a , (comma) or : (colon). If present, the separators are used to separate multiple values. If absent, a space is used. The following shell metacharacters encountered in string values are quoted with a \ (backslash):

; & ( ) | ^ < > newline space tab  \  " '

An invalid expansion constitutes method failure.

Two explicit tokens can be used in the place of method commands.

:kill [-signal]

Sends the specified signal, which is SIGTERM by default, to all processes in the primary instance contract. Always returns SMF_EXIT_OK. This token should be used to replace common pkill invocations.

:true

Always returns SMF_EXIT_OK. This token should be used for methods that are required by the restarter but which are unnecessary for the particular service implementation.

Exiting and Exit Status

The required behavior of a start method is to delay exiting until the service instance is ready to answer requests or is otherwise functional.

The following exit status codes are defined in <libscf.h> and in the shell support file.

SMF_EXIT_OK
0
Method exited, performing its operation successfully.
SMF_EXIT_ERR_FATAL
95
Method failed fatally and is unrecoverable without administrative intervention.
SMF_EXIT_ERR_CONFIG
96
Unrecoverable configuration error. A common condition that returns this exit status is the absence of required configuration files for an enabled service instance.
SMF_EXIT_ERR_NOSMF
99
Method has been mistakenly invoked outside the smf(5) facility. Services that depend on smf(5) capabilities should exit with this status value.
SMF_EXIT_ERR_PERM
100
Method requires a form of permission such as file access, privilege, authorization, or other credential that is not available when invoked.
SMF_EXIT_ERR_OTHER
non-zero
Any non-zero exit status from a method is treated as an unknown error. A series of unknown errors can be diagnosed as a fault by the restarter or on behalf of the restarter.

In addition to the exit codes described above, a method may use the following exit codes in conjunction with smf_method_exit(), available via smf_method_exit(3SCF) and smf_include.sh:

SMF_EXIT_TEMP_DISABLE
101
Method exits successfully and requests a temporary disable.
SMF_EXIT_TEMP_TRANSIENT
105
Method exits successfully and requests that it be treated as if its service model was “transient”.

Use of a precise exit code allows the responsible restarter to categorize an error response as likely to be intermittent and worth pursuing restart or permanent and request administrative intervention.

Timeouts

Each method can have an independent timeout, specified in seconds. The method timeout is specified by the timeout_seconds property.

A timeout is used as a last resort for the service's restarter to determine that a method has hung or is not making progress. If a timeout elapsed, many restarters place the service into the maintenance state. See svc.startd(1M). A significant margin of error is recommended when specifying a timeout in order to avoid premature failures when the method is making progress, but the system is temporarily responding very slowly due to memory, CPU, or I/O load.

60 seconds is a good starting value for methods expected to take only a second or two. 300 seconds (5 minutes) is appropriate for a method which commonly takes 30 seconds. Scale up as appropriate for methods which routinely take longer.

Shorter timeouts can be used if fast failure is desired in order to prompt administrative intervention. If administrative intervention is likely to only be to clear the service and start the method again, consider a longer timeout.

If timeout_seconds is set to 0, there is no timeout for the service. This setting is not preferred, but is available for services which absolutely require it. -1 is also accepted to specify no timeout, but is deprecated.

Shell Programming Support

A set of environment variables that define the above exit status values is provided with convenience shell functions in the file /lib/svc/share/smf_include.sh. This file is a Bourne shell script suitable for inclusion via the source operator in any Bourne-compatible shell.

To assist in the composition of scripts that can serve as SMF methods as well as /etc/init.d scripts, the smf_present() shell function is provided. If the smf(5) facility is not available, smf_present() returns a non-zero exit status.

One possible structure for such a script follows:

if smf_present; then
      # Shell code to run application as managed service
      ....

      smf_clear_env
else
      # Shell code to run application as /etc/init.d script
      ....
fi

This example shows the use of both convenience functions that are provided.

Method Context

The service management facility offers a common mechanism to set the context in which the fork(2)-exec(2) model services execute.

The desired method context should be provided by the service developer. All service instances should run with the lowest level of privileges possible to limit potential security compromises.

A method context can contain the following properties:

use_profile

A boolean that specifies whether the profile should be used instead of the user, group, privileges, and limit_privileges properties.

environment

Environment variables to insert into the environment of the method, in the form of a number of NAME=value strings.

profile

The name of an RBAC (role-based access control) profile which, along with the method executable, identifies an entry in exec_attr(4).

user

The user ID in numeric or text form.

group

The group ID in numeric or text form.

supp_groups

An optional string that specifies the supplemental group memberships by ID, in numeric or text form.

privileges

An optional string specifying the privilege set as defined in privileges(5). An Extended Policy can be specified here.

limit_privileges

An optional string specifying the limit privilege set as defined in privileges(5).

working_directory

The home directory from which to launch the method. :home can be used as a token to indicate the home directory of the user whose uid is used to launch the method. If the property is unset, :home is used.

corefile_pattern

An optional string that specifies the corefile pattern to use for the service, as per coreadm(1M). Most restarters supply a default. Setting this property overrides local customizations to the global core pattern.

project

The project ID in numeric or text form. :default can be used as a token to indicate a project identified by getdefaultproj(3PROJECT) for the user whose uid is used to launch the method.

resource_pool

The resource pool name on which to launch the method. :default can be used as a token to indicate the pool specified in the project(4) entry given in the project attribute above.

The method context can be set for the entire service instance by specifying a method_context property group for the service or instance. A method might override the instance method context by providing the method context properties on the method property group.

Invalid method context settings always lead to failure of the method, with the exception of invalid environment variables that issue warnings.

In addition to the context defined above, many fork(2)-exec(2) model restarters also use the following conventions when invoking executables as methods:

Argument array

The arguments in argv[] are set consistently with the result of /bin/sh -c of the exec string.

File descriptors

File descriptor 0 is /dev/null. File descriptors 1 and 2 are recommended to be a per-service log file.

Files

/lib/svc/share/smf_include.sh

Definitions of exit status values.

/usr/include/libscf.h

Definitions of exit status codes.

Examples

Example 1 Report a service-specific configuration error message in the service log.

A start method might want to use smf_method_exit() to report a service-specific configuration error message in the service log.

if [ ! -s "$my_config_file" ]; then
   smf_method_exit $SMF_EXIT_ERR_CONFIG \
       missing_or_empty_config_file \
       "$my_config_file is missing or empty"
fi

Example 2 Disable a service that should only run in the global zone when started in a non-global zone.

A service that should only run in the global zone might want to disable itself when started in a non-global zone.

if smf_is_nonglobalzone; then
    smf_method_exit $SMF_EXIT_TEMP_DISABLE global_zone_only \
    "$SMF_FMRI is not supported in a local zone" SUNW_OST_OSCMD
fi

See Also

zonename(1), coreadm(1M), inetd(1M), svccfg(1M), svc.startd(1M), exec(2), fork(2), getdefaultproj(3PROJECT), smf_method_exit(3SCF), exec_attr(4), project(4), service_bundle(4), attributes(5), privileges(5), rbac(5), smf(5), smf_bootstrap(5), zones(5)

Notes

The present version of smf(5) does not support multiple repositories.

When a service is configured to be started as root but with privileges different from limit_privileges, the resulting process is privilege aware. This can be surprising to developers who expect seteuid(<non-zero UID>) to reduce privileges to basic or less.