Solaris/SMF

From Segfault
Jump to navigation Jump to search

Usage

We wanted to change the nameserver in /etc/resolv.conf but apparently this file is managed by svccfg now.[1]

svccfg -s network/dns/client
> listprop config
> config                     application        
> config/domain              astring     example.org
> config/nameserver          net_address 10.0.0.1
> config/value_authorization astring     solaris.smf.value.name-service.dns.client
>
> setprop config/nameserver = 10.0.2.2
> refresh

After restarting the DNS client the configuration should be changed:

$ svcadm refresh network/dns/client
$ svcadm restart network/dns/client

$  tail -2 /etc/resolv.conf 
domain      example.org
nameserver  10.0.2.2

Migration

Let's convert the following simple init script to an SMF[2] (Service Management Facility) service:

$ cat /var/tmp/listen.sh 
#!/bin/sh
#
# Listen on tcp4:8080
#
case $1 in start)
        nc -4l 8080 &
        ;;

        stop)
        pkill -f "nc -4l 8080"
        ;;

        status)
        netstat -an -f inet | grep \\.8080
        ;;
esac

The SMF version would be:

$ cat /var/tmp/listen.xml
<?xml version='1.0'?>
<!DOCTYPE service_bundle SYSTEM '/usr/share/lib/xml/dtd/service_bundle.dtd.1'>

<service_bundle type='manifest' name='listen'>

<service
        name='application/listen'
        type='service'
        version='1'>

        <single_instance/>
        <dependency
                name='net-physical'
                type='service'
                grouping='require_all'
                restart_on='none'>
                <service_fmri value='svc:/network/physical'/>
        </dependency>

        <instance name='default' enabled='true'>
        <exec_method
                type='method'
                name='start'
                exec='/var/tmp/listen.sh start'
                timeout_seconds='1'>
        </exec_method>

        <exec_method
                type='method'
                name='stop'
                exec=':kill -15'
                timeout_seconds='3'>
        </exec_method>
        </instance>
</service>
</service_bundle>

Validate it:

$ svccfg validate /var/tmp/listen.xml; echo $?
0

With that in place, we can import the .xml file into our SMF framework:

$ svccfg import /var/tmp/listen.xml 
$ svccfg -s application/listen listprop
manifestfiles                     framework
manifestfiles/var_tmp_listen_xml  astring  /var/tmp/listen.xml
general                           framework
general/single_instance           boolean  true
net-physical                      dependency
net-physical/entities             fmri     svc:/network/physical
net-physical/grouping             astring  require_all
net-physical/restart_on           astring  none
net-physical/type                 astring  service

Enabling the service will start it too:

$ svcadm enable application/listen
$ svcs -xv application/listen
svc:/application/listen:default (?)
 State: online since July  2, 2011 12:16:31 AM PDT
   See: /var/svc/log/application-listen:default.log
Impact: None.

Links

References