本节介绍了如何使用 IPS 软件包提供多个文件以及提供将这些文件组装为一个文件的 SMF 服务。
以下软件包清单可提供自组装服务。isvapp-self-assembly 服务将 /opt/isvapp/config.d 目录中的文件 inc1、inc2 和 inc3 组装为一个 /opt/isvapp/isvconf 文件。
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 \ value=svc:/site/isvapp-self-assembly:default 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 \ mode=0755 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@93.21.0.20110208-0.175.2.0.0.37.1 type=require depend fmri=pkg:/system/core-os@0.5.11-0.175.2.0.0.37.0 type=require
如果要允许其他软件包提供具有相同名称的配置文件,可向这些文件添加 overlay 和 preserve 属性。有关示例,请参见提供其他软件包也提供的文件。
要在安装、删除或更新配置的新片段时重新组装该配置文件,可向配置文件添加 restart_fmri 或 refresh_fmri 执行器。有关示例,请参见Apache Web 服务器配置。
以下脚本执行该服务的配置组装工作。退出调用中的注释将通过 svcs 命令显示。
#!/bin/sh # 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"
以下列表显示了此示例的 SMF 服务清单。此清单通过使用 svcbundle 命令创建并指定 multi-user 里程碑服务的默认依赖项。您可能要更改此依赖项部分,如交付运行一次的服务所示。
<?xml version="1.0" ?> <!DOCTYPE service_bundle SYSTEM '/usr/share/lib/xml/dtd/service_bundle.dtd.1'> <!-- Manifest created by svcbundle (2014-Apr-18 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"/> </dependency> <exec_method timeout_seconds="60" type="method" name="start" exec="/lib/svc/method/isvapp-self-assembly.sh"/> <!-- The exec attribute below can be changed to a command that SMF should execute to stop the service. See smf_method(5) for more details. --> <exec_method timeout_seconds="60" type="method" name="stop" exec=":true"/> <!-- 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(5) 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" exec=":true"/> <property_group type="framework" name="startd"> <propval type="astring" name="duration" value="transient"/> </property_group> <instance enabled="true" name="default"/> <template> <common_name> <loctext xml:lang="C"> ISV app self-assembly </loctext> </common_name> <description> <loctext xml:lang="C"> Assembly of configuration fragment files for ISV app. </loctext> </description> </template> </service> </service_bundle>
使用 svccfg validate 命令确保服务清单有效。
发布并安装软件包后,svcs 命令会显示 isvapp-self-assembly 服务被临时禁用,而且日志文件会包含方法退出注释,说明文件组装已完成。
与交付运行一次的服务中显示的示例不同,当您启用 isvapp-self-assembly 服务时,该服务会在再次禁用该服务之前开始再次运行脚本。