首页 > 代码库 > svcs (service status) 和 svcadm (service administration) 使用

svcs (service status) 和 svcadm (service administration) 使用

1. svcs  显示服务实例的状态信息

svcs - report service status  显示服务状态命令

DESCRIPTION
The svcs command displays information about service instances as recorded in the service configuration repository.

该命令显示记录在服务配置库中的服务实例信息

The first form of this command prints one-line status listings for service instances

specified by the arguments. Each instance is listed only once.

With no arguments, all enabled service instances, even if temporarily disabled, are listed with the columns indicated below.

 

The second form prints one-line status listings for the dependencies or dependents of the service instances

specified by the arguments.

 

The third form prints detailed information about specific services and instances.

 

The fourth form explains the states of service instances.
For each argument, a block of human-readable text is displayed which explains what state the service is in, and why it is in that state. 
With no arguments, problematic services are described.

 

Error messages are printed to the standard error stream.

The output of this command can be used appropriately as input to the svcadm(1M) command.

参数:

-a  列出所有的服务(未使能的服务也显示 -- including disabled ones)

-d  列出给定服务实例依赖的服务实例

-D  列出依赖给定服务实例的服务实例

-l    显示给定服务实例所有可得到的信息,每个属性显示一行

-xv   x显示服务状态的解释,v显示每条解析的附加信息

 

2. svcadm 管理服务实例

NAME
  svcadm - manipulate service instances 管理、操控服务实例

DESCRIPTION
  svcadm issues requests for actions on services executing within the service management facility (see smf(5)). 
Actions for a service are carried out by its assigned service restarter agent. 

发出关于服务执行的动作请求

The default service restarter is svc.startd(see svc.startd(1M)).

--------------------------------------

选项OPTIONS:

-v  打印动作的详细信息

--------------------------------------

 

-------------------------------------------------------------------------------------------------

SUBCOMMANDS :

Common Operations -- 常用操作

  The subcommands listed below are used during the typical administration of a service instance. 下面列出的子命令,在一个服务实例的通常管理过程中被使用

  For subcommands taking one or more operands, if the operand specifies a service (instead of a service instance),

  and that service has only a single instance, svcadm operates on that instance.

  子命令接受一个或多个操作符,如果操作符对象指定一个服务(而不是一个服务实例),并且该服务仅有单个实例,那么svcadm将在那个实例上运行

  

  If an abbreviated FMRI (a fault management resource identifier) or pattern matches more than one service,

  a warning message is displayed and that operand is ignored. See smf(5).

  如果一个缩写FMRI或模式匹配多个服务,一个警告消息将被显示,并且该操作符对象将被忽略

 

  In the case that the service has more than one instance, svcadm return a non-zero exit status.

  在服务有多个实例的情况下,svcadm将返回一个非零的退出状态

 

1)enable [-rst] {FMRI | pattern}. . .  启用服务实例

Enables the service instances specified by the operands.

For each service instance, the assigned restarter will try to bring it to the online state.

对于每个实例,分配的重启器将设法把它带到在线状态

 

This action requires permission to modify the "general" property group of the service instance (see smf_security(5)).

该动作要求有修改服务实例“general”属性组的权限

 

If the -r option is specified, svcadm enables each service instance and recursively enables its dependencies.

如果指定了-r选项,svcadm启用每个服务实例,并递归地开启它的依赖

 

If the -s option is specified, svcadm enables each service instance and then waits for each service instance to enter the online or degraded state

............, 然后等待每个服务实例进入在线或退化状态。如果svcadm能够确定服务在没有管理员干预情况下无法达到这些状态,它会早早地返回

svcadm will return early if it determines that the service cannot reach these states without administrator intervention.

 

If the -t option is specified, svcadm temporarily enables each service instance.

Temporary enable only lasts until reboot.  -t 选项临时开启服务实例,重启后消失

This action requires permission to modify the "restarter_actions" property group of the service instance (see smf_security(5)).

By default, enable is persistent across reboot.  默认enable(使能 -- 启用)是持久的、跨重启的

 

 

2)disable [-st] {FMRI | pattern}. . .   禁用服务实例

Disables the service instance specified by the operands.
For each service instance, the assigned restarter willtry to bring it to the disabled state.

This action requires permission to modify the "general" property group of the service instance (see smf_security(5)).

 

If the -s option is specified, svcadm disables each service instance and then waits for each service instance to enter the disabled state. 

-s 选项,关闭服务实例,并等待每个服务实例进入禁用状态
svcadm will return early if it determines that the service cannot reach this state without administrator intervention.

 

 

If the -t option is specified, svcadm temporarily disables each service instance. Temporary disable only lasts until reboot.

This action requires permission to modify the "restarter_actions" property group of the service instance (see smf_security(5)).

