service.bat 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. @echo off
  2. if "%OS%" == "Windows_NT" setlocal
  3. rem ---------------------------------------------------------------------------
  4. rem NT Service Install/Uninstall script
  5. rem
  6. rem Options
  7. rem install Install the service using Tomcat5 as service name.
  8. rem Service is installed using default settings.
  9. rem remove Remove the service from the System.
  10. rem
  11. rem name (optional) If the second argument is present it is considered
  12. rem to be new service name
  13. rem
  14. rem $Id: service.bat,v 1.5.2.1 2004/08/23 22:54:32 mturk Exp $
  15. rem ---------------------------------------------------------------------------
  16. rem Guess CATALINA_HOME if not defined
  17. set CURRENT_DIR=%cd%
  18. if not "%CATALINA_HOME%" == "" goto gotHome
  19. set CATALINA_HOME=%cd%
  20. if exist "%CATALINA_HOME%\bin\tomcat5.exe" goto okHome
  21. rem CD to the upper dir
  22. cd ..
  23. set CATALINA_HOME=%cd%
  24. :gotHome
  25. if exist "%CATALINA_HOME%\bin\tomcat5.exe" goto okHome
  26. echo The tomcat.exe was not found...
  27. echo The CATALINA_HOME environment variable is not defined correctly.
  28. echo This environment variable is needed to run this program
  29. goto end
  30. rem Make sure prerequisite environment variables are set
  31. if not "%JAVA_HOME%" == "" goto okHome
  32. echo The JAVA_HOME environment variable is not defined
  33. echo This environment variable is needed to run this program
  34. goto end
  35. :okHome
  36. if not "%CATALINA_BASE%" == "" goto gotBase
  37. set CATALINA_BASE=%CATALINA_HOME%
  38. :gotBase
  39. set EXECUTABLE=%CATALINA_HOME%\bin\tomcat5.exe
  40. rem Set default Service name
  41. set SERVICE_NAME=Tomcat5
  42. set PR_DISPLAYNAME=Apache Tomcat
  43. if "%1" == "" goto displayUsage
  44. if "%2" == "" goto setServiceName
  45. set SERVICE_NAME=%2
  46. set PR_DISPLAYNAME=Apache Tomcat %2
  47. :setServiceName
  48. if %1 == install goto doInstall
  49. if %1 == remove goto doRemove
  50. echo Unknown parameter "%1"
  51. :displayUsage
  52. echo
  53. echo Usage: service.bat install/remove [service_name]
  54. goto end
  55. :doRemove
  56. rem Remove the service
  57. "%EXECUTABLE%" //DS//%SERVICE_NAME%
  58. echo The service '%SERVICE_NAME%' has been removed
  59. goto end
  60. :doInstall
  61. rem Install the service
  62. echo Installing the service '%SERVICE_NAME%' ...
  63. echo Using CATALINA_HOME: %CATALINA_HOME%
  64. echo Using JAVA_HOME: %JAVA_HOME%
  65. rem Use the environment variables as an exaple
  66. rem Each command line option is prefixed with PR_
  67. set PR_DESCRIPTION=Apache Tomcat Server - http://jakarta.apache.org/tomcat
  68. set PR_INSTALL=%EXECUTABLE%
  69. set PR_LOGPATH=%CATALINA_HOME%\logs
  70. set PR_CLASSPATH=%JAVA_HOME%\lib\tools.jar;%CATALINA_HOME%\bin\bootstrap.jar
  71. rem Set the server jvm frrom JAVA_HOME
  72. set PR_JVM=%JAVA_HOME%\jre\bin\server\jvm.dll
  73. rem You can use the 'set PR_JVM=auto' for default JVM
  74. "%EXECUTABLE%" //IS//%SERVICE_NAME% --StartClass org.apache.catalina.startup.Bootstrap --StopClass org.apache.catalina.startup.Bootstrap --StartParams start --StopParams stop
  75. rem Clear the environment variables. They are not needed any more.
  76. set PR_DISPLAYNAME=
  77. set PR_DESCRIPTION=
  78. set PR_INSTALL=
  79. set PR_LOGPATH=
  80. set PR_CLASSPATH=
  81. set PR_JVM=
  82. rem Set extra parameters
  83. "%EXECUTABLE%" //US//%SERVICE_NAME% --JvmOptions "-Dcatalina.base=%CATALINA_BASE%;-Dcatalina.home=%CATALINA_HOME%;-Djava.endorsed.dirs=%CATALINA_HOME%\common\endorsed" --StartMode jvm --StopMode jvm
  84. rem More extra parameters
  85. set PR_STDOUTPUT=%CATALINA_HOME%\logs\stdout.log
  86. set PR_STDERROR=%CATALINA_HOME%\logs\stderr.log
  87. "%EXECUTABLE%" //US//%SERVICE_NAME% ++JvmOptions "-Djava.io.tmpdir=%CATALINA_BASE%\temp" --JvmMs 128 --JvmMx 256
  88. echo The service '%SERVICE_NAME%' has been installed.
  89. :end
  90. cd %CURRENT_DIR%