Go to main content

手册页部分 8:系统管理命令

退出打印视图

更新时间: 2022年7月27日 星期三
 
 

svcbundle(8)

名称

svcbundle - 创建 SMF 服务束

用法概要

svcbundle [-i | -o output_file] -s name=value...
svcbundle help [name]

描述

svcbundle 命令用于生成 SMF 清单。此清单是通过多个 –s 选项指定的。要生成清单,必须指定 service-namestart-method。其他 NV 对是可选的,允许用户为服务指定更多详细信息。svccfg(8) 用于验证命令是否会对生成的清单运行,以检测任何模板冲突。

还可使用 svcbundle 生成配置文件。请参见下文中的 bundle-type

第二个用法概要会在标准输出上列显帮助消息,并列出所有合法名称。此外,还可以指定 help 以及一个名称以查看有关该名称的合法值的讨论。

为了降低用户的负担,svcbundle 会在生成清单时进行多项假设以简化操作。如果这些假设对于应用程序不正确,则可以编辑生成的清单:

  • 生成的清单可与主重启程序 svc.startd(8) 配合使用。

  • 生成对 svc:/milestone/multi-user 的依赖性,以免服务过早启动。有关例外情况,请参见下文的 rc-script。In order to have a service start earlier, the manifest may be edited to depend on any specific services or any of the milestones described in smf(7).

  • 服务束名称与提供给 service-name 的值相同。

  • Timeouts for all exec_methods will be 60 seconds unless specified using timeout.However, timeout is set to 0 for periodic/scheduled services if no timeout is specified.

通过使用 –i 选项,可以获取 svcbundle 以执行大量服务安装操作。它会将生成的清单保存在 /lib/svc/manifest/site 中或将配置文件保存在 /etc/svc/profile/site 中。生成的文件名是使用 –s service-name 指定的服务名称的基名,并且该文件会使用扩展名 .xml。警告:svcbundle 将用该名称覆盖任何现有文件。

然后,svcbundle 将重新启动 manifest-import 服务以处理新创建的文件,并将其合并到 SMF 中。对于清单,svcbundle 将等待服务进入一个最终状态(联机、禁用或维护之一)。在该等待期间开始时,svcbundle 将输出:

svcbundle: waiting for service to reach final_state state

...其中 final_state 为启用或禁用。出现该消息后,可以放心地中断 svcbundle

显然,要使用 –i 选项,需要具有足够的授权,以便在这些受限目录中创建文件,并重新启动 manifest-import 服务。请参见 smf_security(7)

扩展描述

本部分讨论名称/值 (NV) 对。

通过在命令行上使用多个 -s 选项,可以定义生成的整个服务束。每个 NV 对均采用格式 name=value,其中 namename 来自此列表:

bundle-type

要生成的服务束类型。合法值为 manifestprofile。缺省值为 manifest

duration

model 的同义词。

enabled(已启用)

指示是否应启用实例。合法值为 truefalse。缺省值为 true

model

设置服务模型。这是 startd/duration 属性的值。请参阅 svc.startd(8)。可将模型设置为以下值之一:

  • contract

  • daemoncontract 的同义词

  • child

  • waitchild 的同义词

  • transient

缺省值为 transient

instance-name

实例的名称。缺省值为 default

instance-property=pg_name:prop_name:prop_type:value
service-property=pg_name:prop_name:prop_type:value

这些选项用于在实例或服务中创建名为 pg_name 的属性组,该属性组的类型为应用程序。PG 将具有一个名为 prop_name 的属性,该属性具有一个类型为 prop_type 的值。通过多次调用 *-property,可以创建具有多个属性的属性组。可以使用一个或多个 *-property= 声明,也可以不使用该声明。如果属性组嵌套(因此应该是包括祖先的完整属性组名称)或者如果属性组或属性名称包含保留字符,则属性组名称和属性名称必须编码(请参见 smf(7))。

