Advertisement
Guest User

segiservice.bat

a guest
Sep 18th, 2015
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.51 KB | None | 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 Tomcat7 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. set JRE_HOME=C:\ebaseXi\jre
  33. set JAVA_HOME=C:\Program Files\Java\jdk1.7.0_45\
  34.  
  35. set "SELF=%~dp0%service.bat"
  36. rem Guess CATALINA_HOME if not defined
  37. set "CURRENT_DIR=%cd%"
  38. if not "%CATALINA_HOME%" == "" goto gotHome
  39. set "CATALINA_HOME=%cd%"
  40. if exist "%CATALINA_HOME%\bin\tomcat7.exe" goto okHome
  41. rem CD to the upper dir
  42. cd ..
  43. set "CATALINA_HOME=%cd%"
  44. :gotHome
  45. if exist "%CATALINA_HOME%\bin\tomcat7.exe" goto okHome
  46. echo The tomcat.exe was not found...
  47. echo The CATALINA_HOME environment variable is not defined correctly.
  48. echo This environment variable is needed to run this program
  49. goto end
  50. :okHome
  51. rem Make sure prerequisite environment variables are set
  52. if not "%JAVA_HOME%" == "" goto gotJdkHome
  53. if not "%JRE_HOME%" == "" goto gotJreHome
  54. echo Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
  55. echo Service will try to guess them from the registry.
  56. goto okJavaHome
  57. :gotJreHome
  58. REM if not exist "%JRE_HOME%\bin\java.exe" goto noJavaHome
  59. REM if not exist "%JRE_HOME%\bin\javaw.exe" goto noJavaHome
  60. goto okJavaHome
  61. :gotJdkHome
  62. REM if not exist "%JAVA_HOME%\jre\bin\java.exe" goto noJavaHome
  63. REM if not exist "%JAVA_HOME%\jre\bin\javaw.exe" goto noJavaHome
  64. REM if not exist "%JAVA_HOME%\bin\javac.exe" goto noJavaHome
  65. if not "%JRE_HOME%" == "" goto okJavaHome
  66. set "JRE_HOME=%JAVA_HOME%\jre"
  67. goto okJavaHome
  68. :noJavaHome
  69. echo The JAVA_HOME environment variable is not defined correctly
  70. echo This environment variable is needed to run this program
  71. echo NB: JAVA_HOME should point to a JDK not a JRE
  72. goto end
  73. :okJavaHome
  74. if not "%CATALINA_BASE%" == "" goto gotBase
  75. set "CATALINA_BASE=%CATALINA_HOME%"
  76. :gotBase
  77.  
  78. set "EXECUTABLE=%CATALINA_HOME%\bin\tomcat7.exe"
  79.  
  80. rem Set default Service name
  81. set SERVICE_NAME=Tomcat7
  82. set PR_DISPLAYNAME=Apache Tomcat 7
  83.  
  84. if "x%1x" == "xx" goto displayUsage
  85. set SERVICE_CMD=%1
  86. shift
  87. if "x%1x" == "xx" goto checkServiceCmd
  88. :checkUser
  89. if "x%1x" == "x/userx" goto runAsUser
  90. if "x%1x" == "x--userx" goto runAsUser
  91. set SERVICE_NAME=%1
  92. set PR_DISPLAYNAME=Apache Tomcat %1
  93. shift
  94. if "x%1x" == "xx" goto checkServiceCmd
  95. goto checkUser
  96. :runAsUser
  97. shift
  98. if "x%1x" == "xx" goto displayUsage
  99. set SERVICE_USER=%1
  100. shift
  101. runas /env /savecred /user:%SERVICE_USER% "%COMSPEC% /K \"%SELF%\" %SERVICE_CMD% %SERVICE_NAME%"
  102. goto end
  103. :checkServiceCmd
  104. if /i %SERVICE_CMD% == install goto doInstall
  105. if /i %SERVICE_CMD% == remove goto doRemove
  106. if /i %SERVICE_CMD% == uninstall goto doRemove
  107. echo Unknown parameter "%1"
  108. :displayUsage
  109. echo.
  110. echo Usage: service.bat install/remove [service_name] [/user username]
  111. goto end
  112.  
  113. :doRemove
  114. rem Remove the service
  115. "%EXECUTABLE%" //DS//%SERVICE_NAME%
  116. if not errorlevel 1 goto removed
  117. echo Failed removing '%SERVICE_NAME%' service
  118. goto end
  119. :removed
  120. echo The service '%SERVICE_NAME%' has been removed
  121. goto end
  122.  
  123. :doInstall
  124. rem Install the service
  125. echo Installing the service '%SERVICE_NAME%' ...
  126. echo Using CATALINA_HOME: "%CATALINA_HOME%"
  127. echo Using CATALINA_BASE: "%CATALINA_BASE%"
  128. echo Using JAVA_HOME: "%JAVA_HOME%"
  129. echo Using JRE_HOME: "%JRE_HOME%"
  130.  
  131. rem Use the environment variables as an example
  132. rem Each command line option is prefixed with PR_
  133.  
  134. set PR_DESCRIPTION=Apache Tomcat 7.0.27 Server - http://tomcat.apache.org/
  135. set "PR_INSTALL=%EXECUTABLE%"
  136. set "PR_LOGPATH=%CATALINA_BASE%\logs"
  137. set "PR_CLASSPATH=%CATALINA_HOME%\bin\bootstrap.jar;%CATALINA_BASE%\bin\tomcat-juli.jar;%CATALINA_HOME%\bin\tomcat-juli.jar"
  138. rem Set the server jvm from JAVA_HOME
  139. set "PR_JVM=%JRE_HOME%\bin\server\jvm.dll"
  140. if exist "%PR_JVM%" goto foundJvm
  141. rem Set the client jvm from JAVA_HOME
  142. set "PR_JVM=%JRE_HOME%\bin\client\jvm.dll"
  143. if exist "%PR_JVM%" goto foundJvm
  144. set PR_JVM=auto
  145. :foundJvm
  146. echo Using JVM: "%PR_JVM%"
  147. "%EXECUTABLE%" //IS//%SERVICE_NAME% --StartClass org.apache.catalina.startup.Bootstrap --StopClass org.apache.catalina.startup.Bootstrap --StartParams start --StopParams stop
  148. if not errorlevel 1 goto installed
  149. echo Failed installing '%SERVICE_NAME%' service
  150. goto end
  151. :installed
  152. rem Clear the environment variables. They are not needed any more.
  153. set PR_DISPLAYNAME=
  154. set PR_DESCRIPTION=
  155. set PR_INSTALL=
  156. set PR_LOGPATH=
  157. set PR_CLASSPATH=
  158. set PR_JVM=
  159. rem Set extra parameters
  160. "%EXECUTABLE%" //US//%SERVICE_NAME% --JvmOptions "-Dcatalina.base=%CATALINA_BASE%;-Dcatalina.home=%CATALINA_HOME%;-Dderby.system.home=c:\ebasexi\UfsServer\DB;-Djava.endorsed.dirs=%CATALINA_HOME%\endorsed" --StartMode jvm --StopMode jvm
  161. rem More extra parameters
  162. set "PR_LOGPATH=%CATALINA_BASE%\logs"
  163. set PR_STDOUTPUT=auto
  164. set PR_STDERROR=auto
  165. "%EXECUTABLE%" //US//%SERVICE_NAME% ++JvmOptions "-DXX:MaxPermSize=512m -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 512 --JvmMx 512 -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9999 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false
  166. echo The service '%SERVICE_NAME%' has been installed.
  167.  
  168. :end
  169. cd "%CURRENT_DIR%"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement