OSDN Git Service

Ver8.5.2.0
[opengion/opengionV8.git] / apps / tomcat10.1.10 / bin / service.bat
1 @echo off
2 rem Licensed to the Apache Software Foundation (ASF) under one or more
3 rem contributor license agreements.  See the NOTICE file distributed with
4 rem this work for additional information regarding copyright ownership.
5 rem The ASF licenses this file to You under the Apache License, Version 2.0
6 rem (the "License"); you may not use this file except in compliance with
7 rem the License.  You may obtain a copy of the License at
8 rem
9 rem     http://www.apache.org/licenses/LICENSE-2.0
10 rem
11 rem Unless required by applicable law or agreed to in writing, software
12 rem distributed under the License is distributed on an "AS IS" BASIS,
13 rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 rem See the License for the specific language governing permissions and
15 rem limitations under the License.
16
17 rem ---------------------------------------------------------------------------
18 rem NT Service Install/Uninstall script
19 rem
20 rem Usage: service.bat install/remove [service_name [--rename]] [--user username]
21 rem
22 rem Options
23 rem install                 Install the service using default settings.
24 rem remove                  Remove the service from the system.
25 rem
26 rem service_name (optional) The name to use for the service. If not specified,
27 rem                         Tomcat10 is used as the service name.
28 rem
29 rem --rename     (optional) Rename tomcat10.exe and tomcat10w.exe to match
30 rem                         the non-default service name.
31 rem
32 rem username     (optional) The name of the OS user to use to install/remove
33 rem                         the service (not the name of the OS user the
34 rem                         service will run as). If not specified, the current
35 rem                         user is used.
36 rem ---------------------------------------------------------------------------
37
38 setlocal
39
40 set "SELF=%~dp0%service.bat"
41
42 set DEFAULT_SERVICE_NAME=Tomcat10
43 set SERVICE_NAME=%DEFAULT_SERVICE_NAME%
44
45 set "CURRENT_DIR=%cd%"
46
47 rem Parse the arguments
48 if "x%1x" == "xx" goto displayUsage
49 set SERVICE_CMD=%1
50 shift
51 if "x%1x" == "xx" goto checkEnv
52 :checkUser
53 if "x%1x" == "x/userx" goto runAsUser
54 if "x%1x" == "x--userx" goto runAsUser
55 set SERVICE_NAME=%1
56 shift
57 if "x%1x" == "xx" goto checkEnv
58 if "x%1x" == "x--renamex" (
59     set RENAME=%1
60     shift
61 )
62 if "x%1x" == "xx" goto checkEnv
63 goto checkUser
64 :runAsUser
65 shift
66 if "x%1x" == "xx" goto displayUsage
67 set SERVICE_USER=%1
68 shift
69 runas /env /savecred /user:%SERVICE_USER% "%COMSPEC% /K \"%SELF%\" %SERVICE_CMD% %SERVICE_NAME%"
70 exit /b 0
71
72 rem Check the environment
73 :checkEnv
74
75 rem Guess CATALINA_HOME if not defined
76 if not "%CATALINA_HOME%" == "" goto gotHome
77 set "CATALINA_HOME=%cd%"
78 if exist "%CATALINA_HOME%\bin\%DEFAULT_SERVICE_NAME%.exe" goto gotHome
79 if exist "%CATALINA_HOME%\bin\%SERVICE_NAME%.exe" goto gotHome
80 rem CD to the upper dir
81 cd ..
82 set "CATALINA_HOME=%cd%"
83 :gotHome
84 if exist "%CATALINA_HOME%\bin\%DEFAULT_SERVICE_NAME%.exe" (
85     set "EXECUTABLE=%CATALINA_HOME%\bin\%DEFAULT_SERVICE_NAME%.exe"
86     goto okHome
87 )
88 if exist "%CATALINA_HOME%\bin\%SERVICE_NAME%.exe" (
89     set "EXECUTABLE=%CATALINA_HOME%\bin\%SERVICE_NAME%.exe"
90     goto okHome
91 )
92 if "%DEFAULT_SERVICE_NAME%"== "%SERVICE_NAME%" (
93     echo The file %DEFAULT_SERVICE_NAME%.exe was not found...
94 ) else (
95     echo Neither the %DEFAULT_SERVICE_NAME%.exe file nor the %SERVICE_NAME%.exe file was found...
96 )
97 echo Either the CATALINA_HOME environment variable is not defined correctly or
98 echo the incorrect service name has been used.
99 echo Both the CATALINA_HOME environment variable and the correct service name
100 echo are required to run this program.
101 exit /b 1
102 :okHome
103 cd "%CURRENT_DIR%"
104
105 rem Make sure prerequisite environment variables are set
106 if not "%JRE_HOME%" == "" goto gotJreHome
107 if not "%JAVA_HOME%" == "" goto gotJavaHome
108 echo Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
109 echo Service will try to guess them from the registry.
110 goto okJava
111
112 :gotJavaHome
113 rem No JRE given, check if JAVA_HOME is usable as JRE_HOME
114 if not exist "%JAVA_HOME%\bin\java.exe" goto noJavaHomeAsJre
115 rem Use JAVA_HOME as JRE_HOME
116 set "JRE_HOME=%JAVA_HOME%"
117 goto okJava
118
119 :noJavaHomeAsJre
120 echo The JAVA_HOME environment variable is not defined correctly.
121 echo JAVA_HOME=%JAVA_HOME%
122 echo NB: JAVA_HOME should point to a JDK not a JRE.
123 exit /b 1
124
125 :gotJreHome
126 rem Check if we have a usable JRE
127 if not exist "%JRE_HOME%\bin\java.exe" goto noJreHome
128 goto okJava
129
130 :noJreHome
131 rem Needed at least a JRE
132 echo The JRE_HOME environment variable is not defined correctly
133 echo JRE_HOME=%JRE_HOME%
134 echo This environment variable is needed to run this program
135 exit /b 1
136
137 :okJava
138 if not "%CATALINA_BASE%" == "" goto gotBase
139 set "CATALINA_BASE=%CATALINA_HOME%"
140
141 :gotBase
142 rem Process the requested command
143 if /i %SERVICE_CMD% == install goto doInstall
144 if /i %SERVICE_CMD% == remove goto doRemove
145 if /i %SERVICE_CMD% == uninstall goto doRemove
146 echo Unknown parameter "%SERVICE_CMD%"
147 :displayUsage
148 echo.
149 echo Usage: service.bat install/remove [service_name [--rename]] [--user username]
150 exit /b 1
151
152 :doRemove
153 rem Remove the service
154 echo Removing the service '%SERVICE_NAME%' ...
155 echo Using CATALINA_BASE:    "%CATALINA_BASE%"
156
157 "%EXECUTABLE%" //DS//%SERVICE_NAME% ^
158     --LogPath "%CATALINA_BASE%\logs"
159 if not errorlevel 1 goto removed
160 echo Failed removing '%SERVICE_NAME%' service
161 exit /b 1
162 :removed
163 echo The service '%SERVICE_NAME%' has been removed
164 if exist "%CATALINA_HOME%\bin\%SERVICE_NAME%.exe" (
165     rename "%SERVICE_NAME%.exe" "%DEFAULT_SERVICE_NAME%.exe"
166     rename "%SERVICE_NAME%w.exe" "%DEFAULT_SERVICE_NAME%w.exe"
167 )
168 exit /b 0
169
170 :doInstall
171 rem Install the service
172 echo Installing the service '%SERVICE_NAME%' ...
173 echo Using CATALINA_HOME:    "%CATALINA_HOME%"
174 echo Using CATALINA_BASE:    "%CATALINA_BASE%"
175 echo Using JRE_HOME:         "%JRE_HOME%"
176
177 rem Try to use the server jvm
178 set "JVM=%JRE_HOME%\bin\server\jvm.dll"
179 if exist "%JVM%" goto foundJvm
180 rem Try to use the client jvm
181 set "JVM=%JRE_HOME%\bin\client\jvm.dll"
182 if exist "%JVM%" goto foundJvm
183 echo Warning: Neither 'server' nor 'client' jvm.dll was found at JRE_HOME.
184 set JVM=auto
185 :foundJvm
186 echo Using JVM:              "%JVM%"
187
188 rem === IFA 2018/02/01 openoffice \82Ì CLASSPATH \82â\81A\8ag\92£\83t\83H\83\8b\83_(endorsed7.0)\82Ì\83N\83\89\83X\83p\83X\82ð\92Ç\89Á\82µ\82Ä\82¨\82«\82Ü\82·\81B\82±\82ê\82Å\83\8c\83W\83X\83g\83\8a\82É\82à\8f\91\82«\8d\9e\82Ü\82ê\82Ü\82·\81B
189 rem set "CLASSPATH=%CATALINA_HOME%\bin\bootstrap.jar;%CATALINA_BASE%\bin\tomcat-juli.jar"
190 set "CLASSPATH=%CATALINA_HOME%\bin\bootstrap.jar;%CATALINA_BASE%\bin\tomcat-juli.jar;%OG_CLASSPATH%"
191 if not "%CATALINA_HOME%" == "%CATALINA_BASE%" set "CLASSPATH=%CLASSPATH%;%CATALINA_HOME%\bin\tomcat-juli.jar"
192
193 if "%SERVICE_STARTUP_MODE%" == "" set SERVICE_STARTUP_MODE=manual
194 if "%JvmMs%" == "" set JvmMs=128
195 if "%JvmMx%" == "" set JvmMx=256
196
197 if exist "%CATALINA_HOME%\bin\%DEFAULT_SERVICE_NAME%.exe" (
198     if "x%RENAME%x" == "x--renamex" (
199         rename "%DEFAULT_SERVICE_NAME%.exe" "%SERVICE_NAME%.exe"
200         rename "%DEFAULT_SERVICE_NAME%w.exe" "%SERVICE_NAME%w.exe"
201         set "EXECUTABLE=%CATALINA_HOME%\bin\%SERVICE_NAME%.exe"
202     )
203 )
204
205 "%EXECUTABLE%" //IS//%SERVICE_NAME% ^
206     --Description "Apache Tomcat 10.1.10 Server - https://tomcat.apache.org/" ^
207     --DisplayName "Apache Tomcat 10.1 %SERVICE_NAME%" ^
208     --Install "%EXECUTABLE%" ^
209     --LogPath "%CATALINA_BASE%\logs" ^
210     --StdOutput auto ^
211     --StdError auto ^
212     --Classpath "%CLASSPATH%" ^
213     --Jvm "%JVM%" ^
214     --StartMode jvm ^
215     --StopMode jvm ^
216     --StartPath "%CATALINA_HOME%" ^
217     --StopPath "%CATALINA_HOME%" ^
218     --StartClass org.apache.catalina.startup.Bootstrap ^
219     --StopClass org.apache.catalina.startup.Bootstrap ^
220     --StartParams start ^
221     --StopParams stop ^
222     --JvmOptions "-Dcatalina.home=%CATALINA_HOME%;-Dcatalina.base=%CATALINA_BASE%;-Djava.io.tmpdir=%CATALINA_BASE%\temp;-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager;-Djava.util.logging.config.file=%CATALINA_BASE%\conf\logging.properties;%JvmArgs%" ^
223     --JvmOptions9 "--add-opens=java.base/java.lang=ALL-UNNAMED#--add-opens=java.base/java.io=ALL-UNNAMED#--add-opens=java.base/java.util=ALL-UNNAMED#--add-opens=java.base/java.util.concurrent=ALL-UNNAMED#--add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED" ^
224     --Startup "%SERVICE_STARTUP_MODE%" ^
225     --JvmMs "%JvmMs%" ^
226     --JvmMx "%JvmMx%"
227 if not errorlevel 1 goto installed
228 echo Failed installing '%SERVICE_NAME%' service
229 exit /b 1
230 :installed
231 echo The service '%SERVICE_NAME%' has been installed.
232 exit /b 0