このセクションでは、IPS パッケージを使用して複数のファイルを配布し、これらの複数ファイルを 1 つのファイルにまとめる SMF サービスを配布する方法を説明します。
次のパッケージマニフェストは、自己アセンブリサービスを配布します。isvapp-self-assembly サービスは、/opt/isvapp/config.d ディレクトリ内のファイル inc1、inc2、および inc3 を 1 つのファイル /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 Server 構成を参照してください。
次のスクリプトは、サービスの構成アセンブリを行います。exit 呼び出しのコメントが 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 マイルストーンサービスへのデフォルトの依存関係を指定します。1 度だけ実行されるサービスの提供に示すこの依存関係セクションを変更することがあります。
<?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 サービスが一時的に無効化されていることが表示され、ファイルアセンブリが完了しているというメソッド出口コメントがログファイルに出力されます。
1 度だけ実行されるサービスの提供で示す例とは対照的に、isvapp-self-assembly サービスを有効にすると、サービスがふたたび無効になる前にサービス起動スクリプトが再度実行されます。