By default, disable is persistent across reboot. 默认disable(禁用) 也是持久的、跨多次重启的

 

 

3)restart {FMRI | pattern}. . .  请求操作符对象指定的服务实例重启

Requests that the service instances specified by the operands be restarted. 

This action requires permission to modify the "restarter_actions" property group of the service instance (see smf_security(5)).

This subcommand can restart only those services that are in the online or degraded states, as those states are defined in smf(5).

 

 

4)refresh {FMRI | pattern}. . .  使用当前配置值,更新服务的运行配置快照

For each service instance specified by the operands, requests that the assigned restarter update the service‘s running configuration snapshot

with the values from the current configuration. 

对于操作符对象指定的每个实例,使用当前配置的值,请求指定的重启器更新服务的运行配置快照
Some of these values take effect immediately (for example, dependency changes). 
Other values do not take effect until the next service restart.  一些值会立即生效,还有一些值直到服务下次重启后,才会生效

If the service is managed by svc.startd(1M), the refresh method will be invoked if it exists to request the service reread its own configuration. 

如果服务被svc.startd管理,且如果该服务存在请求重读自己的自己的配置,那么refresh方法将被调用
For other restarters, see the restarter documentation.

This action requires permission to modify the "restarter_actions" property group of the service instance (see smf_security(5)).

 

 

5)clear {FMRI | pattern}. . .

For each service instance specified by the operands, if the instance is in the maintenance state,

signal to the assigned restarter that the service has been repaired.


If the instance is in the degraded state, request that the assigned restarter take the service to the online state. 
This action requires permission to modify the "restarter_actions" property group of the service instance (see smf_security(5)).

 

 

 

Exceptional Operations -- 例外操作
The following subcommands are used for service development and temporary administrative manipulation.

1)mark [-It] instance_state {FMRI | pattern}. . .  标记服务到维护、退化状态

If instance_state is "maintenance", then for each service specified by the operands, svcadm requests that the assigned restarter place the service in the maintenance state.

 如果命令中instance_state占位符指定的是"maintenance",对于通过操作对象指定的每个服务,svcadm请求指定的重启器把该服务置为"maintenance"状态

If instance_state is "degraded", then for services specified by the operands in the online state, svcadm requests that the restarters assigned to the services
move them into the degraded state.

 

If the -I option is specified, the request is flagged as immediate. 如果指定-I选项,请求将被标注为立即

The -t option is only valid for maintenance requests. -t 选项,仅对维护请求有效
When this option is specified, the request is flagged as temporary, and its effect will only last until the next reboot. 当指定-t选项时,请求被标注为临时

 

 

2)milestone [-d] milestone_FMRI

If milestone_FMRI is the keyword "none", all services other than the master restarter, svc:/system/svc/restarter:default, will be temporarily disabled.

如果milestone_FMRI取值“none”,所有的服务(除了主重启器,svc:/system/svc/restarter:default,都将被临时禁用)

 

If milestone_FMRI is the keyword "all", temporary enable and disable requests for all services will be nullified. nullify 使无效,使作废,使不起作用

 

milestone_FMRI取“all”,对所有服务的临时启用、禁用请求,都将无效

 

If milestone_FMRI is one of the following:

  svc:/milestone/single-user:default
  svc:/milestone/multi-user:default
  svc:/milestone/multi-user-server:default

then temporary enable and disable requests for the indicated service and all services it depends on (directly or indirectly) will be nullified.
All other services will be temporarily disabled.  对指定服务它直接间接依赖的所有服务的临时启用、禁用请求,都将无效

 

Changing the system‘s current milestone with the "milestone" subcommand will not change the current run level of the system. 

使用milestone子命令改变系统当前的“里程碑”不会改变系统的当前运行级别
To change the system‘s run level, invoke/sbin/init directly.

This action requires permission to modify the "options_ovr" property group of the svc:/system/svc/restarter:default service instance (see smf_security(5)).

The -d option immediately changes the milestone to the requested milestone, as above.

Additionally, it makes the specified milestone the default boot milestone,which persists across reboot.

The default milestone is defined by the options/milestone property on the master restarter, svc:/system/svc/restarter:default.
If this property is absent, "all" is the default.

This action requires permission to modify the "options" propertygroup of the svc:/system/svc/restarter:default service instance (see smf_security(5)).

 

 

Operands
The following operands are supported:

FMRI

  An FMRI that specifies one or more instances.
  FMRIs can be abbreviated by specifying the instance name, or the trailing portion of the service name.  能够通过指定实例名或裁剪服务名的部分,被缩写

  For example, given the FMRI:

    svc:/network/smtp:sendmail

  All the following are valid abbreviations:

    sendmail
    :sendmail
    smtp
    smtp:sendmail
    network/smtp

  While the following are invalid:

    mail
    network
    network/smt

  If the FMRI specifies a service, then the command applies to all instances of that service.

  Abbreviated forms of FMRIs are unstable, and should not be used in scripts or other permanent tools.

  注:FMRI的缩写形式是不稳定的,在脚本或其他永久性工具中不应该被使用

 

 

