Posted By

djangofan on 12/14/12


Tagged

service JBoss


Versions (?)

JBoss 5 YAJSW service wrapper script


 / Published in: DOS Batch
 

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

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

  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. ECHO.&ECHO.&ECHO.
  35. IF "%PICK%"=="" (
  36. ECHO -----------------------------
  37. ECHO Options menu:
  38. ECHO -----------------------------
  39. ECHO [auto] Install and start service
  40. ECHO [install] Install service
  41. ECHO [start] Start service
  42. ECHO [stop] Stop service
  43. ECHO [remove] Remove or uninstall service
  44. ECHO [console] Run service as console
  45. ECHO [status] Query service status
  46. ) ELSE (
  47. ECHO Running silently since script has arguments.
  48. )
  49.  
  50. IF "%PICK%"=="" SET /P "PICK=Please enter a service action you want to perform [2]: "
  51.  
  52. IF EXIST servicename.txt SET /P SERVICENAME=<servicename.txt
  53.  
  54. IF "%PICK%"=="" (
  55. ECHO Empty answer. Try Again.
  56. pause
  57. GOTO :MAKECHOICE
  58. )
  59. IF "%PICK%"=="auto" (
  60. IF "%SERVICENAME%"=="" (
  61. ECHO Choice fails without a second script argument passing service name.
  62. GOTO :END
  63. )
  64. ECHO %SERVICENAME%>>servicename.txt
  65. SET ACTION=Starting
  66. SET OPTION=-t
  67. GOTO :ACTIONSET
  68. )
  69. IF "%PICK%"=="install" (
  70. IF "%SERVICENAME%"=="" (
  71. ECHO Choice fails without a second script argument passing service name.
  72. GOTO :END
  73. )
  74. ECHO %SERVICENAME%>>servicename.txt
  75. SET ACTION=Installing
  76. SET OPTION=-i
  77. GOTO :ACTIONSET
  78. )
  79. IF "%PICK%"=="start" (
  80. SET ACTION=Starting
  81. SET OPTION=-t
  82. GOTO :ACTIONSET
  83. )
  84. IF "%PICK%"=="stop" (
  85. SET ACTION=Stopping
  86. SET OPTION=-p
  87. GOTO :ACTIONSET
  88. )
  89. IF "%PICK%"=="remove" (
  90. SET ACTION=Uninstalling
  91. SET OPTION=-r
  92. GOTO :ACTIONSET
  93. )
  94. IF "%PICK%"=="console" (
  95. SET ACTION=Console
  96. SET OPTION=-c
  97. GOTO :ACTIONSET
  98. )
  99. IF "%PICK%"=="status" (
  100. SET ACTION=Querying
  101. SET OPTION=-q
  102. GOTO :ACTIONSET
  103. )
  104. IF "%PICK%"=="X" GOTO :EOF
  105. IF "%PICK%"=="x" GOTO :EOF
  106.  
  107. :ACTIONSET
  108.  
  109. SET "WRAPPER_CONFIG_FILE=%JBOSS_HOME%\%APPDIR%\wrapper\wrapper.jboss.conf"
  110.  
  111. ::-------------------------------------------------------------------
  112. :: Set java options for wrapper
  113. :: Change back-slashes to forward-slashes before passing options to the wrapper
  114. ::-------------------------------------------------------------------
  115. SET "WRAPPER_ARGS=-Djboss.home=%JBOSS_HOME% -Djboss.dir=%APPDIR% -Dservice.name=%SERVICENAME%"
  116. SET WRAPPER_ARGS=%WRAPPER_ARGS:\=/%
  117.  
  118. ::-------------------------------------------------------------------
  119. :: Info output
  120. ::-------------------------------------------------------------------
  121. ECHO.
  122. ECHO -- These variables are set by this script and passed to the service installation:
  123. ECHO JAVA_HOME=%JAVA_HOME%
  124. ECHO JBOSS_HOME=%JBOSS_HOME%
  125. ECHO APPDIR=%APPDIR%
  126. ECHO WRAPPER_CONFIG_FILE: %WRAPPER_CONFIG_FILE%
  127. ECHO WRAPPER_ARGS=%WRAPPER_ARGS%
  128. ECHO SERVICENAME=%SERVICENAME%
  129. ECHO ACTION=%ACTION%
  130. ECHO OPTION=%OPTION%
  131. ECHO.
  132. ::ECHO -- Before you install this service make sure that you properly configured the
  133. ::ECHO property called "wrapper.ntservice.account" in the wrapper config file.
  134. ::ECHO (It will default to running as the "Local System" user.)
  135. ECHO.
  136.  
  137. ::-------------------------------------------------------------------
  138. :: Install service
  139. ::-------------------------------------------------------------------
  140. ECHO.
  141.  
  142. IF "%PICK%"=="remove" (
  143. DEL /Q servicename.txt
  144. )
  145. IF "%PICK%"=="auto" (
  146. :: when auto, perform 1 additional action
  147. ECHO Registering service ...
  148. ECHO "%JAVA_HOME%\bin\java.exe" %WRAPPER_ARGS% -jar %JBOSS_HOME%\%APPDIR%\wrapper\wrapper.jar -i %WRAPPER_CONFIG_FILE%
  149. CALL "%JAVA_HOME%\bin\java.exe" %WRAPPER_ARGS% -jar %JBOSS_HOME%\%APPDIR%\wrapper\wrapper.jar -i %WRAPPER_CONFIG_FILE%
  150. CALL :WAIT
  151. )
  152. ECHO.
  153. ECHO %ACTION% service ...
  154. ECHO "%JAVA_HOME%\bin\java.exe" %WRAPPER_ARGS% -jar %JBOSS_HOME%\%APPDIR%\wrapper\wrapper.jar %OPTION% %WRAPPER_CONFIG_FILE%
  155. CALL "%JAVA_HOME%\bin\java.exe" %WRAPPER_ARGS% -jar %JBOSS_HOME%\%APPDIR%\wrapper\wrapper.jar %OPTION% %WRAPPER_CONFIG_FILE%
  156.  
  157. ECHO.
  158. ECHO.
  159. ECHO %ACTION% service ^"%SERVICENAME%^" is finished.
  160.  
  161. ::-------------------------------------------------------------------
  162. :: Functions
  163. ::-------------------------------------------------------------------
  164. :GET_DIR
  165. SET "_TMPDIR=%~dp1"
  166. SET "_TMPDIR=%_TMPDIR:~0,-1%"
  167. EXIT /B 0
  168.  
  169. :WAIT
  170. PING.exe -n 6 -w 1 127.0.0.1>nul
  171. EXIT /B 0
  172.  
  173. ::-------------------------------------------------------------------
  174. :: End script
  175. ::-------------------------------------------------------------------
  176. :END
  177. 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)

Report this snippet  

You need to login to post a comment.