Go to main content

Packaging and Delivering Software With the Image Packaging System in Oracle® Solaris 11.4

Exit Print View

Updated: November 2018

Assembling a Custom File from Fragment Files

This section shows how to use an IPS package to deliver multiple files and deliver an SMF service that assembles these multiple files into one file.

The following package manifest delivers the self-assembly service. The isvapp-self-assembly service assembles the files inc1, inc2, and inc3 in the /opt/isvapp/config.d directory into the single /opt/isvapp/isvconf file.

set name=pkg.fmri value=isvappcfg@1.0
set name=pkg.summary value="Deliver isvapp config files and assembly service"
set name=pkg.description \
    value="This example package delivers a directory with fragment configuration
 files and a service to assemble them."
set name=org.opensolaris.smf.fmri value=svc:/site/isvapp-self-assembly \
set name=variant.arch value=i386
file lib/svc/manifest/site/isvapp-self-assembly.xml \
    path=lib/svc/manifest/site/isvapp-self-assembly.xml owner=root group=sys \
    mode=0444 restart_fmri=svc:/system/manifest-import:default
file lib/svc/method/isvapp-self-assembly.sh \
    path=lib/svc/method/isvapp-self-assembly.sh owner=root group=bin \
dir  path=opt/isvapp owner=root group=bin mode=0755
dir  path=opt/isvapp/config.d owner=root group=bin mode=0755
file opt/isvapp/config.d/inc1 path=opt/isvapp/config.d/inc1 owner=root \
    group=bin mode=0644
file opt/isvapp/config.d/inc2 path=opt/isvapp/config.d/inc2 owner=root \
    group=bin mode=0644
file opt/isvapp/config.d/inc3 path=opt/isvapp/config.d/inc3 owner=root \
    group=bin mode=0644
file opt/isvapp/isvconf path=opt/isvapp/isvconf owner=root group=bin mode=0644
depend fmri=pkg:/shell/ksh93@ type=require
depend fmri=pkg:/system/core-os@5.12-5.12 type=require

If you want to allow other packages to deliver configuration files with these same names, add overlay and preserve attributes to the files. See Delivering a File That Is Also Delivered by Another Package for an example.

To reassemble the configuration file when new fragments of the configuration are installed, removed, or updated, add restart_fmri or refresh_fmri actuators to the configuration files. See Apache Web Server Configuration for an example.

The following script does the configuration assembly for the service. The comment in the exit call will be displayed by the svcs command.


# Load SMF shell support definitions
. /lib/svc/share/smf_include.sh

# If files exist in /opt/isvapp/config.d,
# and if /opt/isvapp/isvconf exists,
# merge all into /opt/isvapp/isvconf

# After this script runs, the service does not need to remain online.
smf_method_exit $SMF_EXIT_TEMP_DISABLE done "/opt/isvapp/isvconf assembled"

The following listing shows the SMF service manifest for this example. This manifest was created by using the svcbundle command and specifies the default dependency on the multi-user milestone service. You might want to change this dependency section as shown in Delivering a Service that Runs Once.

<?xml version="1.0" ?>
<!DOCTYPE service_bundle
  SYSTEM '/usr/share/lib/xml/dtd/service_bundle.dtd.1'>
    Manifest created by svcbundle (2015-Mar-30 13:22:37-0700)
<service_bundle type="manifest" name="site/isvapp-self-assembly">
    <service version="1" type="service" name="site/isvapp-self-assembly">
            The following dependency keeps us from starting until the
            multi-user milestone is reached.
        <dependency restart_on="none" type="service"
            name="multi_user_dependency" grouping="require_all">
            <service_fmri value="svc:/milestone/multi-user"/>
        <exec_method timeout_seconds="60" type="method" name="start"
            The exec attribute below can be changed to a command that SMF
            should execute to stop the service.  See smf_method(7) for more
        <exec_method timeout_seconds="60" type="method" name="stop"
            The exec attribute below can be changed to a command that SMF
            should execute when the service is refreshed.  Services are
            typically refreshed when their properties are changed in the
            SMF repository.  See smf_method(7) for more details.  It is
            common to retain the value of :true which means that SMF will
            take no action when the service is refreshed.  Alternatively,
            you may wish to provide a method to reread the SMF repository
            and act on any configuration changes.
        <exec_method timeout_seconds="60" type="method" name="refresh"
        <property_group type="framework" name="startd">
            <propval type="astring" name="duration" value="transient"/>
        <instance enabled="true" name="default"/>
                <loctext xml:lang="C">
                    ISV app self-assembly
                <loctext xml:lang="C">
                    Assembly of configuration fragment files for ISV app.

Use the svccfg validate command to make sure the service manifest is valid.

After you publish and install the package, the svcs command shows that the isvapp-self-assembly service is temporarily disabled, and the log file contains the method exit comment that the file assembly is complete.

In contrast to the example shown in Delivering a Service that Runs Once, when you enable the isvapp-self-assembly service, the service start script runs again before the service is again disabled.