18 October 2010

Solaris Management Facility

With the advent of Solaris 10, Sun introduced a new mechanism to manage
the running of services, the services management facility (smf(5)).
This is important to note as it impacts the startup of services
traditionally handled via the various rcX.d directories.  In short, while
the rcX.d directories are still existent and may be used for "legacy"
scripts, the actual handling of the majority of the services is through
SMF.  On a default install, the scripts that do exist initially under
/etc/rcX.d typically just call out SMF commands to maintain the services.
The intention of the following discussion is to provide a base overview
of some of the various commands now available with SMF and their usage
towards service startup / shutdown management.

To view a listing services that SMF is aware of and may control, the
svcs(1) command is available:

        # svcs
        STATE          STIME    FMRI
        legacy_run     Jul_07   lrc:/etc/rcS_d/S50sk98sol
        legacy_run     Jul_07   lrc:/etc/rcS_d/S51installupdates
        legacy_run     Jul_07   lrc:/etc/rc2_d/S10lu

        online         Nov_10   svc:/network/vopied/tcp:default
        online         Nov_10   svc:/network/bpjava-msvc/tcp:default
        offline        Jul_07   svc:/application/print/ipp-listener:default
        offline        Jul_07   svc:/application/print/rfc1179:default
        maintenance    Jul_07   svc:/network/smtp:sendmail

Without any parameters, svcs displays the current state (STATE) of the
services, their start time (STIME), and the fault management resource
identifier (FMRI).  In the above output, four different states are
observed (for a full listing of those possible, see smf(5).  The state
of legacy_run represents a service that is not managed within SMF,
instead being handled directly with a standard rc script within an rcX.d
directory.  Under FMRI, the instance lrc: is shown, also indicative of
a standard rc script, followed by the rc path to the script.  It should
be noted that underscores replace periods in this output in dealing
with the rc directories, thus /etc/rcS_d is relative to /etc/rcS.d
within the filesystem.  The legacy_run state is the only state related
to traditional rc scripts.  The other states seen above are online and
offline (self explanatory) and maintenance.  A service in maintenace
state means that the service is enabled though is not able to run for
some reason.  The FMRI of SMF services should all begin svc:.

Part of the intention behind SMF is to be able to build dependencies
of X service upon the function of other services.  Also, the ability to
"recover" services without admin intervention is considered, thus if a
service dies, SMF can restart said service, providing any dependencies
that service holds are met.  To view the details of a particular service,
svcs may be used with the -l option:

        # svcs -l svc:/network/nfs/status:default
        fmri         svc:/network/nfs/status:default
        name         NFS status monitor
        enabled      true
        state        online
        next_state   none
        state_time   Fri Jul 07 19:11:57 2006
        logfile      /var/svc/log/network-nfs-status:default.log
        restarter    svc:/system/svc/restarter:default
        contract_id  37
        dependency   require_any/error svc:/milestone/network (online)
        dependency   require_all/restart svc:/network/rpc/bind (online)
        dependency   require_all/error svc:/system/filesystem/local (online)

The above output includes the restarter involved should the service
failed, the enable state, the running state, and dependency services for
this service.  The dependency services are those services the specified
service depends upon.  To simply display only those dependency services,
execute svcs with -d:

        # svcs -d svc:/network/nfs/status:default
        STATE          STIME    FMRI
        online         Jul_07   svc:/milestone/network:default
        online         Jul_07   svc:/system/filesystem/local:default
        online         Jul_07   svc:/network/rpc/bind:default

On the other side of the coin, the service in question may have services
dependent upon it.  To see these services, the -D option to svcs is
available:

        # svcs -D svc:/network/nfs/status:default
        STATE          STIME    FMRI
        online         Jul_07   svc:/network/nfs/nlockmgr:default

In the above, service nlockmgr is shown as dependent upon
svc:/network/nfs/status:default.

As it is not always identifiable what running processes are related
to a particular SMF service, svcs provides the -p option.  The output
of svcs -p will display at least the SMF service specified and any
potential processes running that are attached to that SMF service.
Of note, not all SMF services, while listed as online, will have their
own process(es) running in the process table.  This is due to a variety
of reasons, such as the SMF service is a verification of other services,
or as in the case of inetd services, inetd is running as opposed to the
SMF listed service.  The following is the output of processes related
to the svc:/network/nfs/status:default service:

        # svcs -p svc:/network/nfs/status:default
        STATE          STIME    FMRI
        online         Jul_07   svc:/network/nfs/status:default
                       Jul_07        350 statd

The third line of output lists statd preceded by 350, which is the pid
of the statd process:

        # ps -ef | grep 350
          daemon   350     1   0   Jul 07 ?           0:00 /usr/lib/nfs/statd

Now that it is understood how to gather information about an SMF service,
discussion can be geared towards the startup / shutdown of these services.
To enable a particular service, not accounting for dependencies, svcadm
may be used with the enable flag:

        # svcadm enable svc:/network/nfs/status:default

To account for dependent services, specifying -r will enable each service
and recursively start it and its dependencies:

        # svcadm enable -r svc:/network/nfs/status:default

Similarly, to disable a service, the disable keyword would instead
be used.  When either enable or disable are specified, the service in
question is either started or stopped, as appropriate.  It should be
noted, the enable and disable configurations seen above would persist
through a reboot of the host.  For a non-persistent action, -t should
be added to the command line, as so:

        # svcadm disable -t svc:/network/nfs/status:default

While there is still quite a bit more functionality available within
SMF that is not discussed here, the above should provide at least a
base knowledge for how to work with SMF.  For further information,
the following man pages will be of assistance:

        smf(5)                   svcs(1)
        svcadm(1M)               svccfg(1M)
        inetadm(1M)              inetconv(1M)