Thursday, December 01, 2005

How do I customise an SMF service?

After a conversation on #opensolaris I thought it would be useful to explain how to get SMF to run services that you have installed yourself that are really updated versions of ones that ship with solaris.

The one in question was DNS. "Solaris10" had installed his own version of named in /usr/local/sbin/named and wanted to get SMF to start it. When I arrived there was discussion about editing the manifest file (/var/svc/manifest/network/dns/server.xml) or copying it and making another.

As it turns out, neither of those is needed or particularly good. Edits to the system supplied file may be overwritten by a future patch or upgrade and making your own service means you won't get the benefits of those upgrades and patches.

So, how is it done?

The answer is that many attributes of services are parameterized into properties of the service. Those properties can be changed on your system without editing the manifest files, and they are not broken by updates.

You can view the properties for a service with:

# svcprop dns/server


This lists them all. The one we're interested in is called "exec" in the property group "start", so to just see that one:

# svcprop -p start/exec dns/server
/usr/sbin/named


To change a property, use svccfg as follows:

# svccfg
svc:> select dns/server:default
svc:/network/dns/server:default> listprop start/exec
start/exec astring /usr/sbin/named
svc:/network/dns/server:default> setprop start/exec = /usr/local/sbin/named
svc:/network/dns/server:default> listprop start/exec
start/exec astring /usr/local/sbin/named
svc:/network/dns/server:default> quit


Then you need to refresh the service:

# svcadm refresh dns/server


And now, start it:

# svcadm start dns/server


Finally, you can actually make the svccfg part much shorter with:

# svccfg -s dns/server:default setprop start/exec = /usr/local/sbin/named