Ads 468x60px

Pages

Subscribe:

Friday, November 22, 2013

 Creating a simple SMF service in solaris 11.1 using svcbundle



Solaris 10 introduced SMF but not all services are SMF managable , SMF services give the simple way of configuring or managing a service .

It becomes our requirement sometimes to create a SMF manageable service in case we need a startup script executed on bootup like setting ndd parameters . SMF services use a  manifest a xml files that has all the configurations settings for that particular service , this xml file needs to be created before defining a SMF service



In solaris 10 to create a SMF service you need to manually edit and define an xml file that could be tiresome and may need some xml knowledge . With imporved Solaris 11.1 we have  svcbundle utility which gives us easy way to create SMF manifest and profiles .



This post gives a simple procedure to create a transient service (service that doesnt need a stop script) to accomplish setting ndd parameters for /dev/ip.



Start with writing a simple shell script that sets ndd parameters when executed . Here I am a two line script to set igmp version.(Currently this cannot be set with ipadm set-prop)



Step 1:

root@sol11u1:~# cat /lib/svc/method/ndd-igmp.sh
#!/usr/sbin/sh
#
ndd -set /dev/ip igmp_max_version 1
ndd -set /dev/ip mld_max_version 1



Step:2

#svcbundle -o net-tune.xml -s service-name=network/net-tune -s start-method=/lib/svc/method/ndd-igmp.sh



Option -o  the output xml file name and properties for the servcie can be defined with multiple -s options like above service-name name of the service as displayed with svcs -a and start-method that give the script name with complete path . (I prefer to create script under /lib/svc/method/ as all the scripts defined with default SMF services are here). By default if you dont mention -s model which defines the serivce type(transient,deamon etc..) , svcbundle considers it a transient service .



Here is the xml file created after executing the svcbundle .

root@sol11u1:/lib/svc/method# more net-tune.xml

<?xml version="1.0" ?>

<!DOCTYPE service_bundle

SYSTEM '/usr/share/lib/xml/dtd/service_bundle.dtd.1'>

<!--

Manifest created by svcbundle (2013-Nov-20 07:17:48+0530)

-->

<service_bundle type="manifest" name="network/net-tune">

<service version="1" type="service" name="network/net-tune">

<!--

The following dependency keeps us from starting until the

multi-user milestone is reached.

-->

<dependency restart_on="none" type="service"

name="multi_user_dependency" grouping="require_all">

<service_fmri value="svc:/milestone/multi-user"/>

</dependency>

<exec_method timeout_seconds="60" type="method" name="start"

exec="/lib/svc/method/ndd-igmp.sh"/>

<!--

The exec attribute below can be changed to a command that SMF

should execute to stop the service. See smf_method(5) for more

details.

-->

<exec_method timeout_seconds="60" type="method" name="stop"

exec=":true"/>

<!--

The exec attribute below can be changed to a command that SMF

should execute when the service is refreshed. Services are

typically refreshed when their properties are changed in the

SMF repository. See smf_method(5) for more details. It is

common to retain the value of :true which means that SMF will

take no action when the service is refreshed. Alternatively,

you may wish to provide a method to reread the SMF repository

and act on any configuration changes.

-->

<exec_method timeout_seconds="60" type="method" name="refresh"

exec=":true"/>

<property_group type="framework" name="startd">

<propval type="astring" name="duration" value="transient"/>

</property_group>

<instance enabled="true" name="default"/>

<template>

<common_name>

<loctext xml:lang="C">

<!--

Replace this comment with a short name for the

service.

-->

</loctext>

</common_name>

<description>

<loctext xml:lang="C">

<!--

Replace this comment with a brief description of

the service

-->

</loctext>

</description>

</template>

</service>

</service_bundle>





Step 3: Copy the xml file under  /lib/svc/manifest/site/

root@sol11u1:/#   cp net-tune.xml /lib/svc/manifest/site/

root@sol11u1:/lib/svc/method# svcs net-tune
svcs: Pattern 'net-tune' doesn't match any instances
STATE          STIME    FMRI



Import the created SMF service using svcadm restrat manifest-import . This will create the service and can be seein with svcs now .



root@sol11u1:/lib/svc/method# svcadm restart manifest-import



Great to see our service with svc but that is in maintenance . Lets troubleshoot in our traditional manner starting with SMF log file



root@sol11u1:/lib/svc/method# svcs net-tune
STATE          STIME    FMRI
maintenance     7:19:28 svc:/network/net-tune:default

root@sol11u1:/lib/svc/method# svcs net-tune
STATE          STIME    FMRI
maintenance     7:19:59 svc:/network/net-tune:default
root@sol11u1:/lib/svc/method# svcs -l network/net-tune
fmri         svc:/network/net-tune:default
enabled      true
state        maintenance
next_state   none
state_time   November 20, 2013 07:19:59 AM IST
logfile      /var/svc/log/network-net-tune:default.log
restarter    svc:/system/svc/restarter:default
manifest     /lib/svc/manifest/site/net-tune.xml
dependency   require_all/none svc:/milestone/multi-user (online)



Wow we do have a log file created for our services , which clearly shows permission denied

root@sol11u1:/lib/svc/method# more /var/svc/log/network-net-tune:default.log
[ Nov 20 07:19:28 Enabled. ]
[ Nov 20 07:19:28 Executing start method ("/lib/svc/method/ndd-igmp.sh"). ]
/usr/sbin/sh[1]: exec: /lib/svc/method/ndd-igmp.sh: cannot execute [Permission denied]
[ Nov 20 07:19:28 Method "start" exited with status 126. ]
[ Nov 20 07:19:28 Executing start method ("/lib/svc/method/ndd-igmp.sh"). ]
/usr/sbin/sh[1]: exec: /lib/svc/method/ndd-igmp.sh: cannot execute [Permission denied]
[ Nov 20 07:19:28 Method "start" exited with status 126. ]
[ Nov 20 07:19:28 Executing start method ("/lib/svc/method/ndd-igmp.sh"). ]
/usr/sbin/sh[1]: exec: /lib/svc/method/ndd-igmp.sh: cannot execute [Permission denied]

[ Nov 20 07:19:28 Method "start" exited with status 126. ]





Check the permissions on the script we have create ... Always a shell script need executable permissions .



root@sol11u1:/lib/svc/method# ls -l /lib/svc/method/ndd-igmp.sh
-rw-r--r--   1 root     root          93 Nov 20 07:17 /lib/svc/method/ndd-igmp.sh



Change the permissions to have it executed .



root@sol11u1:/lib/svc/method# chmod 755 /lib/svc/method/ndd-igmp.sh



Lets see what our settings currently are before we test if our SMF is working or not . And here we have the ndd parameter  igmp_max_version set to 2 (our goal with the SMF service is to set it to 1)

root@sol11u1:/lib/svc/method# ndd /dev/ip igmp_max_version
2



As our service is in maintenance just clearing the services should make it online as we maded the script executable now .

root@sol11u1:/lib/svc/method# svcadm clear net-tune
root@sol11u1:/lib/svc/method# svcs net-tune
STATE          STIME    FMRI
online          7:21:11 svc:/network/net-tune:default



Check if our goal with SMF service is fullfilled



root@sol11u1:/lib/svc/method#  ndd /dev/ip igmp_max_version
1
root@sol11u1:/lib/svc/method#  ndd /dev/ip mld_max_version
1



That makes us success in creating a SMF service manageable with svcadm . Follow the similar process to create your own SMF service , play with the service using svcadm,svccfg etc …

0 comments:

Post a Comment