Solaris Features: Service Management Facility - Part 3: Working with SMF

After so much theory SMF may look a little bit complex but it isn´t. For the admin it´s really simple. You can control the complete startup of the system with just a few commands.

What´s running on the system

At first let´s have a look on all services running on the system:

# svcs
legacy_run     10:04:44 lrc:/etc/rc3_d/S84appserv
disabled       10:04:22 svc:/system/xvm/domains:default
online         10:03:48 svc:/system/svc/restarter:default
offline        10:03:54 svc:/network/smb/server:default

This is only a short snippet of the configuration. The output of this command is 105 lines long on my system. But you services in several service states in it. For example i hadn´t enabled xvm on my system (makes no sense, as this Solaris is already virtualized, and the smb server is still online. Let´s look after a certain service

 #  svcs name-service-cache
STATE          STIME    FMRI
online         10:08:01 svc:/system/name-service-cache:default

The output is seperated into three columns. The first shows the service state, the second the time of the last start of the service. The last one shows the exact name of the service.

Starting and stoping a service

Okay, but how do i start the service, how do i use all this stuff:let´s assume, you want to disable sendmail. At first we check the current state:

# svcs sendmail
STATE          STIME    FMRI
online         10:23:19 svc:/network/smtp:sendmail

Now we disable the service. It´s really straight forward:

# svcadm disable sendmail

Let´s check the state again.

# svcs sendmail
STATE          STIME    FMRI
disabled       10:23:58 svc:/network/smtp:sendmail

Okay, a few days later we realize that we need the sendmail service on the system. No problem we enable it again:

# svcadm enable  sendmail
# svcs sendmail
STATE          STIME    FMRI
online         10:25:30 svc:/network/smtp:sendmail

The service runs again. Okay, we want to restart the service. This is quite simple, too

# svcadm restart sendmail
# svcs sendmail
STATE          STIME    FMRI
online*        10:25:55 svc:/network/smtp:sendmail
# svcs sendmail
STATE          STIME    FMRI
online         10:26:04 svc:/network/smtp:sendmail

Did you notice the change in the STIME column. The service has restarted. By the way: STIME doesn´t stand for “start time”. It´s a short form for “State Time”. It shows, when the actual state of the services was entered. Okay, now let´s do some damage to the system. We move the config file for sendmail, the glorious sendmail.cf. The source of many major depressions under sys admins.

# mv /etc/mail/sendmail.cf /etc/mail/sendmail.cf.old
# svcadm restart sendmail
# svcs sendmail
STATE          STIME    FMRI
offline        10:27:09 svc:/network/smtp:sendmail

Okay, the service went in the offline state. Offline? At first, the maintainance state would look more sensible. But let´s have a look in some diagnostic informations. With svcs -x you can print out fault messages regaring services.

# svcs -x
svc:/network/smtp:sendmail (sendmail SMTP mail transfer agent)
 State: offline since Sun Feb 24 10:27:09 2008
Reason: Dependency file://localhost/etc/mail/sendmail.cf is absent.
   See: http://sun.com/msg/SMF-8000-E2
   See: sendmail(1M)
   See: /var/svc/log/network-smtp:sendmail.log
Impact: This service is not running.

The SMF didn´t even try to start the service. There is an dependency implicit to the service.

# svcprop sendmail
config/value_authorization astring solaris.smf.value.sendmail
config/local_only boolean true
config-file/entities fmri file://localhost/etc/mail/sendmail.cf
config-file/grouping astring require_all
config-file/restart_on astring refresh
config-file/type astring path
[..]</blockquote></code>
The service configuration for sendmail defines a dependency to the config-file /etc/mail/sendmail.cf. Do you remember the definition of the service states? A service stays in offline mode until all dependencies are fullfilled. We renamed the file, the dependencies isn´t fullfilled. The restart leads correctly to the "offline state"

Okay, we repair the damage:
<!-- Migration Rule 7 --> 

<figure class="highlight"><pre><code class="language-plaintext" data-lang="plaintext"># mv /etc/mail/sendmail.cf.old /etc/mail/sendmail.cf</code></pre></figure>


And now we restart the service

<!-- Migration Rule 8 --> 

<figure class="highlight"><pre><code class="language-plaintext" data-lang="plaintext"># svcadm refresh sendmail
# svcs sendmail
STATE          STIME    FMRI
online         10:33:54 svc:/network/smtp:sendmail</code></pre></figure>


All is well, the service in online again
<h3>Automatic restarting of a service</h3>
Okay, let´s test another capability of the SMF. The kill the sendmail daemon.

<!-- Migration Rule 8 --> 

<figure class="highlight"><pre><code class="language-plaintext" data-lang="plaintext"># svcs sendmail
STATE          STIME    FMRI
online         10:33:54 svc:/network/smtp:sendmail
# pkill "sendmail"
# svcs sendmail
STATE          STIME    FMRI
online         10:38:24 svc:/network/smtp:sendmail</code></pre></figure>


The SMF restarted the daemon automatically as you can see from the stime-column
<h3>Obtaining the configuration of a service</h3>
Okay, as i wrote before every service has some configuration in the SMF Service Configuration Repository. You can dump this configuration with the <code>svcprop</code> command. Let´s print out the configuration for the name service cache:<br />
<blockquote>
<pre><code># svcprop svc:/system/name-service-cache:default
general/enabled boolean false
general/action_authorization astring solaris.smf.manage.name-service-cache
[..]
restarter/state astring online
restarter/state_timestamp time 1203844081.231748000
general_ovr/enabled boolean true

Dependencies

But how do i find out the dependencies between services. The svcadm commands comes to help: The -d switch shows you all services, on which the service depends. In this example we check this for the ssh daemon.

# svcs -d ssh
STATE          STIME    FMRI
disabled        8:58:07 svc:/network/physical:nwam
online          8:58:14 svc:/network/loopback:default
online          8:58:25 svc:/network/physical:default
online          8:59:32 svc:/system/cryptosvc:default
online          8:59:55 svc:/system/filesystem/local:default
online          9:00:12 svc:/system/utmp:default
online          9:00:12 svc:/system/filesystem/autofs:default

To check, what services depend on ssh, you can use the -D switch:

# svcs -D ssh
STATE          STIME    FMRI
online          9:00:22 svc:/milestone/multi-user-server:default

There is no further service depending on ssh. But the milestone multi-user-server depends on ssh. As long the ssh couldn´t started successfully, the multi-user-server milestone can´t be reached.