My first foray into Service Management Framework

Having got Solaris 10 installed and running with the minimum of fuss, I decided that I ought to learn about the Service Management Framework stuff.

So, I decided that my first task (other than reading the docs ;)) would be to set up a suitable configuration for the Squid proxy I am using.

I am using the Solais CSWsquid package from Blastwave, which comes with its own 'init' script that was copied over when I performed the Live Upgrade a couple of days ago. This is launched as a kind of pseudo-service by the SMF because it is legacy code.

The simplest way to start seemed to be to take a dump of the entire services database and then have a look at how things had been set up for a similar service (I chose the Apache 2 web server). You can get a dump of the entire services configuration using:

svccfg export > /tmp/svcs.xml

Before anyone mentions it, I show this for example only - the sources for the system services can be found in /var/svc/manifest/\* :)

With some judicious re-reading of the smf(5), service_bundle(4) and svccfg(1M) man pages, along with existing entry for apache, here is what I came up with as the service bundle for the squid proxy:

<?xml version="1.0"?>
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">

<service_bundle type='manifest' name='CSWsquid:squid'>

<service name='network/httpproxy' type='service' version='1'>

        <!-- Only want one instance and I want it enabled by default -->
        <create_default_instance enabled='true'/>
        <single_instance/>

        <!-- Can't do anything without a network layer -->
	<dependency name='loopback' grouping='require_all'
		    restart_on='error' type='service'>
		<service_fmri value='svc:/network/loopback:default'/>
	</dependency>

	<dependency name='physical' grouping='require_all'
		    restart_on='error' type='service'>
		<service_fmri value='svc:/network/physical:default'/>
	</dependency>

	<!-- Squid needs to be able to resolve host names. -->
	<dependency name='name-services' grouping='require_all'
                    restart_on='refresh' type='service'>
		<service_fmri value='svc:/milestone/name-services'/>
	</dependency>

	<!-- Need to ensure that /opt is mounted -->
	<dependency name='fs-local' grouping='require_all'
		    restart_on='none' type='service'>
		<service_fmri value='svc:/system/filesystem/local'/>
	</dependency>

	<exec_method type='method' name='start'
		exec='/opt/csw/lib/svc/method/squid start'
		timeout_seconds='60' />

	<exec_method type='method' name='stop'
		exec='/opt/csw/lib/svc/method/squid stop'
		timeout_seconds='5' />

	<exec_method type='method' name='refresh'
		exec='/opt/csw/lib/svc/method/squid refresh'
		timeout_seconds='5' />

	<stability value='Unstable' />

	<template>
		<common_name>
			<loctext xml:lang='C'>CSW Squid Proxy</loctext>
		</common_name>
		<documentation>
			<manpage title='squid' manpath='/opt/csw/man' section='8' />
			<doc_link name='squid-cache.org'
				uri='http://www.squid-cache.org' />
		</documentation>
	</template>
</service>

</service_bundle>
I used a similar naming scheme for this file as is used for the standard Solaris services. However, I stuck under /opt/csw/var rather than /var. So, the file name was: /opt/csw/var/svc/manifest/network/squid.xml. I then created a method script (/opt/csw/lib/svc/method/squid), based on /etc/init.d/cswsquid:

#!/sbin/sh

. /lib/svc/share/smf_include.sh

SQUID=/opt/csw/sbin/squid
CONF_FILE=/opt/csw/etc/squid.conf

[ ! -f ${CONF_FILE} ] && exit $SMF_EXIT_ERR_CONFIG

case "$1" in
'start')
        echo 'Starting squid server.'
        ${SQUID} -D &
        ;;
'stop')
        echo 'Stopping squid server.'
        ${SQUID} -k shutdown
        exit 0
        ;;
'refresh')
        echo 'Refreshing squid server.'
        ${SQUID} -k reconfigure
        exit 0
        ;;
\*)
        echo "Usage: $0 { start | stop | refresh }"
        exit 1
        ;;
esac

Then, it was a simple matter to first validate the XML service configuration:

svccfg validate /opt/csw/var/svc/manifest/network/squid.xml

and then import the configuration into the SMF, which starts squid (after I'd shut down the previously running version):

svccfg import /opt/csw/var/svc/manifest/network/squid.xml

A process listing shows the Squid server running and a quick check with my browser shows that it is working fine. Job done!

I'm not 100% sure I've got the dependencies correct though. As you'll see from the exec_method script, I test for the existence of the Squid config file before attempting to take action. This, however, can be expressed as a dependency using a dependency of type 'path' rather than service:

    <dependency name='config-file' type='path' grouping='require_all' restart_on='none'>
        <service_fmli value='file:///opt/csw/etc/squid.conf'/>
    </dependency>

As is common in all sorts of IT development, there is more than one way to skin this particular cat.

Of course, your mileage may vary if you copy this, and don't blame me if it all goes pear shaped - I'm just learning the stuff ;)

Comments:

Nice ;-)

Posted by Elendal on February 13, 2005 at 08:22 PM GMT #

[Trackback] I run a web proxy server for folks in the office; we use it as a longterm testbed for Solaris. But, in the insanity leading up to the release of Solaris 10, I've had little time to work on it. Recently I got a new server to host the cache; and so I'...

Posted by The View from the Moon on March 02, 2005 at 03:49 PM GMT #

Post a Comment:
Comments are closed for this entry.
About

tdw

Search

Top Tags
Archives
« April 2015
MonTueWedThuFriSatSun
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today