JBoss 5 YAJSW service wrapper script


/ Published in: DOS Batch
Save to your folder(s)

A DOS batch script to handle registering and controlling a JBoss service.


Copy this code and paste it in your HTML
  1. @ECHO off
  2. SETLOCAL ENABLEDELAYEDEXPANSION
  3. CLS
  4. :: place this next to the run.bat in your JBoss distro and run it
  5. IF EXIST C:\Users (
  6. ECHO Current User is '%USERNAME%'
  7. ECHO INFO: You may need to run this script as 'Administrator' user.
  8. )
  9.  
  10. ::-------------------------------------------------------------------
  11. :: Set TITLE, JBOSS_HOME, and DIRNAME variables
  12. ::-------------------------------------------------------------------
  13. SET JBOSS_HOME=%~dp0
  14. FOR /F "delims=\" %%a IN ("%JBOSS_HOME%") DO SET "DIRNAME=%%~nxa"
  15. SET "APPDIR=%DIRNAME%"
  16. SET "JBOSS_HOME=%JBOSS_HOME:bin\=%"
  17. IF %JBOSS_HOME:~-1%==\ SET "JBOSS_HOME=%JBOSS_HOME:~0,-1%"
  18.  
  19. ::-------------------------------------------------------------------
  20. :: Handle script args
  21. ::-------------------------------------------------------------------
  22. SET PICK=%~1
  23. SET SERVICENAME=%~2
  24. IF "%SERVICENAME%"=="" SET SERVICENAME=JBOSS
  25. SET TITLETEXT=%SERVICENAME% Service Controller
  26. TITLE %TITLETEXT%
  27.  
  28. ::-------------------------------------------------------------------
  29. :: Parse first script argument for service action
  30. :: If no args are passed then prompt user
  31. ::-------------------------------------------------------------------
  32.  
  33. :MAKECHOICE
  34. IF "%PICK%"=="" (
  35. ECHO -----------------------------
  36. ECHO Options menu:
  37. ECHO -----------------------------
  38. ECHO [auto] Install and start service
  39. ECHO [install] Install service
  40. ECHO [start] Start service
  41. ECHO [stop] Stop service
  42. ECHO [remove] Remove or uninstall service
  43. ECHO [console] Run service as console
  44. ECHO [status] Query service status
  45. ) ELSE (
  46. ECHO Running silently since script has arguments.
  47. )
  48.  
  49. IF "%PICK%"=="" SET /P "PICK=Please enter a service action you want to perform [2]: "
  50.  
  51. IF EXIST servicename.txt SET /P SERVICENAME=<servicename.txt
  52.  
  53. IF "%PICK%"=="" (
  54. ECHO Empty answer. Try Again.
  55. GOTO :MAKECHOICE
  56. )
  57. IF "%PICK%"=="auto" (
  58. IF "%SERVICENAME%"=="" (
  59. ECHO Choice fails without a second script argument passing service name.
  60. GOTO :END
  61. )
  62. ECHO %SERVICENAME%>>servicename.txt
  63. SET ACTION=Starting
  64. SET OPTION=-t
  65. GOTO :ACTIONSET
  66. )
  67. IF "%PICK%"=="install" (
  68. IF "%SERVICENAME%"=="" (
  69. ECHO Choice fails without a second script argument passing service name.
  70. GOTO :END
  71. )
  72. ECHO %SERVICENAME%>>servicename.txt
  73. SET ACTION=Installing
  74. SET OPTION=-i
  75. GOTO :ACTIONSET
  76. )
  77. IF "%PICK%"=="start" (
  78. SET ACTION=Starting
  79. SET OPTION=-t
  80. GOTO :ACTIONSET
  81. )
  82. IF "%PICK%"=="stop" (
  83. SET ACTION=Stopping
  84. SET OPTION=-p
  85. GOTO :ACTIONSET
  86. )
  87. IF "%PICK%"=="remove" (
  88. SET ACTION=Uninstalling
  89. SET OPTION=-r
  90. GOTO :ACTIONSET
  91. )
  92. IF "%PICK%"=="console" (
  93. SET ACTION=Console
  94. SET OPTION=-c
  95. GOTO :ACTIONSET
  96. )
  97. IF "%PICK%"=="status" (
  98. SET ACTION=Querying
  99. SET OPTION=-q
  100. GOTO :ACTIONSET
  101. )
  102. IF "%PICK%"=="X" GOTO :EOF
  103. IF "%PICK%"=="x" GOTO :EOF
  104.  
  105. :ACTIONSET
  106.  
  107. SET "WRAPPER_CONFIG_FILE=%JBOSS_HOME%\%APPDIR%\wrapper\wrapper.jboss.conf"
  108.  
  109. ::-------------------------------------------------------------------
  110. :: Set java options for wrapper
  111. :: Change back-slashes to forward-slashes before passing options to the wrapper
  112. ::-------------------------------------------------------------------
  113. SET "WRAPPER_ARGS=-Djboss.home=%JBOSS_HOME% -Djboss.dir=%APPDIR% -Dservice.name=%SERVICENAME%"
  114. SET WRAPPER_ARGS=%WRAPPER_ARGS:\=/%
  115.  
  116. ::-------------------------------------------------------------------
  117. :: Info output
  118. ::-------------------------------------------------------------------
  119. ECHO -- These variables are set by this script and passed to the service installation:
  120. ECHO JAVA_HOME=%JAVA_HOME%
  121. ECHO JBOSS_HOME=%JBOSS_HOME%
  122. ECHO APPDIR=%APPDIR%
  123. ECHO WRAPPER_CONFIG_FILE: %WRAPPER_CONFIG_FILE%
  124. ECHO WRAPPER_ARGS=%WRAPPER_ARGS%
  125. ECHO SERVICENAME=%SERVICENAME%
  126. ECHO ACTION=%ACTION%
  127. ECHO OPTION=%OPTION%
  128. ::ECHO -- Before you install this service make sure that you properly configured the
  129. ::ECHO property called "wrapper.ntservice.account" in the wrapper config file.
  130. ::ECHO (It will default to running as the "Local System" user.)
  131.  
  132. ::-------------------------------------------------------------------
  133. :: Install service
  134. ::-------------------------------------------------------------------
  135.  
  136. IF "%PICK%"=="remove" (
  137. DEL /Q servicename.txt
  138. )
  139. IF "%PICK%"=="auto" (
  140. :: when auto, perform 1 additional action
  141. ECHO Registering service ...
  142. ECHO "%JAVA_HOME%\bin\java.exe" %WRAPPER_ARGS% -jar %JBOSS_HOME%\%APPDIR%\wrapper\wrapper.jar -i %WRAPPER_CONFIG_FILE%
  143. CALL "%JAVA_HOME%\bin\java.exe" %WRAPPER_ARGS% -jar %JBOSS_HOME%\%APPDIR%\wrapper\wrapper.jar -i %WRAPPER_CONFIG_FILE%
  144. CALL :WAIT
  145. )
  146. ECHO %ACTION% service ...
  147. ECHO "%JAVA_HOME%\bin\java.exe" %WRAPPER_ARGS% -jar %JBOSS_HOME%\%APPDIR%\wrapper\wrapper.jar %OPTION% %WRAPPER_CONFIG_FILE%
  148. CALL "%JAVA_HOME%\bin\java.exe" %WRAPPER_ARGS% -jar %JBOSS_HOME%\%APPDIR%\wrapper\wrapper.jar %OPTION% %WRAPPER_CONFIG_FILE%
  149.  
  150. ECHO %ACTION% service ^"%SERVICENAME%^" is finished.
  151.  
  152. ::-------------------------------------------------------------------
  153. :: Functions
  154. ::-------------------------------------------------------------------
  155. :GET_DIR
  156. SET "_TMPDIR=%~dp1"
  157. SET "_TMPDIR=%_TMPDIR:~0,-1%"
  158. EXIT /B 0
  159.  
  160. :WAIT
  161. PING.exe -n 6 -w 1 127.0.0.1>nul
  162. EXIT /B 0
  163.  
  164. ::-------------------------------------------------------------------
  165. :: End script
  166. ::-------------------------------------------------------------------
  167. :END
  168. FOR /l %%a IN (5,-1,1) DO (TITLE JBoss %APPDIR% -- Closing in %%as&PING.exe -n 2 -w 1 127.0.0.1>nul)

URL: https://gist.github.com/4271240

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.