Home>Computers>Adding a service for a custom program in Solaris 10

Adding a service for a custom program in Solaris 10

dnmasqservice

 

 

This is another thing that I managed to forget, and then I had to remember what I was looking at all over again. Instead of init scripts, Solaris 10 uses services, or SMF. It uses a combination of XML and Shell scripts to start and stop services. In practice, it’s actually really slick and I enjoy using it. When Debian and most other Linux flavors adopted something similar it was a welcome change for me. Now if someone could just write a good service editor we’d be good to go. Hmm, maybe a future project if I find the time 😉

The reason this came up this time was for dnsmasq. The opencsw distribution has dnsmasq, but no service for it installs when you install the package. They have been pretty good about keeping up with this sort of thing however apparently with once that is not the case. It’s actually really easy to add a service when you use what you find on line as a template. Since I’m posting my files here as well as the links I used as a reference you’ll be able to spot the differences and modify my scripts for yourself.

First off is the reference material that I used to complete this. The first thing I found this time and last time was this post here: http://www.unix.com/solaris/32936-solaris-10-add-new-svc.html  Just a little bit down, a gentleman was kind enough to really break down the process. His downfall was when I tried to copy and paste his scripts for me to just quickly modify there was some typographical errors that cause the svcadm command to be unable to parse the file, and complain without a detailed error message. Basically there were a couple of 0’s that should have been ) ‘s ..

I also found this blog later, http://rojanu.wordpress.com/2011/11/28/create-a-new-solaris-10-service/ ,  which helped me get a comparison again of how some things work. If you are reading this page in hopes of putting together a service of your own I feel that you’ll succeed. Looking at these two pages you’ll get an idea of how the requirements work, how to pass messages to the user and so on.

here is my dnsmasq.xml located in /var/svc/manifest/site :

<?xml version="1.0"?>
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
<!--
Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
Use is subject to license terms.

pragma ident        "@(#)dnsmasq.xml 1.2     04/08/09 SMI"
-->

<service_bundle type='manifest' name='OPTnew:dnsmasq'>

<service
name='site/dnsmasq'
type='service'
version='1'>

<single_instance />
<dependency
name='usr'
type='service'
grouping='require_all'
restart_on='none'>
<service_fmri value='svc:/system/filesystem/local'/>
</dependency>

<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/dnsmasq start'
timeout_seconds='30' />

<exec_method
type='method'
name='stop'
exec='/lib/svc/method/dnsmasq stop'
timeout_seconds='30' />

<property_group name='startd' type='framework'>
<propval name='duration' type='astring' value='transient' />
</property_group>
<instance name='default' enabled='true' />

<stability value='Unstable' />
<template>
<common_name>
<loctext xml:lang='C'>
DNSMasq DNS DHCP Server
</loctext>
</common_name>
</template>
</service>

</service_bundle>

Here is my other script in /lib/svc/method/ :

#!/sbin/sh
#
# Copyright (c) 1995, 1997-1999 by Sun Microsystems, Inc.
# All rights reserved.
#
#ident  "@(#)dnsmasq    1.14    06/11/17 SMI"

case "$1" in
'start')
        /opt/csw/sbin/dnsmasq & > /dev/null
        ;;

'stop')
        /usr/bin/pkill -x -u 60001 dnsmasq
        ;;

*)
        echo "Usage: $0 { start | stop }"
        ;;
esac
exit 0

The only other thing was dont forget to change the pkill user id to the one that matches the user of the process that you’re killing. Since the nobody user handles dnsmasq, that is the nobody user id number after the -u directive in pkill..

Anyways, I hope this helps someone else as well. Thanks for stopping in 😀

4/5 - (2 votes)