oreilly.comSafari Books Online.Conferences.


Using Solaris SMF
Pages: 1, 2, 3, 4

Administering SMF

The two most common commands used to administer services are svcs and svcadm. The svcs command reports on the state of configured services, while the svcadm command controls the services.

$ svcs
STATE          STIME    FMRI
legacy_run     Sep_22   lrc:/etc/rc2_d/S99audit
online         Sep_22   svc:/system/svc/restarter:default
online         Sep_22   svc:/system/filesystem/autofs:default
online         Sep_22   svc:/system/system-log:default
online         Sep_22   svc:/network/smtp:sendmail
online         Sep_22   svc:/system/filesystem/local:default
online         Sep_22   svc:/network/ssh:default
online         Sep_22   svc:/system/dumpadm:default
online         Sep_22   svc:/network/loopback:default

Running svcs without arguments lists all running (online) services. The STATE column reports the service status; the STIME refers to when the service state last changed; and the FMRI identifies the service. If you want to list all services, not just those that are running, use the -a option.

The svcs command can also examine a single service by using either a full or partial FMRI. You can add the -v or -x options for extended output on the service. The -d option will list all the dependencies of a service.

$ svcs svc://localhost/network/ssh:default
STATE          STIME    FMRI
online         Sep_22   svc:/network/ssh:default

$ svcs -v svc:/network/ssh
STATE          NSTATE        STIME    CTID   FMRI
online         -             Sep_22       52 svc:/network/ssh:default

$ svcs -x network/ssh
svc:/network/ssh:default (SSH server)
 State: online since Thu Sep 22 07:51:15 2005
   See: sshd(1M)
   See: /var/svc/log/network-ssh:default.log
Impact: None.

$ svcs -d ssh STATE          STIME    FMRI online
Sep_22   svc:/network/loopback:default online         Sep_22
svc:/network/physical:default online         Sep_22
svc:/system/cryptosvc:default online         Sep_22
svc:/system/filesystem/local:default online         Sep_22
svc:/system/utmp:default online         Sep_22

You can add the hostname localhost to an FMRI, or you can abbreviate it by removing the instance name and/or the categories. If the abbreviation results in multiple matches, they will all be listed. Here are two services that each have the name local in the last segment of the service name:

$ svcs local
STATE          STIME    FMRI
online         Sep_22   svc:/system/device/local:default
online         Sep_22   svc:/system/filesystem/local:default

You can also perform basic glob matching on service names:

$ svcs "*network*"
STATE          STIME    FMRI
disabled       Sep_22   svc:/network/rpc/keyserv:default
disabled       Sep_22   svc:/network/rpc/nisplus:default
disabled       Sep_22   svc:/network/nis/client:default
online         Sep_22   svc:/network/nfs/client:default
online         Sep_22   svc:/network/security/ktkt_warn:default
online         Sep_22   svc:/network/telnet:default
online         Sep_22   svc:/network/nfs/rquota:default

Services can manage a running process or an OS state. By using the -p option with svcs, you can identify the processes associated with a service.

$ svcs -p svc:/network/ssh
STATE          STIME    FMRI
online         Sep_22   svc:/network/ssh:default
               Sep_22        345 sshd

The time the process started is listed under the STIME column.

In some cases, services do not have running processes associated with them. Tasks such as bringing a network interface up or mounting a disk partition do not require continuously running processes. The svc:/system/filesyste/local:default service runs the mount command once to mount all local filesystems, and then the script exits. SMF refers to these as transient services.

$ svcs -p svc:/system/filesystem/local:default
STATE          STIME    FMRI
online         Sep_22   svc:/system/filesystem/local:default

Finally, there are services that have running processes only when they are in use. When Sun designed the Service Management Framework, it merged the behavior of inetd and the way it handles network daemons. All the daemons that previously appeared in the /etc/inetd.conf file are now SMF-managed services. The difference is that these services use the inetd daemon as a starter, instead of svc.startd.

$ svcs -p rlogin
STATE          STIME    FMRI
online         Sep_22   svc:/network/login:rlogin

$ rlogin localhost
Last login: Sun Feb 19 23:49:56 from localhost
Sun Microsystems Inc.   SunOS 5.10      Generic January 2005