通过使用两个连续冒号,可以设置缺省属性类型。请参见下文的“示例”部分。对于清单,将使用缺省属性类型 astring。配置文件不需要指定该属性,因为该属性通常可以通过其他信息源确定。

rc-script=script_path:run_level

此 NV 对会导致 svcbundle 发出清单,以方便将传统的 rc 脚本转换为 SMF 服务。script_pathrc 脚本的路径,而 run_levelrc 脚本的运行级别(请参见 init(8))。script_path 用于生成清单中的开始和停止 exec_method 元素。exec 属性将设置为:

script_path %m

run_level 用于生成依赖项,以便使该脚本在引导过程中的适当时间运行。

refresh-method

刷新服务时要执行的命令。该值允许使用空格。该值可以包括带百分比符号 (%) 的方法标记,如 smf_method(7) 中所述。缺省值为 :true

service-name

服务的名称。该 NV 对是必需的。

start-method

启动服务时要执行的命令。该值允许使用空格。允许使用 smf_method(7) 中所述的带 % 的方法标记,该标记将放置在清单中,以供重启程序扩展。可以使用 :true。必须为清单指定该 NV 对,除非指定了 rc-script NV 对。配置文件不需要指定该 NV 对。

stop-method

停止服务时要执行的命令。该命令接受诸如 start-method 这类的值,同时,还接受 :kill:true 是瞬态服务的缺省值,而 :kill 是合同和子服务的缺省值。

timeout

The service will be set with a general method timeout in seconds if method specific timeout is not provided.The default timeout is 60 seconds and for periodic or scheduled services, the default value is 0 seconds which signifies no timeout for the exec method of the service.Also, method specific timeouts do not apply to periodic/scheduled services.

start-timeout

The service will be set with a timeout specified by user specifically for the start-method.

stop-timeout

The service will be set with a timeout specified by user specifically for the stop-method.

refresh-timeout

The service will be set with a timeout specified by user specifically for the refresh-method.

user

The service will run as the defined user rather than root.

Note that the user name is not validated by svcbundle(8) or required to exist on the system where svcbundle(8) is run.

group

The service will run as the defined group rather than root.

Note that the group name is not validated by svcbundle(8) or required to exist on the system where svcbundle(8) is run.

privileges

The service will run with the defined set of privileges.A privilege specification can include any of the predefined sets: basic, all and may use the extended policy specification and negation operations (to remove a privilege).See privileges(7) and smf_method(8)for details and syntax.

Note that the names of the privileges are not validated by svcbundle(8).

Periodic and Scheduled service attributes

The following attributes are used to create a periodic or scheduled service.

period

This NV pair is used to create a manifest for a periodic service.The value is used for the period, in seconds, when the start-method should run.

day

指定创建预定服务时的 'day' 约束。有关预定服务的详细信息,请参阅 svc.periodicd(8)

day_of_month

指定创建预定服务时的 'day_of_month' 约束。

delay

在首次调用启动方法之前,服务转换为联机状态后的秒数。

frequency

指定创建预定服务时的频率。

jitter

在启动方法运行之前,经过 period 之后的随机秒数的最大值。使用的最终秒数的范围为 0 到此属性值。

minute

指定创建预定服务时的 'minute' 约束。

month

指定创建预定服务时的 'month' 约束。

hour

指定创建预定服务时的 'hour' 约束。

interval

此 NV 对以及 start-method 对用于为预定服务创建清单。此对的值用于确定应该运行预定服务的频率。如果指定了此对,还需要指定 start-method,反之亦然。start-method 对的值将用于 scheduled_method 元素的 exec 属性。有关预定服务的详细信息,请参阅 svc.periodicd(8)

timezone

指定创建预定服务时的 'timezone' 值。

weekday_of_month

指定创建预定服务时的 'weekday_of_month' 约束。

week_of_year

指定创建预定服务时的 'week_of_year' 约束。

year

指定创建预定服务时的 'year' 约束。

