Wednesday January 26, 2005 With some trepidation I set about porting a very simple rc script to into smf. It seems I should not have been overly concerned. The service in question was a very small Postgres database, which on Solaris 9 had been started from rc3.d. Moving the rc script over to 10 worked but I wanted a fuller smf experience so decided to create a manifest and import that into smf on the zone running the database.
Starting with the start part of the rc script this became:
#!/sbin/sh
FMRI="svc:/appl/postgres"
getproparg() {
val=`svcprop -p $1 $FMRI`
[ -n "$val" ] && echo $val
}
p=`getproparg postgres/path`
d=`getproparg postgres/dbdir`
u=`getproparg postgres/user`
PATH=$p:${PATH}
export PATH
exec /bin/su $u -c "postmaster -i -S -D $d"It struck me that we are no longer confined to the bourne shell at this point. As long as we depend on the files systems being mounted we could use a more exotic shell, though never the csh. So all the possible options that postgres uses are defined as properties. Then this manifest can be imported and we are away:
<?xml version="1.0"?>
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
<service_bundle type='manifest' name='postgres'>
<service
name='appl/postgres'
type='service'
version='1'>
<create_default_instance enabled='true' />
<dependency
name='autofs'
grouping='require_all'
restart_on='none'
type='service'>
<service_fmri value='svc:/system/filesystem/autofs' />
</dependency>
<exec_method
type='method'
name='start'
exec='/postgres/svc/method/postgres'
timeout_seconds='0' />
<exec_method
type='method'
name='stop'
exec=':kill -15'
timeout_seconds='3' />
<property_group name='postgres' type='application'>
<propval name='user' type='astring' value='postgres' />
<propval name='path' type='astring' value='/usr/local/pgsql/bin' />
<propval name='dbdir' type='astring' value='/var/pgsql' />
</property_group>
</service>
</service_bundle>It depends on autofs so that if the binaries or the database files are automounted it will be ready.
Then:
# svccfg import postgres.xml
and we are away. Clearly I did not manage to get this right first time, and someone more knowledgeable in smf will tell me I still have not, but this was easy to debug as the output of the script when into /var/smf/log/appl-postgres:default.log.
dredd 5 # svcs -l svc:/appl/postgres:default fmri svc:/appl/postgres:default enabled true state online next_state none restarter svc:/system/svc/restarter:default contract_id 27355 dependency require_all/none svc:/system/filesystem/autofs (online) dredd 6 #
Now killing postgres using kill or pkill results in the database being restarted. Nice.
This was on a zone running build 67 so things may appear different in the released version.
Except where otherwise noted, this site is
licensed under a Creative Commons License 2.0
This is a personal weblog, I do not speak for my employer.
Posted by Warren Strange on January 26, 2005 at 10:10 PM GMT #