Tomcat7 采用service.bat 注册window服务

来源:互联网 发布:淘宝卖家公益怎么收费 编辑:程序博客网 时间:2024/06/05 19:23

Tomcat7 采用service.bat 注册window服务

service.bat 文件配置参考

@echo offrem Licensed to the Apache Software Foundation (ASF) under one or morerem contributor license agreements.  See the NOTICE file distributed withrem this work for additional information regarding copyright ownership.rem The ASF licenses this file to You under the Apache License, Version 2.0rem (the "License"); you may not use this file except in compliance withrem the License.  You may obtain a copy of the License atremrem     http://www.apache.org/licenses/LICENSE-2.0remrem Unless required by applicable law or agreed to in writing, softwarerem distributed under the License is distributed on an "AS IS" BASIS,rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.rem See the License for the specific language governing permissions andrem limitations under the License.if "%OS%" == "Windows_NT" setlocalrem ---------------------------------------------------------------------------rem NT Service Install/Uninstall scriptremrem Optionsrem install                Install the service using Tomcat7 as service name.rem                        Service is installed using default settings.rem remove                 Remove the service from the System.remrem name        (optional) If the second argument is present it is consideredrem                        to be new service nameremrem $Id: service.bat 1000718 2010-09-24 06:00:00Z mturk $rem ---------------------------------------------------------------------------set "SELF=%~dp0%service.bat"rem Guess CATALINA_HOME if not definedset "CURRENT_DIR=%cd%"if not "%CATALINA_HOME%" == "" goto gotHomeset "CATALINA_HOME=%cd%"if exist "%CATALINA_HOME%\bin\tomcat7.exe" goto okHomerem CD to the upper dircd ..set "CATALINA_HOME=%cd%":gotHomeif exist "%CATALINA_HOME%\bin\tomcat7.exe" goto okHomeecho The tomcat.exe was not found...echo The CATALINA_HOME environment variable is not defined correctly.echo This environment variable is needed to run this programgoto end:okHomerem Make sure prerequisite environment variables are setif not "%JAVA_HOME%" == "" goto gotJdkHomeif not "%JRE_HOME%" == "" goto gotJreHomeecho Neither the JAVA_HOME nor the JRE_HOME environment variable is definedecho Service will try to guess them from the registry.goto okJavaHome:gotJreHomeif not exist "%JRE_HOME%\bin\java.exe" goto noJavaHomeif not exist "%JRE_HOME%\bin\javaw.exe" goto noJavaHomegoto okJavaHome:gotJdkHomeif not exist "%JAVA_HOME%\jre\bin\java.exe" goto noJavaHomeif not exist "%JAVA_HOME%\jre\bin\javaw.exe" goto noJavaHomeif not exist "%JAVA_HOME%\bin\javac.exe" goto noJavaHomeif not "%JRE_HOME%" == "" goto okJavaHomeset "JRE_HOME=%JAVA_HOME%\jre"goto okJavaHome:noJavaHomeecho The JAVA_HOME environment variable is not defined correctlyecho This environment variable is needed to run this programecho NB: JAVA_HOME should point to a JDK not a JREgoto end:okJavaHomeif not "%CATALINA_BASE%" == "" goto gotBaseset "CATALINA_BASE=%CATALINA_HOME%":gotBaseset "EXECUTABLE=%CATALINA_HOME%\bin\tomcat7.exe"rem Set default Service nameset SERVICE_NAME=Tomcat7set PR_DISPLAYNAME=Apache Tomcat 7if "x%1x" == "xx" goto displayUsageset SERVICE_CMD=%1shiftif "x%1x" == "xx" goto checkServiceCmd:checkUserif "x%1x" == "x/userx" goto runAsUserif "x%1x" == "x--userx" goto runAsUserset SERVICE_NAME=%1set PR_DISPLAYNAME=Apache Tomcat %1shiftif "x%1x" == "xx" goto checkServiceCmdgoto checkUser:runAsUsershiftif "x%1x" == "xx" goto displayUsageset SERVICE_USER=%1shiftrunas /env /savecred /user:%SERVICE_USER% "%COMSPEC% /K \"%SELF%\" %SERVICE_CMD% %SERVICE_NAME%"goto end:checkServiceCmdif /i %SERVICE_CMD% == install goto doInstallif /i %SERVICE_CMD% == remove goto doRemoveif /i %SERVICE_CMD% == uninstall goto doRemoveecho Unknown parameter "%1":displayUsageecho.echo Usage: service.bat install/remove [service_name] [/user username]goto end:doRemoverem Remove the service"%EXECUTABLE%" //DS//%SERVICE_NAME%if not errorlevel 1 goto removedecho Failed removing '%SERVICE_NAME%' servicegoto end:removedecho The service '%SERVICE_NAME%' has been removedgoto end:doInstallrem Install the serviceecho Installing the service '%SERVICE_NAME%' ...echo Using CATALINA_HOME:    "%CATALINA_HOME%"echo Using CATALINA_BASE:    "%CATALINA_BASE%"echo Using JAVA_HOME:        "%JAVA_HOME%"echo Using JRE_HOME:         "%JRE_HOME%"rem Use the environment variables as an examplerem Each command line option is prefixed with PR_set PR_DESCRIPTION=Apache Tomcat 7.0.28 Server - http://tomcat.apache.org/set "PR_INSTALL=%EXECUTABLE%"set "PR_LOGPATH=%CATALINA_BASE%\logs"rem  如果让tomcat编译jsp文件,就在PR_CLASSPATH中加入J2SDK的tools.jarset "PR_CLASSPATH=%JAVA_HOME%\lib\tools.jar;%CATALINA_HOME%\bin\bootstrap.jar;%CATALINA_BASE%\bin\tomcat-juli.jar;%CATALINA_HOME%\bin\tomcat-juli.jar"rem set "PR_CLASSPATH=%CATALINA_HOME%\bin\bootstrap.jar;%CATALINA_BASE%\bin\tomcat-juli.jar;%CATALINA_HOME%\bin\tomcat-juli.jar"rem Set the server jvm from JAVA_HOMErem 指定JVMset "PR_JVM=%JRE_HOME%\bin\server\jvm.dll"if exist "%PR_JVM%" goto foundJvmrem Set the client jvm from JAVA_HOMEset "PR_JVM=%JRE_HOME%\bin\client\jvm.dll"if exist "%PR_JVM%" goto foundJvmset PR_JVM=auto:foundJvmecho Using JVM:              "%PR_JVM%"rem 要使用一个特定的JVM,就要修改jvm的参数;要使注册的windows服务的启动方式为自动,增加--Startup Automatic,这个是比较常用的;要用定制的server.xml配置文件并且传递多个参数给StartClass,要修改StartParams的值,各个值之间用分号分隔:--StartParams "-config;%CUSTOM_SERVERXML_FILE%;-nonaming;start""%EXECUTABLE%" //IS//%SERVICE_NAME% --Jvm "%JAVA_HOME%\jre\bin\server\jvm.dll" --StartClass org.apache.catalina.startup.Bootstrap --StopClass org.apache.catalina.startup.Bootstrap --StartParams start --StopParams stop --Startup Automaticrem "%EXECUTABLE%" //IS//%SERVICE_NAME% --StartClass org.apache.catalina.startup.Bootstrap --StopClass org.apache.catalina.startup.Bootstrap --StartParams start --StopParams stopif not errorlevel 1 goto installedecho Failed installing '%SERVICE_NAME%' servicegoto end:installedrem Clear the environment variables. They are not needed any more.set PR_DISPLAYNAME=set PR_DESCRIPTION=set PR_INSTALL=set PR_LOGPATH=set PR_CLASSPATH=set PR_JVM=rem Set extra parametersrem 指定最大和最小的内存限制,要增加jvm的初始参数"%EXECUTABLE%" //US//%SERVICE_NAME% --JvmOptions "-Xms800M;-Xmx1024M;-XX:PermSize=256M;-XX:MaxNewSize=256m;-XX:MaxPermSize=256m;-Dcatalina.base=%CATALINA_BASE%;-Dcatalina.home=%CATALINA_HOME%;-Djava.endorsed.dirs=%CATALINA_HOME%\common\endorsed" --StartMode jvm --StopMode jvmrem "%EXECUTABLE%" //US//%SERVICE_NAME% --JvmOptions "-Dcatalina.base=%CATALINA_BASE%;-Dcatalina.home=%CATALINA_HOME%;-Djava.endorsed.dirs=%CATALINA_HOME%\endorsed" --StartMode jvm --StopMode jvmrem More extra parametersset "PR_LOGPATH=%CATALINA_BASE%\logs"set PR_STDOUTPUT=autoset PR_STDERROR=auto"%EXECUTABLE%" //US//%SERVICE_NAME% ++JvmOptions "-Djava.io.tmpdir=%CATALINA_BASE%\temp;-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager;-Djava.util.logging.config.file=%CATALINA_BASE%\conf\logging.properties" --JvmMs 800 --JvmMx 1024rem 设置开机启动sc config %SERVICE_NAME% start= autoecho The service '%SERVICE_NAME%' has been installed.:endcd "%CURRENT_DIR%"


0 0