Solaris SMF: Define File Dependency

Solaris SMF: Define File Dependency

One of the biggest benefits of migrating to the Service Management Framework is that we can introduce dependencies to a services, these dependencies can be other services which is very valuable, however they can also be file based.  This can be used in a number of ways, say for example you have some application trees that live on some NFS mounts, in the event that the mount hasn’t been successfully mounted it will still attempt to start the service.  However if we make our service dependent on the file, then if the file doesn’t exist it won’t even attempt to start the service.

MANUAL PROCESS

We can use svccfg to navigate the service tree and set the properties that we require.  The big gotcha here comes when you are defining the file (line 5), notice we define it including file://localhost/ as part of the path, if you don’t include this it will be unable to locate the file and your test will fail.  In this example we are assuming that this configuration file is needed for the service to start.

# svccfg -s application/xvfb
svc:/application/xvfb> select default
svc:/application/xvfb:default> addpg config_file dependency
svc:/application/xvfb:default> setprop config_file/grouping = astring: require_all
svc:/application/xvfb:default> setprop config_file/entities = fmri: file://localhost/etc/xvfb.conf
svc:/application/xvfb:default> setprop config_file/type = astring: path
svc:/application/xvfb:default> setprop config_file/restart_on = astring: refresh
svc:/application/xvfb:default> end

STREAMLINED COMMANDS

We can also execute the same actions without entering the SMF

# svccfg -s application/xvfb:default addpg config_file
# svccfg -s application/xvfb:default setprop config_file/grouping = astring: require_all
# svccfg -s application/xvfb:default setprop config_file/entities = fmri: file://localhost/etc/xvfb.conf
# svccfg -s application/xvfb:default setprop config_file/type = astring: path
# svccfg -s application/xvfb:default setprop config_file/restart_on = astring: none

INCLUDE IN A SERVICE DEFINITION

Now of course if your service doesn’t exist yet, then the best way is to include it in the service definition.  Dependencies belong inside of the instance tags (shown below).

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

Here is how the above example of a file-based dependency would look inside of a service definition.

<dependency name='config_file' grouping='require_all' restart_on='refresh' type='
<service_fmri value='file://localhost/etc/xvfb-securitypolicy.conf'/>
</dependency>

Also keep in mind when using this approach it is invaluable to use the svccfg utility to validate the structure of your service definition.

svccfg validate xvfb.xml

TESTING

Now of course all of this is without any value if we don’t test the outcome.  The best way to do this is by moving your file (so that it doesn’t exist) and restarting the service.  Of course this goes without saying that this will cause downtime (as we are trying to) so please ensure that you have coordinated everything necessary.