---
title: "WASService的使用"
author: "acen.chen"
date: "2010-11-29T10:59:01Z"
tags: []
categories: ["企业架构"]
slug: "wasservice"
draft: false
lastmod: "2010-11-29T10:59:01Z"
id: 828015
url: "https://acen-chen.iteye.com/blog/828015"
---

WASService的使用

2010年06月11日 星期五 14:12

WASService 命令行工具允许您在 Linux 和 Windows 操作系统上为产品 Java 进程创建服务。

您可以为 WebSphere Application Server Java 进程创建服务。可能存在的服务包括下列服务器进程：

应用程序服务器节点上的缺省 server1 进程  
您在应用程序服务器节点上创建的应用程序服务器进程  
当安装向导创建服务时，卸载程序可以除去服务。如果使用 WASService 命令自已创建一个服务，那么当该服务不再有效时，您必须除去它。卸载程序不会除去您使用 WASService 命令创建的服务。

要在 Microsoft Windows 操作系统上设置并运行此功能，用户必须属于 administrator 组，而且具有下列高级用户权限：

作为操作系统的一部分  
作为服务登录  
有关将应用程序服务器作为服务在 Microsoft® Windows Vista™ 操作系统上运行的注意事项：

如果要在 Microsoft Windows Vista 操作系统上启动或停止作为服务来运行的应用程序服务器，那么需要以管理员特权来运行。  
服务可配置为在系统重新引导时自动启动，或者可以在接受管理员特权的提升提示后，手动从 Windows 服务面板启动和停止服务。

使用 WASService.exe 实用程序更改服务的特征或创建新服务时，也需要以管理员特权运行。  
为此，通过执行以下操作，从启动的命令提示符处运行 WASService.exe：

右键单击命令文件或其快捷方式。  
单击用管理员帐户运行。  
可以执行下列 .bat 文件以调用服务操作：  
startServer.bat  
stopServer.bat  
以标准用户特权运行时，不能执行改变或控制这些服务操作。管理员特权是必需的。

如果将应用程序服务器安装为服务，请执行以下操作以调用“命令提示符”窗口，然后在该窗口中运行 .bat 文件来控制此服务：

右键单击“命令提示符”快捷方式。  
单击用管理员帐户运行。  
如果未将应用程序服务器配置为作为服务来运行，那么不必根据管理员特权的提升提示来运行这些实用程序。

命令文件的位置

wasservice.sh 命令文件位于 app\_server\_root\\bin 目录中。

WASService.exe 命令文件位于 app\_server\_root\\bin 目录中。

命令语法

用于启动现有服务的命令语法

命令语法如下所示：

wasservice.sh -start service\_name \[optional startServer.bat parameters]

WASService.exe -start service\_name \[optional startServer.bat parameters]

用于创建服务或更新现有服务的命令语法

命令语法如下所示：

wasservice.sh -add service\_name

   -serverName server\_name

   -profilePath server\_profile\_directory

   \[-wasHome app\_server\_root]

   \[-startArgs additional\_start\_arguments]

   \[-stopArgs additional\_stop\_arguments]

   \[-userid user\_id -password password]

       

WASService.exe -add service\_name

   -serverName server\_name

   -profilePath server\_profile\_directory

   \[-wasHome app\_server\_root]

   \[-configRoot configuration\_repository\_directory]

   \[-startArgs additional\_start\_arguments]

   \[-stopArgs additional\_stop\_arguments]

   \[-userid user\_id -password password]

   \[-logFile service\_log\_file]

   \[-logRoot server\_log\_directory]

   \[-restart true | false]

   \[-startType automatic | manual | disabled]

     

用于删除服务的命令语法

命令语法如下所示：

wasservice.sh -remove service\_name

WASService.exe -remove service\_name

用于停止正在运行的服务的命令语法

命令语法如下所示：

wasservice.sh -stop service\_name \[optional stopServer.bat parameters]

WASService.exe -stop service\_name \[optional stopServer.bat parameters]

用于检索服务状态的命令语法

命令语法如下所示：

wasservice.sh -status service\_name

WASService.exe -status service\_name

参数

支持的参数包括：

-add service\_name

创建名为 service\_name 的服务或者更新现有服务。对于这两种情况，语法是相同的。

-configRoot configuration\_repository\_directory

可选参数，它识别 WebSphere Application Server 产品的安装根目录的配置目录。

-encodeParams service\_name

