Friday, November 3, 2017

SMF service - properties

An usually important part of a SMF service or instance metadata is a series of key / values entries known as service properties, which can be single-valued (the propval tag) or multi-valued (the property, typename_list and value_node tags) and must always appear within a property_group tag to the bottom of an instance description or service description, respectively depending on if the properties refer to an specific instance or are common to all instances (factored out up one level to the abstract service description, which is the common parent description of all of its concrete instances descriptions).

Example:

...

<service type="service" version="..."
 name="..." >

  <instance enabled="..." name="default" />
  <single_instance />  

  ... 
 
  <!-- single-instance anyway --> 
  <property_group type="application" name="..." >

    <!-- single-valued properties -->
    <propval type="..." name="..." value="..." /> 
    ... 

    <!-- multi-valued properties -->
    <property type="typename" name="..." >
      <typename_list >
        <value_node value="..." />
        <value_node value="..." />
        ...
      </typename_list >
    </property > 
    ... 

  </property_group > 

  ...

</service >
 
<service type="service" version="..."
 name="..." >

  <instance enabled="..." name="..." >

    ...

    <property_group type="application" name="..." > 

      <!-- single-valued properties -->
      <propval type="..." name="..." value="..." /> 
      ... 

      <!-- multi-valued properties -->
      <property type="typename" name="..." >
        <typename_list >
          <value_node value="..." />
          <value_node value="..." />
          ...
        </typename_list >
      </property > 
      ... 

    </property_group > 

    ... 

  </instance >

  <instance enabled="..." name="..." >

    ...

    <!-- instance specific 1st property group -->
    <property_group type="application" name="..." >

      <!-- single-valued properties -->
      <propval type="..." name="..." value="..." /> 
      ... 

    <property_group /> 

    <!-- instance specific 2nd property group -->
    <property_group type="application" name="..." >

      <!-- single-valued properties -->
      <propval type="..." name="..." value="..." /> 
      ... 

      <!-- multi-valued properties -->
      <property type="typename" name="..." >
        <typename_list >
          <value_node value="..." />
          <value_node value="..." />
          ...
        </typename_list >
      </property > 
      ... 

    </property_group > 

    ... 

  </instance >

  ...

  <!-- service-level/shared property group --> 
  <property_group type="application" name="..." >

    <!-- single-valued properties -->
    <propval type="..." name="..." value="..." /> 
    ... 

    <!-- multi-valued properties -->
    <property type="typename" name="..." >
      <typename_list >
        <value_node value="..." />
        <value_node value="..." />
        ...
      </typename_list >
    </property > 
    ... 

  </property_group >

  ...

</service >

... 


NOTE
The above example is a simplified excerpt of a service bundle description containing two services descriptions, one single-instance and one multi-instance. For a single-instance service, there's no real purpose on having instance specific properties (the instance "easily can get confused" with the service). The type attribute of the property_group tag should be set to application, meaning that it's service specific (internal) and the framework shouldn't care about it. Lastly, there can be more than one property group, which may help better organization of properties, if needed.

NOTE
The datatype documentation for properties isn't very easily found, but in the scf_value_create(3SCF) man page. Possible values are:

count          : unsigned int (64-bits)
integer        : int (64-bits)
boolean        : true or false (bit)
astring        : Null-terminated ASCII string
ustring        : Null-terminated utf-8 string
net_address_v4 : IPv4 address
net_address_v6 : IPv6 address
net_address    : net_address_v4 or net_addrss_v6
hostname       : fully-qualified domain name (FQDN)
host           :
hostname or net_address
time
           :
int, 64-bits seconds or 32-bits nanoseconds
fmri           : obvious
uri            : obvious
opaque         : a byte sequence

NOTE
Sometime it's good to know that after a service has been integrated into the SMF framework, the enabled property is automatically located on a special property group called general. This may be of particular interest when interactively creating a new instance of a service.