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 |
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/ |
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 |
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 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 |
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 |
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 |
Check if our goal with SMF service is fullfilled
root@sol11u1:/lib/svc/method#
ndd /dev/ip igmp_max_version |
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 …