Go to main content

Developing System Services in Oracle® Solaris 11.4

Exit Print View

Updated: November 2020
 
 

How to Create a Stencil Service to Generate Multiple Configuration Files

  1. Define multiple configfile type property groups.

    Each configfile type property group describes a single configuration file for the service. To create multiple configuration files, define a separate configfile type property group for each configuration file.

    Each configfile type property group in a single service must specify a different configuration file: a different value for the path property. Values of the stencil, mode, owner, and group properties can be the same or different.

  2. Add a defines property group to each configfile type property group.

    To add configuration that is unique to each configuration file, specify the unique configuration in a defines property group in each configfile type property group. A defines property group is type application. A defines property group is a nested property group: a child of the configfile type property group.

    A defines property group defines name/value pairs to preload before parsing the stencil. See Example 10, Creating Multiple Configuration Files Using a Single Stencil File below.

  3. Create a stencil file.

    The stencil file can be the same or different in each configfile type property group. If the structure of two configuration files is the same, you can use the same stencil file for each configuration file, including a line such as the following in the stencil file to add unique values to each configuration file:

    # $%[property-name], printing one value per line if multiple values are defined
    $%{$%[property-name]:,\n}

    In Example 10, Creating Multiple Configuration Files Using a Single Stencil File, you can see how property-name selects different values for each configuration file defined in each defines property group.

    Put your stencil file in the /lib/svc/stencils directory, and specify the name of the stencil file as the value of the stencil property in the configfile type property group.

Example 10  Creating Multiple Configuration Files Using a Single Stencil File

This example has the following features:

  • Properties named host_keys/dsa and host_keys/rsa are defined for the service.

  • Two configfile type property groups specify two different configuration files: /etc/ssh/hostkey_1 and /etc/ssh/hostkey_2.

  • Within each configfile type property group, a defines property group defines the key property that provides the appropriate host_keys property value to the configuration file.

<property_group type="application" name="host_keys">
    <propval type="astring" name="dsa" value="key1" />
    <property type="astring" name="rsa">
        <astring_list>
            <value_node value="key2" />
            <value_node value="key3" />
        </astring_list>
    </property>

    <property_group type="configfile" name="host_key_1">
        <propval type="astring" name="mode" value="0444" />
        <propval type="astring" name="path" value="/etc/ssh/hostkey_1" />
        <propval type="astring" name="stencil" value="sshhostkey.stencil" />

        <property_group type="application" name="defines">
            <propval type="astring" name="key" value="host_keys/dsa" />
        </property_group>
    </property_group>

    <property_group type="configfile" name="host_key_2">
        <propval type="astring" name="mode" value="0444" />
        <propval type="astring" name="path" value="/etc/ssh/hostkey_2" />
        <propval type="astring" name="stencil" value="sshhostkey.stencil" />

        <property_group type="application" name="defines">
            <propval type="astring" name="key" value="host_keys/rsa" />
        </property_group>
    </property_group>
</property_group>

The stencil file includes the following line, where key is the property defined in each defines property group:

# $%[key], printing one key per line if multiple are defined
$%{$%[key]:,\n}

When the svcio utility reads the stencil file and service property values, the following configuration files are created:

$ cat /etc/ssh/hostkey_1
# host_keys/dsa, printing one key per line if multiple are defined
key1
$ cat /etc/ssh/hostkey_2
# host_keys/rsa, printing one key per line if multiple are defined
key2
key3