Tuesday, August 4, 2009

Svnserve, and Solaris 10

I had to go through the trouble of getting svnserve to run as an SMF-managed service on Solaris 10, so there's no reason you should, too.

Create the method script.


This script uses rc-like syntax. The xml manifest (coming up!) uses this.

vi /lib/svc/method/svc-svnserve

The contents:
#!/sbin/sh

case $1 in
start)
svnserve -r /var/svnroot -d ;;
stop)
/usr/bin/pkill -x -u 0 svnserve ;;
*)
echo Usage is $0 { start | stop }
exit 1 ;;
esac

exit 0

Fix the permissions:

chmod 555 /lib/svc/method/svc-svnserve
chown root:bin /lib/svc/method/svc-svnserve

Test it with:

sh /lib/svc/method/svc-svnserve start

Try to connect, list, etc., make sure it works the way you want it to.

Create the SMF manifest


vi /var/svc/manifest/site/svnserve.xml

The manifest, itself


<?xml version="1.0"?>
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
<service_bundle type='manifest' name='SUNWsvn:svnserve'>
<service
name='site/svnserve'
type='service'
version='1'>
<single_instance/>
<dependency
name='loopback'
grouping='require_all'
restart_on='error'
type='service'>
<service_fmri value='svc:/network/loopback:default'/>
</dependency>

<exec_method
type='method'
name='start'
exec='/lib/svc/method/svc-svnserve start'
timeout_seconds='30' />
<exec_method
type='method'
name='stop'
exec='/lib/svc/method/svc-svnserve stop'
timeout_seconds='30' />
<property_group name='startd' type='framework'>
<propval name='duration' type='astring' value='contract'/>
</property_group>
<instance name='default' enabled='true' />
<stability value='Unstable' />
<template>
<common_name>
<loctext xml:lang='C'>
New service
</loctext>
</common_name>
</template>
</service>
</service_bundle>

Check your work


Check the xml with:

xmllint --valid /var/svc/manifest/site/svnserve.xml

Then let's see if the smf stuff likes it:

svccfg validate /var/svc/manifest/site/svnserve.xml

If everything looks good so far...

Importing the manifest


svccfg import /var/svc/manifest/site/svnserve.xml

It should show up under svcs in maintenance. Let's fix that:

svcadm enable svnserve:default

If it doesn't start, check /var/svc/log/site-svnserve:default.log

You should be all nicely integrated now.

2 comments:

  1. The manifest requires an XML declaration and DTD. Add the following to the top of the file or it won't validate:

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

    ReplyDelete
  2. Doh! Sure enough - it's present on my system. I must've fudged the cut and paste.

    I've updated the instructions.

    Thanks!

    ReplyDelete