Author: tfonteyn
Date: 2012-04-24 09:52:53 -0400 (Tue, 24 Apr 2012)
New Revision: 2947
Modified:
trunk/utils/windows/native/service/examples/service.bat
Log:
[JBPAPP-8334]
Modified: trunk/utils/windows/native/service/examples/service.bat
===================================================================
--- trunk/utils/windows/native/service/examples/service.bat 2012-04-24 13:41:38 UTC (rev
2946)
+++ trunk/utils/windows/native/service/examples/service.bat 2012-04-24 13:52:53 UTC (rev
2947)
@@ -8,11 +8,23 @@
REM JBoss Service Script for Windows
REM -------------------------------------------------------------------------
-
@if not "%ECHO%" == "" echo %ECHO%
@if "%OS%" == "Windows_NT" setlocal
set DIRNAME=%CD%
+REM Read an optional configuration file located in the current (native/sbin) directory
+if "x%RUN_CONF%" == "x" (
+ set "RUN_CONF=%DIRNAME%\run.conf.bat"
+)
+if exist "%RUN_CONF%" (
+ call "%RUN_CONF%" %*
+)
+
+REM Modify these to set the profile to use and the bind address
+set SVCPROFILE=default
+set SVCBINDIP=127.0.0.1
+
+REM To run multiple instances, create a copy of the service.bat and modify
SVCNAME/SVCDISP/SVCDESC
REM
REM VERSION, VERSION_MAJOR and VERSION_MINOR are populated
REM during the build with ant filter.
@@ -22,9 +34,28 @@
set SVCDESC=JBoss Application Server @VERSION@/Platform: @VERSION_PLATFORM@
set NOPAUSE=Y
-REM Suppress killing service on logoff event
-set JAVA_OPTS=-Xrs
+REM Find the JBOSS-AS home
+if exist "..\..\jboss-as\bin\run.bat" (
+ set "EAPPATH=..\..\jboss-as\bin"
+) else if exist "..\bin\run.bat" (
+ set "EAPPATH=..\bin"
+) else if exist "run.bat" (
+ set "EAPPATH=."
+)
+if not "x%EAPPATH" == "x" goto getSvcPath
+echo Cannot find the run.bat.
+echo Invalid installation
+goto cmdEnd
+
+REM Translate to an absolute path
+:getSvcPath
+pushd %EAPPATH%
+set "SVCPATH=%CD%"
+popd
+
+set EAPPATH=
+
REM Figure out the running mode
if /I "%1" == "install" goto cmdInstall
@@ -36,7 +67,7 @@
echo Usage: service install^|uninstall^|start^|stop^|restart^|signal
goto cmdEnd
-REM jbosssvc retun values
+REM jbosssvc return values
REM ERR_RET_USAGE 1
REM ERR_RET_VERSION 2
REM ERR_RET_INSTALL 3
@@ -52,15 +83,17 @@
goto cmdEnd
:cmdInstall
-jbosssvc.exe -imwdc %SVCNAME% "%DIRNAME%" "%SVCDISP%"
"%SVCDESC%" service.bat
+echo Installing %SVCDISP%
+echo Using %SVCPATH%\run.bat
+
+REM %0 == service.bat, but allows you to have multiple services by duplicating the
service.bat file
+jbosssvc.exe -imwdc %SVCNAME% "%DIRNAME%" "%SVCDISP%"
"%SVCDESC%" %0
if not errorlevel 0 goto errExplain
-echo Service %SVCDISP% installed
goto cmdEnd
:cmdUninstall
jbosssvc.exe -u %SVCNAME%
if not errorlevel 0 goto errExplain
-echo Service %SVCDISP% removed
goto cmdEnd
:cmdStart
@@ -70,9 +103,36 @@
echo Could not continue. Locking file already in use.
goto cmdEnd
)
+
+REM initialise the log file
+echo %SVCPATH% > run.log
+
+REM Read the JBoss configuration file which sets JAVA_OPTS. First try to find it in the
selected profile, otherwise use the global one
+REM note the different var names to get around cmd.exe limitations
+set JAVA_OPTS=
+set RUN_CONF=
+set "RUN_CONF_PROFILE=%SVCPATH%\..\server\%SVCPROFILE%\conf\run.conf.bat"
+set "RUN_CONF_BIN=%SVCPATH%\run.conf.bat"
+if exist "%RUN_CONF_PROFILE%" (
+ call "%RUN_CONF_PROFILE%" %*
+) else (
+ if exist "%RUN_CONF_BIN%" (
+ call "%RUN_CONF_BIN%" %*
+ ) else (
+ echo "No run.conf.bat found" >> run.log
+ )
+)
+
+REM Suppress killing service on logoff event
+if "x%JAVA_OPTS%" == "x" (
+ set "JAVA_OPTS=-Xrs"
+) else (
+ set "JAVA_OPTS=-Xrs %JAVA_OPTS%"
+)
+
echo Y > .r.lock
-jbosssvc.exe -p 1 "Starting %SVCDISP%" > run.log
-call run.bat < .r.lock >> run.log 2>&1
+jbosssvc.exe -p 1 "Starting %SVCDISP%" >> run.log
+call "%SVCPATH%\run.bat" -c %SVCPROFILE% -b %SVCBINDIP% < .r.lock >>
run.log 2>&1
jbosssvc.exe -p 1 "Shutdown %SVCDISP% service" >> run.log
del .r.lock
goto cmdEnd
@@ -81,7 +141,7 @@
REM Executed on service stop
echo Y > .s.lock
jbosssvc.exe -p 1 "Shutting down %SVCDISP%" > shutdown.log
-call shutdown -S < .s.lock >> shutdown.log 2>&1
+call "%SVCPATH%\shutdown.bat" -S < .s.lock >> shutdown.log
2>&1
jbosssvc.exe -p 1 "Shutdown %SVCDISP% service" >> shutdown.log
del .s.lock
goto cmdEnd
@@ -91,20 +151,9 @@
REM Note: We can only stop and start
echo Y > .s.lock
jbosssvc.exe -p 1 "Shutting down %SVCDISP%" >> shutdown.log
-call shutdown -S < .s.lock >> shutdown.log 2>&1
+call "%SVCPATH%\shutdown.bat" -S < .s.lock >> shutdown.log
2>&1
del .s.lock
-:waitRun
-REM Delete lock file
-del .r.lock > nul 2>&1
-REM Wait one second if lock file exist
-jbosssvc.exe -s 1
-if exist ".r.lock" goto waitRun
-echo Y > .r.lock
-jbosssvc.exe -p 1 "Restarting %SVCDISP%" >> run.log
-call run.bat < .r.lock >> run.log 2>&1
-jbosssvc.exe -p 1 "Shutdown %SVCDISP% service" >> run.log
-del .r.lock
-goto cmdEnd
+goto cmdStart
:cmdSignal
REM Send signal to the service.
@@ -118,3 +167,4 @@
goto cmdEnd
:cmdEnd
+
Show replies by date