Advertisement
ovichan

Untitled

Apr 2nd, 2024 (edited)
764
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 10.22 KB | Fixit | 0 0
  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. if "%OS%" == "Windows_NT" setlocal
  18. rem ---------------------------------------------------------------------------
  19. rem NT Service Install/Uninstall script
  20. rem
  21. rem Options
  22. rem install                Install the service using Tomcat as service name.
  23. rem                        Service is installed using default settings.
  24. rem remove                 Remove the service from the System.
  25. rem
  26. rem name        (optional) If the second argument is present it is considered
  27. rem                        to be new service name
  28. rem
  29. rem $Id: service.bat 1000718 2010-09-24 06:00:00Z mturk $
  30. rem ---------------------------------------------------------------------------
  31.  
  32. rem ---------XAMPP-------------------------------------------------------------
  33. ::::::::::::::::::::::::::::::::::::
  34. ::  Set JAVA_HOME or JRE_HOME     ::
  35. ::::::::::::::::::::::::::::::::::::
  36.  
  37. echo.
  38. echo [XAMPP]: Searching for JDK or JRE HOME with reg query ...
  39. set JDKKeyName64=HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit
  40. set JDKKeyName64Short=HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\JDK
  41. set AdoptOpenJDKKeyName64=HKEY_LOCAL_MACHINE\SOFTWARE\AdoptOpenJDK\JDK
  42. set JREKeyName64=HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment
  43. set JREKeyName64Short=HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\JRE
  44. set AdoptOpenJDKKeyName64JRE=HKEY_LOCAL_MACHINE\SOFTWARE\AdoptOpenJDK\JRE
  45.  
  46. reg query "%JDKKeyName64%" /s
  47. if %ERRORLEVEL% EQU 1 (
  48.     echo . [XAMPP]: Could not find 32 bit or 64 bit JDK
  49.     echo . [XAMPP]: Looking for 32 bit JDK on 64 bit machine
  50.     goto FINDJDK64SHORT
  51. )
  52. set KeyName=%JDKKeyName64%
  53. goto JDKRUN
  54.  
  55. :FINDJDK64SHORT
  56. reg query "%JDKKeyName64Short%" /s
  57. if %ERRORLEVEL% EQU  1 (
  58.     echo . [XAMPP]: Could not find 32 bit JDK
  59.     echo . [XAMPP]: Looking for 32 bit or 64 bit on 64 bit machine with short name
  60.     goto FINDADOPTOPENJDK64
  61. )
  62. set KeyName=%JDKKeyName64Short%
  63. goto JDKRUN
  64.  
  65. :FINDADOPTOPENJDK64
  66. reg query "%AdoptOpenJDKKeyName64%" /s
  67. if %ERRORLEVEL% EQU  1 (
  68.     echo . [XAMPP]: Could not find 32 bit or 64 bit AdoptOpenJDK
  69.     echo . [XAMPP]: Looking for 32 bit or 64 bit JRE
  70.     goto FINDJRE64
  71. )
  72. set KeyName=%AdoptOpenJDKKeyName64%
  73. goto JDKRUN
  74.  
  75. :FINDJRE64
  76. reg query "%JREKeyName64%" /s
  77. if %ERRORLEVEL% EQU 1 (
  78.     echo . [XAMPP]: Could not find 32 bit or 64 bit JRE with long name
  79.     echo . [XAMPP]: Looking for 32 bit or 64 bit JRE on 64 bit machine with short name
  80.     goto FINDJRE64SHORT
  81. )
  82. set KeyName=%JREKeyName64%
  83. goto JRERUN
  84.  
  85. :FINDJRE64SHORT
  86. reg query "%JREKeyName64Short%" /s
  87. if %ERRORLEVEL% EQU 1 (
  88.     echo . [XAMPP]: Could not find 32 bit or 64 bit JRE with short name
  89.     echo . [XAMPP]: Looking for 32 bit or 64 bit AdoptOpenJDK JRE on 64 bit machine
  90.     goto FINDADOPTOPENJDK64JRE
  91. )
  92. set KeyName=%JREKeyName64Short%
  93. goto JRERUN
  94.  
  95. :FINDADOPTOPENJDK64JRE
  96. reg query "%AdoptOpenJDKKeyName64JRE%" /s
  97. if %ERRORLEVEL% EQU  1 (
  98.     echo . [XAMPP]: Could not find 32 bit or 64 bit AdoptOpenJDK JRE
  99.     echo . [XAMPP]: Looking for 32 JRE on 64 bit machine
  100.     goto ENDERROR
  101. )
  102. set KeyName=%AdoptOpenJDKKeyName64JRE%
  103. goto JDKRUN
  104.  
  105. :JDKRUN
  106. echo.
  107. echo [XAMPP]: Using JDK
  108. set "CURRENT_DIR=%~dp0"
  109. set "CURRENT_DIR=%CURRENT_DIR:~,-1%"
  110. set "CATALINA_HOME=%CURRENT_DIR%\tomcat"
  111.  
  112. set Cmd=reg query "%KeyName%" /s
  113. for /f "tokens=2*" %%i in ('%Cmd% ^| find "JavaHome"') do set JAVA_HOME=%%j
  114.  
  115. echo.
  116. echo [XAMPP]: Seems fine!
  117. echo [XAMPP]: Set JAVA_HOME : %JAVA_HOME%
  118. echo [XAMPP]: Set CATALINA_HOME : %CATALINA_HOME%
  119. echo.
  120. goto NEXT
  121.  
  122. :JRERUN
  123. echo.
  124. echo [XAMPP]: Using JRE
  125. set "CURRENT_DIR=%~dp0"
  126. set "CURRENT_DIR=%CURRENT_DIR:~,-1%"
  127. set "CATALINA_HOME=%CURRENT_DIR%\tomcat"
  128.  
  129. set Cmd=reg query "%KeyName%" /s
  130. for /f "tokens=2*" %%i in ('%Cmd% ^| find "JavaHome"') do set JRE_HOME=%%j
  131.  
  132. echo.
  133. echo [XAMPP]: Seems fine!
  134. echo [XAMPP]: Set JRE_HOME : %JRE_HOME%
  135. echo [XAMPP]: Set CATALINA_HOME : %CATALINA_HOME%
  136. echo.
  137. goto NEXT
  138.  
  139. :ENDERROR
  140. exit 1
  141.  
  142. :NEXT
  143.  
  144. echo [XAMPP]: Finding Java Version
  145.  
  146. set Cmd=reg query "%KeyName%" /v CurrentVersion
  147. for /f "tokens=2*" %%i in ('%Cmd% ^| find "CurrentVersion"') do set CVERSION=%%j
  148.  
  149. echo [XAMPP]: Java Version: %CVERSION%
  150. echo [XAMPP]: Starting Tomcat Service Install...
  151. echo .
  152.  
  153. rem ----------END XAMPP-----------------------------------------------------------------
  154.  
  155. set "SELF=%~dp0%service.bat"
  156. rem Guess CATALINA_HOME if not defined
  157. set "CURRENT_DIR=%~dp0"
  158. set "CURRENT_DIR=%CURRENT_DIR:~,-1%"
  159. if not "%CATALINA_HOME%" == "" goto gotHome
  160. set "CATALINA_HOME=%CURRENT_DIR%\tomcat"
  161. if exist "%CATALINA_HOME%\bin\tomcat8.exe" goto okHome
  162. rem CD to the upper dir
  163. cd ..
  164. set "CATALINA_HOME=%CURRENT_DIR%\tomcat"
  165. :gotHome
  166. if exist "%CATALINA_HOME%\bin\tomcat8.exe" goto okHome
  167. echo The tomcat.exe was not found...
  168. echo The CATALINA_HOME environment variable is not defined correctly.
  169. echo This environment variable is needed to run this program
  170. goto end
  171. :okHome
  172. rem Make sure prerequisite environment variables are set
  173. if not "%JAVA_HOME%" == "" goto gotJdkHome
  174. if not "%JRE_HOME%" == "" goto gotJreHome
  175. echo Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
  176. echo Service will try to guess them from the registry.
  177. goto okJavaHome
  178. :gotJreHome
  179. if not exist "%JRE_HOME%\bin\java.exe" goto noJavaHome
  180. if not exist "%JRE_HOME%\bin\javaw.exe" goto noJavaHome
  181. goto okJavaHome
  182. :gotJdkHome
  183. if not exist "%JAVA_HOME%\bin\java.exe" goto noJavaHome
  184. if not exist "%JAVA_HOME%\bin\javaw.exe" goto noJavaHome
  185. if not exist "%JAVA_HOME%\bin\javac.exe" goto noJavaHome
  186. if not "%JRE_HOME%" == "" goto okJavaHome
  187. set "JRE_HOME=%JAVA_HOME%\bin"
  188. goto okJavaHome
  189. :noJavaHome
  190. echo The JAVA_HOME environment variable is not defined correctly
  191. echo This environment variable is needed to run this program
  192. echo NB: JAVA_HOME should point to a JDK not a JRE
  193. goto end
  194. :okJavaHome
  195. if not "%CATALINA_BASE%" == "" goto gotBase
  196. set "CATALINA_BASE=%CATALINA_HOME%"
  197. :gotBase
  198.  
  199. set "EXECUTABLE=%CATALINA_HOME%\bin\tomcat8.exe"
  200.  
  201. rem Set default Service name
  202. set SERVICE_NAME=Tomcat
  203. set PR_DISPLAYNAME=Apache Tomcat
  204.  
  205. if "x%1x" == "xx" goto displayUsage
  206. set SERVICE_CMD=%1
  207. shift
  208. if "x%1x" == "xx" goto checkServiceCmd
  209. :checkUser
  210. if "x%1x" == "x/userx" goto runAsUser
  211. if "x%1x" == "x--userx" goto runAsUser
  212. set SERVICE_NAME=%1
  213. set PR_DISPLAYNAME=Apache Tomcat %1
  214. shift
  215. if "x%1x" == "xx" goto checkServiceCmd
  216. goto checkUser
  217. :runAsUser
  218. shift
  219. if "x%1x" == "xx" goto displayUsage
  220. set SERVICE_USER=%1
  221. shift
  222. runas /env /savecred /user:%SERVICE_USER% "%COMSPEC% /K \"%SELF%\" %SERVICE_CMD% %SERVICE_NAME%"
  223. goto end
  224. :checkServiceCmd
  225. if /i %SERVICE_CMD% == install goto doInstall
  226. if /i %SERVICE_CMD% == remove goto doRemove
  227. if /i %SERVICE_CMD% == uninstall goto doRemove
  228. echo Unknown parameter "%1"
  229. :displayUsage
  230. echo.
  231. echo Usage: service.bat install/remove [service_name] [/user username]
  232. goto end
  233.  
  234. :doRemove
  235. rem Remove the service
  236. "%EXECUTABLE%" //DS//%SERVICE_NAME%
  237. if not errorlevel 1 goto removed
  238. echo Failed removing '%SERVICE_NAME%' service
  239. goto end
  240. :removed
  241. echo The service '%SERVICE_NAME%' has been removed
  242. goto end
  243.  
  244. :doInstall
  245. rem Install the service
  246. echo Installing the service '%SERVICE_NAME%' ...
  247. echo Using CATALINA_HOME:    "%CATALINA_HOME%"
  248. echo Using CATALINA_BASE:    "%CATALINA_BASE%"
  249. echo Using JAVA_HOME:        "%JAVA_HOME%"
  250. echo Using JRE_HOME:         "%JRE_HOME%"
  251.  
  252. rem Use the environment variables as an example
  253. rem Each command line option is prefixed with PR_
  254.  
  255. set PR_DESCRIPTION=Apache Tomcat Server - http://tomcat.apache.org/
  256. set "PR_INSTALL=%EXECUTABLE%"
  257. set "PR_LOGPATH=%CATALINA_BASE%\logs"
  258. set "PR_CLASSPATH=%CATALINA_HOME%\bin\bootstrap.jar;%CATALINA_BASE%\bin\tomcat-juli.jar;%CATALINA_HOME%\bin\tomcat-juli.jar"
  259. rem Set the server jvm from JAVA_HOME
  260. set "PR_JVM=%JRE_HOME%\bin\server\jvm.dll"
  261. if exist "%PR_JVM%" goto foundJvm
  262. rem Set the client jvm from JAVA_HOME
  263. set "PR_JVM=%JRE_HOME%\bin\client\jvm.dll"
  264. if exist "%PR_JVM%" goto foundJvm
  265. set PR_JVM=auto
  266. :foundJvm
  267. echo Using JVM:              "%PR_JVM%"
  268. "%EXECUTABLE%" //IS//%SERVICE_NAME% --StartClass org.apache.catalina.startup.Bootstrap --StopClass org.apache.catalina.startup.Bootstrap --StartParams start --StopParams stop --Startup auto
  269. if not errorlevel 1 goto installed
  270. echo Failed installing '%SERVICE_NAME%' service
  271. goto ENDERROR
  272. :installed
  273. rem Clear the environment variables. They are not needed any more.
  274. set PR_DISPLAYNAME=
  275. set PR_DESCRIPTION=
  276. set PR_INSTALL=
  277. set PR_LOGPATH=
  278. set PR_CLASSPATH=
  279. set PR_JVM=
  280. rem Set extra parameters
  281. "%EXECUTABLE%" //US//%SERVICE_NAME% --JvmOptions "-Dcatalina.base=%CATALINA_BASE%;-Dcatalina.home=%CATALINA_HOME%;-Djava.endorsed.dirs=%CATALINA_HOME%\endorsed" --StartMode jvm --StopMode jvm
  282. rem More extra parameters
  283. set "PR_LOGPATH=%CATALINA_BASE%\logs"
  284. set PR_STDOUTPUT=auto
  285. set PR_STDERROR=auto
  286.  
  287. rem XAMPP: We need special parameters for Java 7
  288. if "%CVERSION%" == "1.7" goto JAVA7
  289. :JAVA
  290. "%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 128 --JvmMx 256
  291. goto FINISH
  292. :JAVA7
  293. "%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;-Djava.net.preferIPv4Stack=true" --JvmMs 128 --JvmMx 256
  294. :FINISH
  295. echo The service '%SERVICE_NAME%' has been installed.
  296.  
  297. :end
  298. cd "%CURRENT_DIR%"
  299.  
  300.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement