Less known Solaris Features: Resource Management - Part 6: Resource Management and SMF

A few days ago, i wrote about the Service Management Facility, a framework to manage services in Solaris. This framework enables Solaris to start services in a more intelligent manner. Albeit almost all services started by SMF are member of the project system it doesn´t have to be this way. You can specify the project used for a service.  

Assigning a project to an already running service

This method is described in the SMF FAQ. I will use an practical example. You run a server in the internet, but it´s under high load from spam bot. You´ve already created a project sendmail and configured the resource management. At the moment, the sendmail runs in the system project:

# ps -o pid,project,args  -ef | grep "sendmail" | grep -v "grep"<br />
  648   system /usr/lib/sendmail -Ac -q15m<br />
  647   system /usr/lib/sendmail -bd -q15m -C /etc/mail/local.cf

How do you start it as a part of a different project? Okay, check for an already configured project.

# svcprop -p start/project smtp:sendmail
svcprop: Couldn't find property `start/project' for instance `svc:/network/smtp:sendmail'.

Okay, nothing defined … this makes it a little bit harder, because we can´t set the project only at the moment, as there is a bug in the restarter daemon. You need a fully populated start method. If the svcprop run delivers you the name of a project, you can ignore the next block of commands:

svccfg -s sendmail setprop start/user = astring: root<br />
svccfg -s sendmail setprop start/group = astring: :default<br />
svccfg -s sendmail setprop start/working_directory = astring: :default<br />
svccfg -s sendmail setprop start/resource_pool = astring: :default<br />
svccfg -s sendmail setprop start/supp_groups = astring: :default<br />
svccfg -s sendmail setprop start/privileges = astring: :default<br />
svccfg -s sendmail setprop start/limit_privileges = astring: :default<br />
svccfg -s sendmail setprop start/use_profile = boolean: false

Okay, now we can set the project property of the start method:

svccfg -s smtp/sendmail setprop start/project = astring: sendmail

Now we have to refresh the configuration of the service. After refreshing the service we can check the property:

# svcadm refresh sendmail<br />
#  svcprop -p start/project sendmail<br />
sendmail

Okay, the new properties are active. Now restart the service:

# svcadm restart sendmail

Let´s check for the result:

# ps -o pid,project,args  -ef | grep "sendmail" | grep -v "grep"<br />
 1539 sendmail /usr/lib/sendmail -bd -q15m -C /etc/mail/local.cf<br />
 1540 sendmail /usr/lib/sendmail -Ac -q15m

Configuring the project in a SMF manifest

Okay, you have written your own application and want to run it under the control of the SMF. You can define the project for the service in the manifest. You have to define the project in the start method of the manifest:

&lt;exec_method type='method' name='start' exec='/path/to/method start' timeout_seconds='0' &gt;<br />
        <b>&lt;method_context project=projectname' &gt;</b><br />
        &lt;method_credential user='someuser' /&gt;<br />
        &lt/method_context&gt;<br />
&lt;/exec_method&gt;

That´s all. The important part is the seond row of the fragment. We define the project as a part of the startup method context. The rest is done as described in the SMF tutorial.