Copyright 2017 RackTop Systems.
Copyright 2019 OmniOS Community Edition (OmniOSce) Association.
Copyright (c) 2009, Sun Microsystems, Inc. All Rights Reserved.
The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.
See the License for the specific language governing permissions and limitations under the License. When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with
the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
/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(8) 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.
The service fault management resource identifier (FMRI) of the instance for which the method is invoked.
The full name of the method being invoked, such as start or stop.
The service FMRI of the restarter that invokes the method
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.
These properties are: exec (astring)
Method executable string.
Number of seconds before method times out. See the Timeouts section for more detail.
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.
%
Name of the restarter, such as svc.startd
The full name of the method being invoked, such as start or stop.
Name of the service
Name of the instance
FMRI of the instance
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.
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.
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_NODAEMON 94 |
Method exited successfully but purposefully leaves no processes remaining in |
the contract; it should be treated as if it had a transient service model. |
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_MON_DEGRADE 97 |
Method encountered some problems. The service may not be fully functional. |
SMF_EXIT_ERR_NOSMF 99 |
Method has been mistakenly invoked outside the smf(7) facility. Services that depend on smf(7) 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. |
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.
If you specify 0 timeout_seconds for a method, it declares to the restarter that there is no timeout for the service. This setting is not preferred, but is available for services that absolutely require it.
-1 timeout_seconds is also accepted, but is a deprecated specification.
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(7) 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.
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 variables to insert into the environment of the method, in the form of a number of NAME=value strings.
The name of an RBAC (role-based access control) profile which, along with the method executable, identifies an entry in exec_attr(5).
The user ID in numeric or text form.
The group ID in numeric or text form.
An optional string that specifies the supplemental group memberships by ID, in numeric or text form.
An optional string specifying the privilege set as defined in privileges(7).
An optional string specifying the limit privilege set as defined in privileges(7).
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.
The security flags to apply when launching the method. See security-flags(7).
The "default" keyword specifies those flags specified in svc:/system/process-security. The "all" keyword enables all flags, the "none" keyword enables no flags. The "current" keyword specifies the current flags. Flags may be added by specifying their name (optionally preceded by '+'), and removed by preceding their name with '-').
Use of "all" has associated risks, as future versions of the system may include further flags which may harm poorly implemented software.
An optional string that specifies the corefile pattern to use for the service, as per coreadm(8). Most restarters supply a default. Setting this property overrides local customizations to the global core pattern.
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.
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(5) 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
File descriptorsFile descriptor 0 is /dev/null. File descriptors 1 and 2 are recommended to be a per-service log file.
Definitions of exit status values.
Definitions of exit status codes.
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.