{"id":248,"date":"2016-03-03T09:39:38","date_gmt":"2016-03-03T08:39:38","guid":{"rendered":"http:\/\/www.lambiek.eu\/blog\/?p=248"},"modified":"2016-03-03T10:01:02","modified_gmt":"2016-03-03T09:01:02","slug":"solaris-create-custom-service","status":"publish","type":"post","link":"https:\/\/www.lambiek.eu\/blog\/tutorial\/solaris-create-custom-service\/","title":{"rendered":"Solaris create custom service"},"content":{"rendered":"<p>It is possible to have custom scripts managed by SMF in Solaris. To do so you need two components, namely a script and a service manifest.<\/p>\n<p>When you create the script include the <code>\/lib\/svc\/share\/smf_include.sh<\/code> script. The following is a sample script primer:<\/p>\n<pre class=\"lang:default decode:true \" title=\"Service script primer\" >\r\n#!\/bin\/bash\r\n. \/lib\/svc\/share\/smf_include.sh\r\n\r\nfunction _run()\r\n{\r\n        while :\r\n        do\r\n                your magic\r\n        done\r\n}\r\n\r\n_run &amp;\r\n\r\nexit $SMF_EXIT_OK\r\n<\/pre>\n<p>Next step is to create the service manifest. The following can be used as a manifest primer:<\/p>\n<pre class=\"lang:default decode:true \" title=\"Service manifest primer\" >\r\n&lt;?xml version='1.0'?&gt;\r\n&lt;!DOCTYPE service_bundle SYSTEM '\/usr\/share\/lib\/xml\/dtd\/service_bundle.dtd.1'&gt;\r\n&lt;service_bundle type='manifest' name='export'&gt;\r\n  &lt;service name='group\/service' type='service' version='0'&gt;\r\n    &lt;create_default_instance enabled='true'\/&gt;\r\n    &lt;dependency restart_on=\"none\" type=\"service\" name=\"multi_user_dependency\" grouping=\"require_all\"&gt;\r\n      &lt;service_fmri value=\"svc:\/milestone\/multi-user\"\/&gt;\r\n    &lt;\/dependency&gt;\r\n    &lt;exec_method name='start' type='method' exec='\/lib\/svc\/method\/my-script.sh' timeout_seconds='60'&gt;\r\n      &lt;method_context&gt;\r\n        &lt;method_credential user='root' group='root'\/&gt;\r\n      &lt;\/method_context&gt;\r\n    &lt;\/exec_method&gt;\r\n    &lt;exec_method name='stop' type='method' exec=':kill -9' timeout_seconds='60'\/&gt;\r\n    &lt;template&gt;\r\n      &lt;common_name&gt;\r\n        &lt;loctext xml:lang='C'&gt;Short name of service&lt;\/loctext&gt;\r\n      &lt;\/common_name&gt;\r\n      &lt;description&gt;\r\n        &lt;loctext xml:lang=\"C\"&gt;Brief description of service&lt;\/loctext&gt;\r\n      &lt;\/description&gt;\r\n    &lt;\/template&gt;\r\n  &lt;\/service&gt;\r\n&lt;\/service_bundle&gt;\r\n<\/pre>\n<p>Besides using the above primer, you can also use the manifest of an existing service. To do so find a service which &#8216;looks&#8217; like the service you are creating and export it to get the manifest:<\/p>\n<pre class=\"lang:default decode:true \" title=\"Export an existing service manifest\" >svccfg export network\/physical &gt; .\/my-service.xml<\/pre>\n<p>Edit the manifest and make the necessary changes. It is advised to validate your xml for syntax errors using:<\/p>\n<pre class=\"lang:default decode:true \" title=\"Validate service manifest file\" >svccfg validate .\/myservice.xml<\/pre>\n<p>After you finished creating both the script and the service manifest put the files into the appropriate locations:<\/p>\n<p>cp myscript.sh \/lib\/svc\/method\/myscript.sh<br \/>\ncp myservice.xml \/lib\/svc\/manifests\/site\/myservice.xml<\/p>\n<p>And install the service using:<\/p>\n<pre class=\"lang:default decode:true \" title=\"Import newly placed service manifests\" >svcadm restart manifest-import<\/pre>\n<p>There is also another approach which you can use based on svcbundle.<\/p>\n<p>A quick way to install a service is by using:<\/p>\n<pre class=\"lang:default decode:true \" title=\"Use svcbundle to quickly create a service based on a script\" >svcbundle -i -s service-name=group\/myservice -s start-method=\/path\/to\/myscript.sh -s stop-method=\":kill -9\"<\/pre>\n<p>If you want to modify some properties and\/or add dependencies etc. don&#8217;t use -i but use -o myservice.xml instead to create a manifest file.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>It is possible to have custom scripts managed by SMF in Solaris. To do so you need two components, namely a script and a service manifest. When you create the script include the \/lib\/svc\/share\/smf_include.sh script. The following is a sample script primer: #!\/bin\/bash . \/lib\/svc\/share\/smf_include.sh function _run() { while : do your magic done } &#8230; <span class=\"more\"><a class=\"more-link\" href=\"https:\/\/www.lambiek.eu\/blog\/tutorial\/solaris-create-custom-service\/\">[Read more&#8230;]<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4],"tags":[13],"_links":{"self":[{"href":"https:\/\/www.lambiek.eu\/blog\/wp-json\/wp\/v2\/posts\/248"}],"collection":[{"href":"https:\/\/www.lambiek.eu\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.lambiek.eu\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.lambiek.eu\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.lambiek.eu\/blog\/wp-json\/wp\/v2\/comments?post=248"}],"version-history":[{"count":3,"href":"https:\/\/www.lambiek.eu\/blog\/wp-json\/wp\/v2\/posts\/248\/revisions"}],"predecessor-version":[{"id":254,"href":"https:\/\/www.lambiek.eu\/blog\/wp-json\/wp\/v2\/posts\/248\/revisions\/254"}],"wp:attachment":[{"href":"https:\/\/www.lambiek.eu\/blog\/wp-json\/wp\/v2\/media?parent=248"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.lambiek.eu\/blog\/wp-json\/wp\/v2\/categories?post=248"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.lambiek.eu\/blog\/wp-json\/wp\/v2\/tags?post=248"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}