选项

支持以下命令行选项:

–i

安装生成的文件。有关详细信息,请参见“说明”部分。

–o output_file

指定要创建的文件的名称。

–s name=value

指定名称/值对。有关详细信息,请参见“扩展说明”部分。

如果 –i–o 均未指定,则生成的文件将写入到 stdout。

示例

示例 1 为瞬态服务创建清单

以下命令将为一个简单的瞬态服务创建清单。由于瞬态服务是 svcbundle 的缺省值,因此,只能使用两个选项指定清单。

# svcbundle -s service-name=site/sneezy \
-s start-method=/lib/svc/method/sneezy
示例 2 为守护进程服务创建清单

以下命令将为一个守护进程服务创建清单。

# svcbundle -s service-name=site/sneezy \
-s start-method=/lib/svc/method/sneezy \
-s model=daemon
示例 3 使用 Stop 和 Refresh 命令为守护进程服务创建清单

以下命令将使用 stop 和 refresh 命令为一个守护进程服务创建清单。

# svcbundle -s service-name=site/sleepy \
-s start-method="/lib/svc/method/sleepy %m" \
-s stop-method="/lib/svc/method/sleepy %m" \
-s refresh-method="/lib/svc/method/sleepy %m" \
-s model=daemon
示例 4 使用实例属性创建清单

以下命令将使用实例属性创建清单。

# svcbundle -s service-name=system/happy \
-s start-method=/lib/svc/method/happy \
-s instance-property=config:velocity:count:50 \
-s instance-property=config:color:astring:red

生成的清单将使用包含两个属性(velocitycolor)的配置属性组创建服务实例。

示例 5 使用包含保留字符的实例属性创建清单

以下命令将使用实例属性创建清单。

# svcbundle -s service-name=system/happy \
-s start-method=/lib/svc/method/happy \
-s instance-property=config:velocity:count:50 \
-s instance-property=config:color%20name:astring:red

生成的清单将使用包含两个属性(velocitycolor name)的配置属性组创建服务实例。

示例 6 rc 脚本转换创建清单

以下命令将创建一个清单以帮助转换 rc 脚本。此示例假定 rc 脚本在多用户级别运行,并且不会启动守护进程。

# svcbundle -s service-name=doc \
-s rc-script=/etc/init.d/doc:2

谨慎的用户将修改 rc 脚本,使其包含 /lib/svc/share/smf_include.sh

示例 7 生成配置文件以修改服务属性

以下命令将生成配置文件以设置 grumpy 服务的 nfsmapid_domain 属性。

# svcbundle -s bundle-type=profile \
-s service-name=network/nfs/grumpy \
-s service-property=nfs-props:nfsmapid_domain:astring:grumpy
示例 8 使用缺省属性类型

以下命令会将 config/color 缺省值的属性类型设置为 astring

# svcbundle -s service-name=system/happy \
-s start-method=/lib/svc/method/happy \
-s instance-property=config:color::red
示例 9 Installing the Manifest

以下命令将使用 –i 选项安装清单。在此示例中,生成的清单将写入 /lib/svc/manifest/site/bashful.xml,因为 bashful 是服务名称的基名。

# svcbundle -i -s service-name=application/bashful \
-s start-method=/opt/bashful/start
svcbundle: waiting for application/bashful to reach enabled state
示例 10 Specifying user and privileges for service method

The following command creates a service that runs as a non-root user but with more than basic privileges.

# svcbundle -s service-name=site/myapp -s user=appuser \
-s privileges=basic,proc_chroot,{file_write}:/var/share/myapp*

属性

有关下列属性的说明,请参见 attributes(7)

属性类型
属性值
可用性
system/core-os
接口稳定性
Committed(已确定)

另请参见

svcs(1), service_bundle(5), attributes(7), smf(7), smf_method(7), smf_security(7), smf_template(7), init(8), svc.startd(8), svccfg(8), svc.periodicd(8)