pattern

  A pattern that is matched against the FMRIs of service instances according to the "globbing" rules described by fnmatch(5). 
  

  If the pattern does not begin with "svc:", then "svc:/" is prepended. 如果模式没有以"svc:"开头,那么"svc:"将被自动加到前面

  If an abbreviated FMRI or pattern matches more than one service, a warning message is displayed and that operand is ignored.

  如果一个FMRI缩写或模式匹配超过一个服务,那么将显示一个警告消息并忽略该操作数

 

EXAMPLES


Example 1 Restarting a Service Instance 重启一个服务实例

The following command restarts the NFS server. The full FMRI for the default service instance is:
svc:/network/nfs/server:default

However, you can abbreviate the full FMRI as follows:

# svcadm restart nfs/server

 

Example 2 Disabling the Standard HTTP Server 禁用HTTP Server服务

The following command disables the standard HTTP server, using an abbreviated FMRI:

$ svcadm disable http

 

Example 3 Enabling an Instance and Its Dependent Instances 启用一个服务实例及其它的依赖服务实例

The following command enables the foo:bar instance, and all instances on which it depends:

$ svcadm enable -r foo:bar

 

Example 4 Synchronously enabling an instance 同步地启用一个服务实例

The following command enables the foo:bar instance.

The command will not return until the instance comes online or svcadm determines it is not possible for the service to come online.

直到该实例在线,或svcadm确定该服务不可能在线(启用过程中,一些依赖不成功等,造成启用失败),该命令才会返回

$ svcadm enable -s foo:bar

 

Example 5 Restricting and Restoring the Running Services

The following command restricts the running services to single user mode:

# svcadm milestone milestone/single-user

The following command restores the running services:

# svcadm milestone all

 

EXIT STATUS
The following exit values are returned:

  0    Successful completion.

  1    A fatal error occurred.

      One or more error messages are displayed on standard error.

  2    Invalid command line options were specified.

  3    svcadm determined that a service instance that it was waiting for could not reach the desired state 
      without administrator intervention due to a problem with the service instance itself.

  4    svcadm determined that a service instance that it was waiting for could not reach the desired state 
        without administrator intervention due to a problem with the service‘s dependencies.

 

ATTRIBUTES

____________________________________
| ATTRIBUTE TYPE    | ATTRIBUTE VALUE |
|___________________________________|
| Availability        | SUNWcsu         |
|___________________________________|
| Interface Stability    | See below.             |
|___________________________________|

The interactive output is Uncommitted. The invocation and non-interactive output are Committed.

 

SEE ALSO
svcprop(1), svcs(1), inetd(1M), init(1M), svccfg(1M),svc.startd(1M), libscf(3LIB), contract(4), attributes(5), smf(5), smf_security(5)

 

NOTES
The amount of time svcadm will spend waiting for services and their dependencies to change state is implicitly limited by their method timeouts. 

svcadm等待服务和它们的依赖改变状态的时间,被这些方法的超时时间隐含限制

For example, a service using the default restarter whose start method hangs will be transitioned to the maintenance state when its timeout expires.

svcadm will then consider it impossible for this service to come online without administrator intervention.

一个使用默认启动器的服务(把该服务的状态转换到维护状态),当它的超时过期时,该服务的start方法暂停(中止、悬挂、停摆)

 

Attempts to synchronously enable a service which depends(directly or indirectly) on a file may fail with an exit status 
indicating that dependencies are unsatisfied if the caller does not have the privileges necessary to search the directory containing the file. 

试图同步启用一个服务(该服务直接或间接依赖一个文件)也许会失败,带一个退出标志(暗示它的依赖没有满足,如果调用者没有搜索包含该文件目录的权限)

This limitation may be removed in a future Solaris release.

 

====================================================

http://angellin0.iteye.com/blog/681879 上摘录的启用服务的例子

1. 启用FTP服务:
# svcadm enable /network/ftp

此时查看FTP服务状态:
# svcs -l network/ftp

默认情况下,root用户无法登录,需要修改/etc/ftpd/ftpusers文件,把root那行前面加个#注释掉就可以了。

2. SSH
默认SSH是开启的。但是root用户无法登录,需要修改/etc/ssh/sshd_config,把里面的 PermitRootLogin改为 yes,再重启ssh服务,
重启命令:
# svcadm restart network/ssh


3. 重启网卡
以前修改/etc/hosts文件的IP后都是通过重启机器来使设置生效的,现在也可以通过下面的命令让它生效,无需重启机器。
# svcadm restart physical

 

svcs (service status) 和 svcadm (service administration) 使用