How to bring a service under SMF

This entry was posted in Linux, WebServer and tagged on June 17, 2012, by

Bring a service under SMF

The general steps required for this is as follow

  • Determine the process of starting and stop service
  • Establish the name of the service
  • Determine whether your service runs multiple instance
  • Indentify any dependencies
  • Create a manifest file
  • Put the script into SMF
  • Enable the service

1. Consider the following example, we create a new service name “nameservice”

# vi /usr/local/svc/method/newservice

#!/sbin/sh
#
# ident “@(#)newservice 1.14 09/09/2010 SMI”
case “$1” in
’start’)
/usr/bin/newservice &
;;
’stop’)
/usr/bin/pkill -x -u 0 newservice
;;
*)
echo “Usage: $0 { start | stop }”
;;
esac
exit 0

Save and quit.

2. Create a xml file

# cd /var/svc/manifest/site

# vi newservice.xml

<?xml version=”1.0″?>
<!DOCTYPE service_bundle SYSTEM
“/usr/share/lib/xml/dtd/service_bundle.dtd.1”>

<service_bundle type=’manifest’ name=’OPTnew:newservice’>
<service
name=’site/newservice’
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>
<dependent
name=’newservice’
grouping=’require_all’
restart_on=’none’>
<service_fmri value=’svc:/milestone/multi-user’ />
</dependent>
<exec_method
type=’method’
name=’start’
exec=’/lib/svc/method/newservice start’
timeout_seconds=’30’ />
<exec_method
type=’method’
name=’stop’
exec=’/lib/svc/method/newservice 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’ />

</service>
</service_bundle>

Save and quit.

3 . Following is the content of the file created above

  • Standard header : It will give you version and all
  • Name of the service: Nameservice
  • Service category type, name and version
  • Also gives instances of service that will run
  • How the service is started and stop
  • After that deafine dependencies for the service
  • Create the instances

4.  Next check if the syntax is correct or not of the xml file

# xmllint /var/svc/manifest/site

If any error correct it and follow the next step

5. Import the xml file into SMF

# svcfg import /var/svc/manifest/site/newservice.xml

6. Check the status of the service

# svcs newservice

7. If its disabled enable it

# svcadm -v enable site/newservice

Leave a Reply

Your email address will not be published. Required fields are marked *

Copyright 2017 ©Aceadmins. All rights reserved.