Professional Documents
Culture Documents
http://www.oracle.com/technetwork/articles/servers-storage-admin/intro...
Communities
I am a...
I want to...
Search
SOLUTIONS
DOWNLOADS
STORE
SUPPORT
TRAINING
PARTNERS
ABOUT
Articles
Introducing the Basics of Service Management Facility (SMF) on Oracle Solaris 11 by Glynn Foster Simple examples of administering services on Oracle Solaris 11 with the Service Management Facility.
Published August 2012
The Service Management Facility (SMF), first introduced in Oracle Solaris 10, is a feature of the operating system for managing system and application services, replacing the legacy init scripting start-up mechanism common to prior releases of Oracle Solaris and other UNIX operating systems. SMF improves the availability of a system by ensuring that essential system and application services run continuously even in the event of hardware or software failures. SMF is one of the components of the wider Oracle Solaris Predictive Self Healing capability. This article gives an introduction to SMF and demonstrates some simple examples of administering services on Oracle Solaris 11. More advanced administration topics will be covered in another article. To learn more about SMF, check out a variety of content at the SMF technology page on Oracle Technology Network.
An Overview of SMF
Before we look at some command line examples, let's quickly explore some of the features of SMF and the benefits it can bring in terms of improving application resiliency in a typical data center environment. SMF is the software framework that is responsible for managing services on a systemwhether they are critical system services essential to the working operation of the system or application services, such as a database or Web server.
If you'd like to download software, participate in forums, and get access to other technical how-to goodies in addition to content like this, become an OTN member. No spam!
Each service has a well-defined state (enabled, disabled, offline, maintenance) and usually a relationship to other dependent services that are required to be running on the system first. This provides a key benefit in that services can be started in parallel during system start up, resulting in a much faster boot when compared to the legacy init framework, which is only able to start processes in sequence and must wait until they complete. Each service is usually started by the SMF master restarter daemon, svc.startd, though this task can be delegated to an alternative restarter, as is the case for internet services delegated to inetd. Behind the scenes of each service is a service manifest that describes some basic information about the service, what service dependencies are required, any required service configuration, and how SMF should start and stop the service. A service, once started, can start several different processes that are tied together as part of a service contract. This means that an administrator needs to manage only the higher-level service, rather than worrying about a series of individual processes and what start order might be required by those processes. If a service fails for any reason, whether during a hardware or software fault, SMF will automatically detect the failure and restart the service and any dependent services. SMF also includes the ability to run multiple instances of a given service and share common configuration across those instances. This is especially useful when you want to run multiple Apache Web server instances, for example, that might differ only by a given port number and document root. SMF stores service configuration data in a configuration repository, including the current state of each service instance on the system as well as the configuration data related to that service and service instance. The configuration repository is managed by the SMF configuration repository daemon, svc.configd. Each service on the system can be described using a Fault Management Resource Indicator (FMRI) that shows the service name, the service instance, and an associating category. For example, the SSH server has the following FMRI: svc:/network/ssh:default In this case, the service name is ssh, the service instance is default, and the category is network. All SMF-related FMRIs are prefixed with the svc:/ scheme, except for "legacy services," which are prefixed with the lrc:/ scheme, as we will see below. Administrators use FMRIs as the main way to manipulate services on an Oracle Solaris system. In some cases, we can use abbreviated forms to refer to the same service, which we will see a little later in this article. The SMF framework is always active on an Oracle Solaris 11 system, and it is started (and restarted) through the default init process, as shown in Figure 1.
1 of 8
11/9/2012 5:10 PM
http://www.oracle.com/technetwork/articles/servers-storage-admin/intro...
2 of 8
11/9/2012 5:10 PM
http://www.oracle.com/technetwork/articles/servers-storage-admin/intro...
disabled Jun_14 disabled Jun_14 disabled Jun_14 disabled Jun_14 disabled Jun_14 disabled Jun_14 disabled Jun_14 disabled Jun_14 ... online Jun_14 online Jun_14 online Jun_14 online Jun_14 online Jun_14 Listing 2. List of All Services
svc:/network/ipsec/manual-key:default svc:/system/name-service-cache:default svc:/network/ldap/client:default svc:/network/nis/client:default svc:/network/ibd-post-upgrade:default svc:/network/inetd-upgrade:default svc:/network/nfs/status:default svc:/network/nfs/nlockmgr:default svc:/system/zones:default svc:/system/power:default svc:/system/hal:default svc:/application/texinfo-update:default svc:/application/pkg/update:default
As we can see in Listing 2, we get a number of new service instances not listed with the previous command. To get an idea of just how many differences there are, we can get a quick count of the lines of output and get the number of disabled (or incomplete) services. In this case, it amounts to 111 disabled services on this system. # svcs | wc -l 147 # svcs -a | wc -l 258 Now that we've seen a listing of all service instances, let's explore one of the service instances and get some more information about it. In this example, let's choose the svc:/system/zones:default service instance. We can use the -l option and the service name to get more information, as shown in Listing 3. # svcs -l svc:/system/zones:default fmri svc:/system/zones:default name Zones autoboot and graceful shutdown enabled true state online next_state none state_time June 14, 2012 08:30:31 PM NZST logfile /var/svc/log/system-zones:default.log restarter svc:/system/svc/restarter:default manifest /etc/svc/profile/generic.xml manifest /lib/svc/manifest/system/zones.xml manifest /lib/svc/manifest/system/zonestat.xml dependency require_all/none svc:/milestone/multi-user-server (online) dependency optional_all/none svc:/system/pools:default (disabled) dependency optional_all/none svc:/system/pools/dynamic:default (disabled) dependency optional_all/none svc:/system/zones-monitoring (online) Listing 3. Getting Information About a Service Instance This command lists a lot of information about the svc:/system/zones:default service instance, including a description, detail about the state, where on the file system messages about it are being logged, what service is responsible for starting and restarting it, related service manifests, and dependency information. As we can see from the description, this service instance is responsible for autobooting zones during system startup and shutting them down. From Listing 3, we can see that this service instance has four dependencies, one of which is required and three of which are optional. Another way to view dependency information is to use the -d option to svcs. While this gives us information about the state of the dependent service, it does not tell us what the dependency relationship might be: # svcs -d svc:/system/zones:default gman@rampage:~$ svcs -d zones STATE STIME FMRI disabled Jun_14 svc:/system/pools:default disabled Jun_14 svc:/system/pools/dynamic:default online Jun_14 svc:/system/zones-monitoring:default online Jun_14 svc:/milestone/multi-user-server:default Let's now have a look at another related service instance, svc:/system/zones-monitoring:default, and see what services depend on this service using the -D option to svcs: # svcs -D svc:/system/zones-monitoring:default STATE STIME FMRI online Jun_14 svc:/system/zone:default The result, svc:/system/zones:default, is relatively unsurprising since we had already determined that relationship in the previous example. One of the key features of SMF is that administrators manage services rather than the individual processes themselves. But what if we wanted to know what processes were being started by a given service instance? We can look at this easily by using the -p option to svcs, which ps helps to confirm: # svcs -p zones-monitoring STATE STIME FMRI online Jun_14 svc:/system/zones-monitoring:default Jun_14 216 zonestatd # ps 216 PID TT 216 ?
S S
Up until now, we have always used the full FMRI on the command line to specify the service that we are interested in. SMF also supports abbreviated FMRIs. All of the following examples of getting information about the svc:/system/system-log:default service instance are equivalent because they each uniquely identify the service: # svcs -l svc:/system/system-log:default # svcs -l system/system-log:default
3 of 8
11/9/2012 5:10 PM
http://www.oracle.com/technetwork/articles/servers-storage-admin/intro...
4 of 8
11/9/2012 5:10 PM
http://www.oracle.com/technetwork/articles/servers-storage-admin/intro...
We can see that the /usr/sbin/snmpd process has restarted with a new process ID of 6065 and the service is still online! Permanently disabling the service is also simple by using the svcadm disable command, as follows: # svcadm disable net-snmp # svcs net-snmp STATE STIME FMRI disabled 9:44:40 svc:/application/management/net-snmp:default # snmpwalk -v 1 -c public localhost Timeout: No response from localhost If we had chosen to, we could also have disabled the service temporarily until the next reboot using the -t option. Each service in SMF is always in one of a few different states, as shown in Table 2. Table 2. SMF Service States State Description This is the initial state of all services until its restarter (usually svc.startd) moves uninitialized services to another state. offline The instance is enabled but not yet running or unable to run. online The instance is enabled and running. The instance is enabled but unable to run for some reason, and administrative action maintenance will be required. disabled The instance is disabled. legacy-run The service is not directly managed by SMF, but it was started at some point. If, for any reason, we wanted to restart a service, we could use the svcadm restart command.
SMF Milestones
SMF milestones are services that aggregate multiple service dependencies and describe a specific state of system readiness on which other services can depend. Administrators can see the list of milestones that are defined by using the svcs command, as shown in Listing 6. # svcs milestone* STATE STIME online Jun_30 online Jun_30 online Jun_30 online Jun_30 online Jun_30 online Jun_30 online Jun_30 online Jun_30 online Jun_30 Listing 6. Listing Milestones FMRI svc:/milestone/unconfig:default svc:/milestone/config:default svc:/milestone/devices:default svc:/milestone/network:default svc:/milestone/single-user:default svc:/milestone/name-services:default svc:/milestone/self-assembly-complete:default svc:/milestone/multi-user:default svc:/milestone/multi-user-server:default
Some of the above milestones correspond to the traditional system run levels S (svc:/milestone/single-user), 2 (svc:/milestone/multiuser), and 3 (svc:/milestone/multi-user-server). Others correspond to internal implementation of the system configuration framework, sysconfig. While changing milestones is possible with svcadm, it is recommended that administrators continue to use the init command.
5 of 8
11/9/2012 5:10 PM
http://www.oracle.com/technetwork/articles/servers-storage-admin/intro...
parent service and the service instance. If we just wanted to look at the instance properties, we can use the -C option, as shown in Listing 8. # svcprop -C dns/client:default general/complete astring general/enabled boolean true restarter/logfile astring /var/svc/log/network-dns-client:default.log restarter/start_pid count 572 restarter/start_method_timestamp time 1339662573.041262000 restarter/start_method_waitstatus integer 0 restarter/transient_contract count restarter/auxiliary_state astring dependencies_satisfied restarter/next_state astring none restarter/state astring online restarter/state_timestamp time 1339662573.051463000 restarter_actions/auxiliary_tty boolean false restarter_actions/auxiliary_fmri astring svc:/network/location:default general_ovr/enabled boolean true Listing 8. Listing Only Instance Properties If we wanted to focus on a particular property, we can use the -p option to specify the property group and property. In this case, we're going to find the config/nameserver property on the service rather than on the service instance. This property is used as a replacement to the legacy /etc/resolv.conf file in previous versions of Oracle Solaris, though the value is mirrored to that file for compatibility with applications that might be parsing it. # svcprop -p config/nameserver dns/client 192.168.0.1 Now that we've seen how to query properties, let's take a look at another command, svccfg, that we can use to set properties. svccfg provides a number of different ways to set properties: directly on the command line, through an interactive text-based interface, or through a text editor. Let's keep with our svc:/network/dns/client example and see how easy it is to set the name server configuration. # svccfg -s dns/client setprop config/nameserver = 10.0.0.1 # svccfg -s dns/client listprop config/nameserver config/nameserver net_address 10.0.0.1 Changes made to an existing service in the respository typically do not take effect until the service instance has been refreshed. # svcprop -p config/nameserver dns/client 192.168.0.1 # svcadm refresh dns/client:default # svcprop -p config/nameserver dns/client 10.0.0.1 Equally, we could have used the interactive interface to make these changes. Let's change the value of config/nameserver back to what it was originally, 192.168.0.1, as shown in Listing 9. # svccfg svc:> select dns/client svc:/network/dns/client> listprop config/nameserver config/nameserver net_address 10.0.0.1 svc:/network/dns/client> describe config/nameserver config/nameserver net_address 10.0.0.1 The value used to construct the "nameserver" directive in resolv.conf(4) svc:/network/dns/client> setprop config/nameserver = 192.168.0.1 svc:/network/dns/client> listprop config/nameserver config/nameserver net_address 192.168.0.1 svc:/network/dns/client> select default svc:/network/dns/client:default> refresh svc:/network/dns/client:default> exit Listing 9. Using the Interactive Interface svccfg supports a number of other useful commands, such as listpg to list property groups on a given service, editprop to open up a text editor to more easily allow configuration of multiple properties at the same time, and extract to allow administrators to easily capture service customizations as an XML file that can be applied on other systems. We will cover more of these in another article.
6 of 8
11/9/2012 5:10 PM
http://www.oracle.com/technetwork/articles/servers-storage-admin/intro...
# svcs http:apache22 STATE STIME FMRI online Jun_14 svc:/network/http:apache22 # svccfg -s http:apache22 setnotify from-online mailto:admin@mycompany.com # svccfg -s http:apache22 listnotify Event: from-online (source: svc:/network/http:apache22) Notification Type: smtp Active: true to: admin@mycompany.com
Troubleshooting
Now that we have covered some of the basics of administration with SMF, let's quickly take a look at some of the things we can do to troubleshoot what might be wrong with a service. To quickly get an idea of what services are not running due to errors, we can use the -xv options to svcs, as shown in Listing 11. # svcs -xv svc:/system/identity:node (system identity (nodename)) State: disabled since June 22, 2012 08:11:14 PM NZST Reason: Disabled by an administrator. See: http://sun.com/msg/SMF-8000-05 See: man -M /usr/share/man -s 4 nodename See: /var/svc/log/system-identity:node.log Impact: 5 dependent services are not running: svc:/network/rpc/bind:default svc:/network/rpc/gss:default svc:/system/filesystem/autofs:default svc:/network/rpc/smserver:default svc:/network/nfs/mapid:default Listing 11. Determining Which Services Have Errros In this case, we have a simple problem: svc:/system/identity:node has been disabled causing five dependent services to not run. Enabling it fixes the problem. Another reason for failure might be a missing configuration file, as in this example with svc:/application/management/net-snmp:default: # svcs -xv svc:/application/management/net-snmp:default (net-snmp SNMP daemon) State: offline since June 22, 2012 08:17:28 PM NZST Reason: Dependency file://localhost/etc/net-snmp/snmp/snmpd.conf is absent. See: http://sun.com/msg/SMF-8000-E2 See: man -M /usr/share/man/ -s 8 snmpd See: /var/svc/log/application-management-net-snmp:default.log Impact: This service is not running. Once we have fixed the problem (by ensuring that the snmpd.conf file exists), we need to restart the service. Another failure might be due to an incorrect configuration file or missing executables, as it the case here with svc:/network/http:apache22: # svcs -xv svc:/network/http:apache22 (Apache 2.2 HTTP server) State: maintenance since June 22, 2012 08:23:35 PM NZST Reason: Method failed. See: http://sun.com/msg/SMF-8000-8Q See: man -M /usr/apache2/2.2/man -s 8 httpd See: http://httpd.apache.org See: /var/svc/log/network-http:apache22.log Impact: This service is not running. In this case, it's not clear from a quick summary of the error what the fault is; however, it's clear that the service is now in maintenance state requiring explicit administrative intervention. The next logical step is to look at the service log located at /var/svc/log/network-http:apache22.log, as shown in Listing 12, which soon reveals the problem. # tail /var/svc/log/network-http\:apache22.log [ Jun 22 20:22:34 Method "stop" exited with status 0. ] [ Jun 22 20:22:34 Executing start method ("/lib/svc/method/http-apache22 start"). ] Apache version is 2.2 [ Jun 22 20:22:35 Method "start" exited with status 0. ] [ Jun 22 20:23:35 Stopping because service restarting. ] [ Jun 22 20:23:35 Executing stop method ("/lib/svc/method/http-apache22 stop"). ] Apache version is 2.2 /usr/apache2/2.2/bin/apachectl[86]: /usr/apache2/2.2/bin/httpd: not found [No such file or directory] Server failed to start. Check the error log (defaults to /var/apache2/2.2/logs/error_log) for more information, if any. [ Jun 22 20:23:35 Method "stop" exited with status 95. ] Listing 12. Checking the Service Log We can easily see that our system is missing the /usr/apache2/2.2/bin/httpd executable file. This can be fixed easily by restoring the missing file using the IPS package manager with a pkg fix apache-22 command. Once we have identified and fixed the problem, we need to clear the state of the SMF service: # svcadm clear http:apache22 # svcs http:apache22 STATE STIME FMRI online 20:34:04 svc:/network/http:apache22 While some of the examples above have relied on checking the output of the status of a service through svcs or the service log located in /var/svc/log, sometimes you will need to check the log of the SMF restarter for that service, either svc.startd or a delegated restarter. In the case of the former, the log can be found at /var/svc/log/svc.startd.log. In another article, we will cover other troubleshooting tips in case the tips above don't work.
7 of 8
11/9/2012 5:10 PM
http://www.oracle.com/technetwork/articles/servers-storage-admin/intro...
Summary
The Service Management Facility (SMF) provides a number of benefits for administrators managing system services and applications on Oracle Solaris 11, including automatic service restart, consolidated service configuration, and integration into the fault management framework. Unlike the legacy init system, administrators manage servicesrather than processeswith full service dependency checking and parallel service startup, leading to a more consistent system state and more manageability.
See Also
Download Oracle Solaris 11 Get more information about SMF from the SMF technology page See the Oracle Solaris Administration: Common Tasks guide Access Oracle Solaris 11 product documentation Access all Oracle Solaris 11 how-to articles Learn more with Oracle Solaris 11 training and support See the official Oracle Solaris blog Check out The Observatory and OTN Garage blogs for Oracle Solaris tips and tricks Follow Oracle Solaris on Facebook and Twitter
8 of 8
11/9/2012 5:10 PM