1@echo off
2rem -------------------------------------------------------------------------
3rem JBoss Bootstrap Script for Windows
4rem -------------------------------------------------------------------------
5
6rem Use --debug to activate debug mode with an optional argument to specify the port
7rem Usage : standalone.bat --debug
8rem         standalone.bat --debug 9797
9
10@if not "%ECHO%" == ""  echo %ECHO%
11@if "%OS%" == "Windows_NT" setlocal
12
13rem By default debug mode is disable.
14set DEBUG_MODE=false
15set DEBUG_PORT=8787
16rem Set to all parameters by default
17set "SERVER_OPTS=%*"
18
19if NOT "x%DEBUG%" == "x" (
20  set "DEBUG_MODE=%DEBUG%
21)
22
23rem Get the program name before using shift as the command modify the variable ~nx0
24if "%OS%" == "Windows_NT" (
25  set "PROGNAME=%~nx0%"
26) else (
27  set "PROGNAME=standalone.bat"
28)
29
30if "%OS%" == "Windows_NT" (
31  set "DIRNAME=%~dp0%"
32) else (
33  set DIRNAME=.\
34)
35setlocal EnableDelayedExpansion
36rem check for the security manager system property
37echo(!SERVER_OPTS! | findstr /r /c:"-Djava.security.manager" > nul
38if not errorlevel == 1 (
39    echo ERROR: The use of -Djava.security.manager has been removed. Please use the -secmgr command line argument or SECMGR=true environment variable.
40    GOTO :EOF
41)
42setlocal DisableDelayedExpansion
43
44rem Read command-line args, the ~ removes the quotes from the parameter
45:READ-ARGS
46if "%~1" == "" (
47   goto MAIN
48) else if "%~1" == "--debug" (
49   goto READ-DEBUG-PORT
50) else if "%~1" == "-secmgr" (
51   set SECMGR=true
52)
53shift
54goto READ-ARGS
55
56:READ-DEBUG-PORT
57set "DEBUG_MODE=true"
58set DEBUG_ARG="%2"
59if not %DEBUG_ARG% == "" (
60   if x%DEBUG_ARG:-=%==x%DEBUG_ARG% (
61      shift
62      set DEBUG_PORT=%DEBUG_ARG%
63   )
64   shift
65   goto READ-ARGS
66)
67
68:MAIN
69rem $Id$
70)
71
72pushd "%DIRNAME%.."
73set "RESOLVED_JBOSS_HOME=%CD%"
74popd
75
76if "x%JBOSS_HOME%" == "x" (
77  set "JBOSS_HOME=%RESOLVED_JBOSS_HOME%"
78)
79
80pushd "%JBOSS_HOME%"
81set "SANITIZED_JBOSS_HOME=%CD%"
82popd
83
84if /i "%RESOLVED_JBOSS_HOME%" NEQ "%SANITIZED_JBOSS_HOME%" (
85   echo.
86   echo   WARNING:  JBOSS_HOME may be pointing to a different installation - unpredictable results may occur.
87   echo.
88   echo       JBOSS_HOME: "%JBOSS_HOME%"
89   echo.
90)
91
92rem Read an optional configuration file.
93if "x%STANDALONE_CONF%" == "x" (
94   set "STANDALONE_CONF=%DIRNAME%standalone.conf.bat"
95)
96if exist "%STANDALONE_CONF%" (
97   echo Calling "%STANDALONE_CONF%"
98   call "%STANDALONE_CONF%" %*
99) else (
100   echo Config file not found "%STANDALONE_CONF%"
101)
102
103
104rem Set debug settings if not already set
105if "%DEBUG_MODE%" == "true" (
106   echo "%JAVA_OPTS%" | findstr /I "\-agentlib:jdwp" > nul
107  if errorlevel == 1 (
108     set "JAVA_OPTS=%JAVA_OPTS% -agentlib:jdwp=transport=dt_socket,address=%DEBUG_PORT%,server=y,suspend=n"
109  ) else (
110     echo Debug already enabled in JAVA_OPTS, ignoring --debug argument
111  )
112)
113
114set DIRNAME=
115
116rem Setup JBoss specific properties
117set "JAVA_OPTS=-Dprogram.name=%PROGNAME% %JAVA_OPTS%"
118
119if "x%JAVA_HOME%" == "x" (
120  set  JAVA=java
121  echo JAVA_HOME is not set. Unexpected results may occur.
122  echo Set JAVA_HOME to the directory of your local JDK to avoid this message.
123) else (
124  if not exist "%JAVA_HOME%" (
125    echo JAVA_HOME "%JAVA_HOME%" path doesn't exist
126    goto END
127  ) else (
128    echo Setting JAVA property to "%JAVA_HOME%\bin\java"
129    set "JAVA=%JAVA_HOME%\bin\java"
130  )
131)
132
133if not "%PRESERVE_JAVA_OPTS%" == "true" (
134  rem Add -client to the JVM options, if supported (32 bit VM), and not overriden
135  echo "%JAVA_OPTS%" | findstr /I \-server > nul
136  if errorlevel == 1 (
137    "%JAVA%" -client -version 2>&1 | findstr /I /C:"Client VM" > nul
138    if not errorlevel == 1 (
139      set "JAVA_OPTS=-client %JAVA_OPTS%"
140    )
141  )
142)
143
144rem EAP6-121 feature disabled
145rem if not "%PRESERVE_JAVA_OPTS%" == "true" (
146  rem Add rotating GC logs, if supported, and not already defined
147  rem echo "%JAVA_OPTS%" | findstr /I "\-verbose:gc" > nul
148  rem if errorlevel == 1 (
149    rem Back up any prior logs
150    rem move /y "%JBOSS_LOG_DIR%\gc.log.0" "%JBOSS_LOG_DIR%\backupgc.log.0" > nul 2>&1
151    rem move /y "%JBOSS_LOG_DIR%\gc.log.1" "%JBOSS_LOG_DIR%\backupgc.log.1" > nul 2>&1
152    rem move /y "%JBOSS_LOG_DIR%\gc.log.2" "%JBOSS_LOG_DIR%\backupgc.log.2" > nul 2>&1
153    rem move /y "%JBOSS_LOG_DIR%\gc.log.3" "%JBOSS_LOG_DIR%\backupgc.log.3" > nul 2>&1
154    rem move /y "%JBOSS_LOG_DIR%\gc.log.4" "%JBOSS_LOG_DIR%\backupgc.log.4" > nul 2>&1
155    rem move /y "%JBOSS_LOG_DIR%\gc.log.*.current" "%JBOSS_LOG_DIR%\backupgc.log.current" > nul 2>&1
156    rem "%JAVA%" -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=3M -Xloggc:%XLOGGC% -XX:-TraceClassUnloading -version > nul 2>&1
157    rem if not errorlevel == 1 (
158      rem if not exist "%JBOSS_LOG_DIR" > nul 2>&1 (
159        rem mkdir "%JBOSS_LOG_DIR%"
160      rem )
161     rem set XLOGGC="%JBOSS_LOG_DIR%\gc.log"
162     rem set "JAVA_OPTS=-verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=3M -XX:-TraceClassUnloading %JAVA_OPTS%"
163    rem )
164  rem )
165rem )
166
167rem Find jboss-modules.jar, or we can't continue
168if exist "%JBOSS_HOME%\jboss-modules.jar" (
169    set "RUNJAR=%JBOSS_HOME%\jboss-modules.jar"
170) else (
171  echo Could not locate "%JBOSS_HOME%\jboss-modules.jar".
172  echo Please check that you are in the bin directory when running this script.
173  goto END
174)
175
176rem Setup JBoss specific properties
177
178rem Setup directories, note directories with spaces do not work
179setlocal EnableDelayedExpansion
180set "CONSOLIDATED_OPTS=%JAVA_OPTS% %SERVER_OPTS%"
181set baseDirFound=false
182set configDirFound=false
183set logDirFound=false
184for %%a in (!CONSOLIDATED_OPTS!) do (
185   if !baseDirFound! == true (
186      set "JBOSS_BASE_DIR=%%~a"
187      set baseDirFound=false
188   )
189   if !configDirFound! == true (
190      set "JBOSS_CONFIG_DIR=%%~a"
191      set configDirFound=false
192   )
193   if !logDirFound! == true (
194      set "JBOSS_LOG_DIR=%%~a"
195      set logDirFound=false
196   )
197   if "%%~a" == "-Djboss.server.base.dir" (
198       set baseDirFound=true
199   )
200   if "%%~a" == "-Djboss.server.config.dir" (
201       set configDirFound=true
202   )
203   if "%%~a" == "-Djboss.server.log.dir" (
204       set logDirFound=true
205   )
206)
207
208rem If the -Djava.security.manager is found, enable the -secmgr and include a bogus security manager for JBoss Modules to replace
209echo(!JAVA_OPTS! | findstr /r /c:"-Djava.security.manager" > nul && (
210    echo ERROR: The use of -Djava.security.manager has been removed. Please use the -secmgr command line argument or SECMGR=true environment variable.
211    GOTO :EOF
212)
213setlocal DisableDelayedExpansion
214
215rem Set default module root paths
216if "x%JBOSS_MODULEPATH%" == "x" (
217  set  "JBOSS_MODULEPATH=%JBOSS_HOME%\modules"
218)
219
220rem Set the standalone base dir
221if "x%JBOSS_BASE_DIR%" == "x" (
222  set  "JBOSS_BASE_DIR=%JBOSS_HOME%\standalone"
223)
224rem Set the standalone log dir
225if "x%JBOSS_LOG_DIR%" == "x" (
226  set  "JBOSS_LOG_DIR=%JBOSS_BASE_DIR%\log"
227)
228rem Set the standalone configuration dir
229if "x%JBOSS_CONFIG_DIR%" == "x" (
230  set  "JBOSS_CONFIG_DIR=%JBOSS_BASE_DIR%\configuration"
231)
232
233rem Set the module options
234set "MODULE_OPTS="
235if "%SECMGR%" == "true" (
236    set "MODULE_OPTS=-secmgr"
237)
238
239echo ===============================================================================
240echo.
241echo   JBoss Bootstrap Environment
242echo.
243echo   JBOSS_HOME: "%JBOSS_HOME%"
244echo.
245echo   JAVA: "%JAVA%"
246echo.
247echo   JAVA_OPTS: "%JAVA_OPTS%"
248echo.
249echo ===============================================================================
250echo.
251
252:RESTART
253rem if x%XLOGGC% == x (
254  "%JAVA%" %JAVA_OPTS% ^
255   "-Dorg.jboss.boot.log.file=%JBOSS_LOG_DIR%\server.log" ^
256   "-Dlogging.configuration=file:%JBOSS_CONFIG_DIR%/logging.properties" ^
257      -jar "%JBOSS_HOME%\jboss-modules.jar" ^
258      %MODULE_OPTS% ^
259      -mp "%JBOSS_MODULEPATH%" ^
260       org.jboss.as.standalone ^
261      "-Djboss.home.dir=%JBOSS_HOME%" ^
262       %SERVER_OPTS%
263rem ) else (
264  rem "%JAVA%" -Xloggc:%XLOGGC% %JAVA_OPTS% ^
265   rem "-Dorg.jboss.boot.log.file=%JBOSS_LOG_DIR%\server.log" ^
266   rem "-Dlogging.configuration=file:%JBOSS_CONFIG_DIR%/logging.properties" ^
267      rem -jar "%JBOSS_HOME%\jboss-modules.jar" ^
268      rem %MODULE_OPTS% ^
269      rem -mp "%JBOSS_MODULEPATH%" ^
270      rem org.jboss.as.standalone ^
271      rem "-Djboss.home.dir=%JBOSS_HOME%" ^
272      rem %SERVER_OPTS%
273rem )
274
275if ERRORLEVEL 10 goto RESTART
276
277:END
278if "x%NOPAUSE%" == "x" pause
279
280:END_NO_PAUSE
281