可选参数，它强制服务对 -startArgs 和 -stopArgs 进行编码以使无法通过编辑注册表来确定参数。使用 -add 参数创建服务时，通过在命令行上添加不带参数的 -encodeParams 的方式使用该参数。

或者对现有服务的参数进行编码：

WASService -encodeParams service\_name

-logFile service\_log\_file

识别 WASService 命令用于记录其活动的日志文件的可选参数。

-logRoot server\_log\_directory

识别概要文件的服务器日志目录的必需参数。WASService 命令查找名为 server\_name.pid 的文件，以确定服务器是否在运行。

-profilePath server\_profile\_directory

指定定义服务器进程的概要文件的目录路径。

-remove service\_name

删除指定的服务。

-restart true | false

设置为 true 时，在服务失败的情况下自动重新启动现有的服务。

-serverName server\_name

识别服务控制的服务器。

-start service\_name \[optional startServer.bat parameters]

启动现有的服务。

-startArgs additional\_start\_arguments

识别其他参数的可选参数。

-startType automatic | manual | disabled

定义新服务的启动类型。automatic 启动类型在系统启动或第一次调用服务时自动启动。在操作系统可以装入 manual 服务并且让它可供使用之前，您必须先将它启动。您无法在更改 disabled 启动类型之前，启动该服务。

-status service\_name

返回服务的当前状态，它包含服务是在运行还是停止了。

-stop service\_name \[optional stopServer.bat parameters]

停止指定的服务。

-stopArgs additional\_stop\_arguments

识别其他参数的可选参数。

-userid user\_id -password password

识别 Windows 服务将以该标识运行的特权用户标识和密码的可选参数。

-wasHome app\_server\_root

标识产品的安装根目录的可选参数。

由向导创建的服务的缺省名称

安装向导创建的服务的名称为 IBM WebSphere Application Server V6.x - DefaultNode。

查看服务面板

要查看服务，打开控制面板并单击管理工具 &gt; 服务。选择要查看它的信息的服务。右击该服务并单击属性。四个选项卡提供信息和功能。例如，选择常规选项卡上的设置类型字段，更改设置类型。

示例

示例

本示例创建用于启动应用程序服务器进程的名为 IBM WebSphere Application Server V6.x - name\_of\_the\_application\_server\_service 的服务：

WASService -add name\_of\_the\_application\_server\_service

   -servername application\_server\_name

   -profilePath profile\_root

   -wasHome app\_server\_root

   -logFile profile\_root\\logs\\WS\_startServer.log

   -logRoot profile\_root\\logs\\application\_server\_name

   -restart true

其中

·         name\_of\_the\_application\_server\_service 是想要命名服务的名称

·         application\_server\_name 是服务器的名称

输入命令后，命令窗口中会显示类似于以下示例中显示的消息的消息：

Adding Service: name\_of\_the\_application\_server\_service

Config Root: profile\_root\\config

Server Name: application\_server\_name

Profile Path: profile\_root

Was Home: app\_server\_root

Start Args:

Restart: 1

IBM WebSphere Application Server V6.x - name\_of\_the\_application\_server\_service service successfully added.

示例

用于 Windows 操作系统的本示例使用其他的停止参数、用户名和密码来更新名为 IBM WebSphere Application Server V6.x - Server2 Service 的现有服务。会自动将这些参数传递到 Windows 服务用来关闭系统的脚本中。

WASService -add "Server2 Service"

   -servername server2

   -profilePath profile\_root

   -logRoot profile\_root\\logs\\server2

   -stopArgs "-username user\_name -password password"

   -encodeParams

在创建 Windows 服务后启动和停止服务器进程

对于本 Windows 操作系统示例，如果在为 server1 创建 Windows 服务后发出 startServer server1 命令或 stopServer server1 命令，那么会显示类似于以下示例的消息：

因为将 server1 注册为作为 Windows 服务方式运行，因此启动此服务器的请求将通过启动关联的 Windows 服务完成。

 

说明：

在windows平台上在创建profile时，系统自动创建的服务名称为*IBM WebSphere Application Server V6.x - name\_of\_the\_application\_server\_service 例如：IBM WebSphere Application Server V6.1 - cnooc\_n-node01*

注意*cnooc\_n-node01才是服务的名称。*  
\--------------------------------------------------------------------------------

相关参考

[启用安全性后的访问问题](http://publib.boulder.ibm.com/infocenter/wasinfo/v6r1/topic/com.ibm.websphere.base.doc/info/aes/ae/rtrb_secprobs.html)