$ svcs -p rlogin
STATE          STIME    FMRI
online         Sep_22   svc:/network/login:rlogin
               23:50:41    23833 in.rlogind
               23:50:41    23836 bash
               23:50:48    23840 svcs

$ exit
Connection to localhost closed.
$ svcs -p rlogin
STATE          STIME    FMRI
online         Sep_22   svc:/network/login:rlogin

If you kill a process under the control of service management, the program that originally started it will restart it. Here's an example of an Apache2 service that has been running since January 5. First, I double-checked the service by grepping for the process IDs, which match the ones listed with the service. Then, I sent the TERM signal to the parent of all of the child processes.

# svcs -p http
STATE          STIME    FMRI
online         Jan_05   svc:/application/http:apache2
               Jan_05      12377 httpd
               Jan_05      12378 httpd
               Jan_05      12379 httpd
               Jan_05      12380 httpd

# ps -ef | grep http
    root 12377     1   0   Jan 05 ?           2:14 /opt/apache2/bin/httpd -DPERL
    root 23521 23520   0 20:33:01 pts/1       0:00 grep http
    http 12378 12377   0   Jan 05 ?           0:00 /opt/apache2/bin/httpd -DPERL
    http 12380 12377   0   Jan 05 ?           0:00 /opt/apache2/bin/httpd -DPERL

# kill -TERM 12377

# ps -ef | grep http
    root 23527 23520   0 20:33:25 pts/1       0:00 grep http
    root 23580     1   0 20:33:09 ?           0:01 /opt/apache2/bin/httpd -DPERL
    http 23581 23580   0 20:33:10 ?           0:00 /opt/apache2/bin/httpd -DPERL
    http 23582 23580   0 20:33:12 ?           0:00 /opt/apache2/bin/httpd -DPERL
    http 23583 23580   0 20:33:12 ?           0:00 /opt/apache2/bin/httpd -DPERL

# svcs -p svc:/application/http:apache2
STATE          STIME    FMRI
online         20:33:09 svc:/application/http:apache2
               20:33:09    23580 httpd
               20:33:10    23581 httpd
               20:33:11    23582 httpd
               20:33:11    23583 httpd

I then rechecked for the httpd processes to find that the svc.start daemon started new Apache servers. Then I examined the http service. It reported that the service time had changed, and listed the new process IDs.

The following table lists some SMF services, their associated processes, and their restarter FMRI:

Service Processes Restarter
svc:/system/svc/restarter:sendmail svc.startd none
svc:/network/smtp:sendmail sendmail svc:/system/svc/restarter:default
svc:/network/ssh:default sshd svc:/system/svc/restarter:default
svc:/system/sac:default sac
svc:/network/inetd:default inetd svc:/system/svc/restarter:default
svc:/network/telnet:default in.telnetd svc:/network/inetd:default

If you want to know the restarter for a service, use svcs -l. Use svcs -R with a full FMRI to list all of the services a restarter service controls.

$ svcs -l network/ssh
fmri         svc:/network/ssh:default
name         SSH server
enabled      true
state        online
next_state   none
state_time   Thu Sep 22 07:51:15 2005
logfile      /var/svc/log/network-ssh:default.log
restarter    svc:/system/svc/restarter:default
contract_id  52
dependency   require_all/none svc:/system/filesystem/local (online)
dependency   optional_all/none svc:/system/filesystem/autofs (online)
dependency   require_all/none svc:/network/loopback (online)
dependency   require_all/none svc:/network/physical (online)
dependency   require_all/none svc:/system/cryptosvc (online)
dependency   require_all/none svc:/system/utmp (online)
dependency   require_all/restart file://localhost/etc/ssh/sshd_config (online)

$ svcs -R svc:/system/svc/restarter:default
STATE          STIME    FMRI
disabled       Sep_22   svc:/system/metainit:default
disabled       Sep_22   svc:/network/rpc/keyserv:default
online         Sep_22   svc:/system/svc/restarter:default
online         Sep_22   svc:/network/pfil:default
online         Sep_22   svc:/milestone/name-services:default
online         Sep_22   svc:/network/loopback:default

Pages: 1, 2, 3, 4

Next Pagearrow

Sponsored by: