How to use SMF to quickly detect problems

SMF (Service Management Facility) was introduced in Solaris 10 and it radically changed how you work with services. Gone are the old SysV scripts but they still work and not all services that are shipped with Solaris 10 is converted yet. If you have been a UNIX admin for a while they will feel foreign and strange, at least I felt like that, but once you get used to them you don’t really want to go back. I don’t want to write a tutorial on how to use it. There are plenty of them available, e.g you can find one at BigAdmin.

One nice feature is that you can quickly detect services that are not running. You can use the command svcs(1) to find out the status of the different services. One really useful parameter is -x. It shows which services which are not running due to a problem.

# svcs -x
svc:/application/management/snmpdx:default (Sun Solstice Enterprise Master Agent)
State: offline since Wed May 30 19:08:36 2007
Reason: Dependency svc:/application/management/seaport is absent.
See: http://sun.com/msg/SMF-8000-E2
See: snmpdx(1M)
Impact: This service is not running.

This means that snmpdx is not running because it can’t find seaport. I can either decide to install and start seaport or I can just disable snmpdx if I’m not planning to use it.


# svcadm disable svc:/application/management/snmpdx:default
# svcs -x
#

smf is happy again. We can use this feature to write a nice little script that can send us an email (or be integrated into a snmp based monitoring solution) when a service is not running.

Lets take a look at the script.

#!/bin/ksh

# Public domain. Use as you wish.

EMAIL=nickus@aspiringsysadmin.com
TMPFILE=/tmp/svcs.output.$$

export PATH=/usr/bin

svcs -x >$TMPFILE

#
# check if the file size is greater than zero
# which means we got some output from svcs and
# therefore a service is bad
#
if [ -s $TMPFILE ]; then
        cat $TMPFILE | mailx -s "Service failed on `hostname`" $EMAIL
fi

rm -f $TMPFILE

It is very simple. If we get any output from svcs we simply email it to the address specificed in EMAIL. Run the script from roots crontab once an hour and you have a nice service monitoring system in place.

You can also download the script here.

[?]
Do you need system administration assistance? If you like what you are reading please consider subscribing to the RSS feed. If you have feedback or if you find the article useful please leave a comment below.

3 Responses to “How to use SMF to quickly detect problems”

  1. Hi, how about if I DO want snmp, and the svc:/application/management/seaport is absent. How does one go about finding the needed packages from Solaris media and install the seaport svc to recover snmp? for example.

    Thanks!

  2. James, if you google for the terms “solaris seaport absent” it seems to point to that you are missing a patch.

  3. But what if it WAS running and I’m not missing the required patch ?

Leave a Reply