Last active
December 17, 2015 17:38
-
-
Save djangofan/5646932 to your computer and use it in GitHub Desktop.
Native service.bat for JBoss6EAP or JBoss7CE on Windows. Doesn't completely work.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ECHO off | |
SET SCRIPTTITLE=Jboss Service Script | |
TITLE %SCRIPTTITLE% | |
:: ------------------------------------------------------------------------- | |
:: JBoss/WildFly, the OpenSource webOS | |
:: JBoss 6.01EAP/7CE Native Service Wrapper Script for Windows | |
:: ------------------------------------------------------------------------- | |
IF NOT "%ECHO%" == "" ECHO %ECHO% | |
IF "%OS%" == "Windows_NT" SETLOCAL | |
SET JB_HOME=%CD% | |
SET "JB_HOME=%JB_HOME:bin=%" | |
IF %JB_HOME:~-1%==\ SET "JB_HOME=%JB_HOME:~0,-1%" | |
ECHO JB_HOME=%JB_HOME% | |
ECHO. | |
::------------------------------------------------------------------- | |
:: JAVA_HOME override | |
:: Uncomment the next line to override JAVA_HOME on your system | |
::------------------------------------------------------------------- | |
SET JAVA_HOME=C:\AeroFS\Java64\jdk1.7.0_17_x64 | |
::------------------------------------------------------------------- | |
:: Verify JAVA_HOME | |
::------------------------------------------------------------------- | |
IF NOT DEFINED JAVA_HOME ( | |
ECHO JAVA_HOME must be defined as an environment variable. | |
GOTO :cmdEnd | |
) ELSE ( | |
SET "PATH=%JAVA_HOME%\bin;%PATH%" | |
) | |
IF NOT EXIST "%JAVA_HOME%" ( | |
ECHO JAVA_HOME must be defined to an actual location. | |
ECHO Also, make sure you used the override in this script correctly. | |
GOTO :cmdEnd | |
) | |
ECHO JAVA_HOME=%JAVA_HOME% | |
ECHO. | |
::------------------------------------------------------------------- | |
:: Detect Java JRE architecture and SET JAVA_ARCH | |
::------------------------------------------------------------------- | |
ECHO Checking that JRE bit architecture matches cmd.exe bit architecture... | |
"%JAVA_HOME%\bin\java.exe" -version 2>&1 | findstr "64-Bit">NUL | |
IF %ERRORLEVEL% == 0 ( | |
SET JAVA_ARCH=64 | |
) ELSE ( | |
SET JAVA_ARCH=32 | |
) | |
ECHO Java architecture is %JAVA_ARCH%-bit. | |
ECHO. | |
:: ------------------------------------------------------------------------- | |
:: Script configuration parameters. | |
:: Standard JMX port is 9999 | |
:: ------------------------------------------------------------------------- | |
SET JBOSS_VER=JB601EAP | |
SET INSTANCE=ports-01 | |
SET SVCNAME=%JBOSS_VER%-%INSTANCE% | |
SET SVCDISP=%SVCNAME% | |
SET SVCDESC=JBoss 6.0.1 %JAVA_ARCH%-bit running in ^"%JB_HOME%\bin^" | |
SET NOPAUSE=Y | |
SET /A CLOSE_DELAY=30 | |
SET /A JMXPORT=10099 | |
:: verify JBoss7 objects are in current directory and set JBOSS_HOME | |
IF NOT EXIST jboss-cli.bat ECHO Missing jboss-cli.bat & GOTO :cmdEnd | |
IF NOT EXIST standalone.bat ECHO Missing standalone.bat & GOTO :cmdEnd | |
::------------------------------------------------------------------- | |
:: Check for required wrapper directory | |
::------------------------------------------------------------------- | |
IF NOT EXIST native\tcnative-1.dll ( | |
ECHO. | |
ECHO The wrapper required files are missing. | |
ECHO Download distro from http://www.jboss.org/jbossweb/downloads/jboss-native-2-0-10.html | |
C: | |
START "%ProgramFiles%\Internet Explorer\iexplore.exe" http://www.jboss.org/jbossweb/downloads/jboss-native-2-0-10.html | |
ECHO. | |
timeout 20 | |
GOTO :cmdEnd | |
) | |
:: verify instance dir exists | |
IF NOT EXIST "%JB_HOME%\%INSTANCE%" ( | |
ECHO Instance directory does not exist. Making a copy of the standalone instance. | |
XCOPY.exe "%JB_HOME%\standalone" "%JB_HOME%\%INSTANCE%" /Y /E /F /I | |
) | |
:: Figure out the running mode | |
SET ANSWER=%~1 | |
:ASK | |
IF /I "%ANSWER%" == "install" CALL :cmdInstall | |
IF /I "%ANSWER%" == "uninstall" CALL :cmdUninstall | |
IF /I "%ANSWER%" == "start" GOTO :cmdStart | |
IF /I "%ANSWER%" == "stop" GOTO :cmdStop | |
IF /I "%ANSWER%" == "restart" GOTO :cmdRestart | |
ECHO. | |
ECHO -------------------------------- | |
ECHO. | |
ECHO Usage: service install^|uninstall^|start^|stop^|restart | |
ECHO. | |
ECHO -------------------------------- | |
SET /P ANSWER=Enter an action for this script: | |
GOTO :ASK | |
GOTO :cmdEnd | |
:: jbosssvc return values | |
:: ERR_RET_USAGE 1 | |
:: ERR_RET_VERSION 2 | |
:: ERR_RET_INSTALL 3 | |
:: ERR_RET_REMOVE 4 | |
:: ERR_RET_PARAMS 5 | |
:: ERR_RET_MODE 6 | |
:errExplain | |
IF ERRORLEVEL 1 ECHO Invalid command line parameters | |
IF ERRORLEVEL 2 ECHO Failed installing %SVCDISP% | |
IF ERRORLEVEL 4 ECHO Failed removing %SVCDISP% | |
IF ERRORLEVEL 6 ECHO Unknown service mode for %SVCDISP% | |
EXIT /B 0 | |
:cmdInstall | |
ECHO Using JAVA_OPTS: %JAVA_OPTS% | |
ECHO Install: jbosssvc.exe -imwdc %SVCNAME% "%JB_HOME%" "%SVCDISP%" "%SVCDESC%" service.bat | |
ECHO. | |
jbosssvc.exe -imwdc %SVCNAME% "%JB_HOME%" "%SVCDISP%" "%SVCDESC%" service.bat | |
IF NOT ERRORLEVEL 0 GOTO :errExplain | |
ECHO Service %SVCDISP% installed | |
ECHO. | |
ECHO. | |
EXIT /B 0 | |
:cmdUninstall | |
jbosssvc.exe -u %SVCNAME% | |
IF NOT ERRORLEVEL 0 GOTO :errExplain | |
ECHO Service %SVCDISP% removed | |
ECHO. | |
ECHO. | |
EXIT /B 0 | |
:cmdStart | |
REM Executed on service start | |
del .r.lock 2>&1 | findstr /C:"being used" > nul | |
if not errorlevel 1 ( | |
echo Could not continue. Locking file already in use. | |
goto :cmdEnd | |
) | |
echo Y > .r.lock | |
jbosssvc.exe -p 1 "Starting %SVCDISP%" > run.log | |
CALL standalone.bat "-Djboss.server.base.dir=../%INSTANCE%" < .r.lock >> run.log 2>&1 | |
jbosssvc.exe -p 1 "Started %SVCDISP% service" >> run.log | |
del .r.lock | |
goto :cmdEnd | |
:cmdStop | |
REM Executed on service stop | |
echo Y > .s.lock | |
jbosssvc.exe -p 1 "Shutting down %SVCDISP%" > shutdown.log | |
NET STOP %SVCNAME% < .s.lock >> shutdown.log 2>&1 | |
jbosssvc.exe -p 1 "Shutdown %SVCDISP% service" >> shutdown.log | |
del .s.lock | |
goto :cmdEnd | |
:cmdRestart | |
REM Executed manually from command line | |
REM Note: We can only stop and start | |
echo Y > .s.lock | |
jbosssvc.exe -p 1 "Shutting down %SVCDISP%" >> shutdown.log | |
NET STOP %SVCNAME% < .s.lock >> shutdown.log 2>&1 | |
del .s.lock | |
:waitLoop | |
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 :waitLoop | |
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 | |
::------------------------------------------------------------------- | |
:: End script | |
::------------------------------------------------------------------- | |
:cmdEnd | |
ECHO. | |
ECHO Service script is finished and will close automatically in %CLOSE_DELAY% seconds. | |
FOR /l %%a IN (%CLOSE_DELAY%,-1,1) DO ( TITLE %SCRIPTTITLE% -- closing in %%as&ping -n 2 -w 1000 127.0.0.1>NUL ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ECHO off | |
:: ------------------------------------------------------------------------- | |
:: JBoss Bootstrap Script for Windows | |
:: ------------------------------------------------------------------------- | |
::------------------------------------------------------------------- | |
:: SET TITLE, JBOSS_HOME, and CDIR variables | |
::------------------------------------------------------------------- | |
SET CDIR=%CD% | |
SET RESOLVED_JBOSS_HOME=%~dp0 | |
SET "RESOLVED_JBOSS_HOME=%RESOLVED_JBOSS_HOME:bin\=%" | |
IF "%RESOLVED_JBOSS_HOME:~-1%"=="\" SET "RESOLVED_JBOSS_HOME=%RESOLVED_JBOSS_HOME:~0,-1%" | |
IF DEFINED JBOSS_HOME ( | |
ECHO. | |
ECHO WARNING: JBOSS_HOME may be pointing to a different installation - unpredictable results may occur. | |
ECHO. | |
ECHO JBOSS_HOME: %JBOSS_HOME% | |
ECHO RESOLVED_JBOSS_HOME: %RESOLVED_JBOSS_HOME% | |
ECHO. | |
) ELSE ( | |
SET JBOSS_HOME=%RESOLVED_JBOSS_HOME% | |
ECHO JBOSS_HOME was not defined. Using ^"%RESOLVED_JBOSS_HOME%^" | |
) | |
:: Read an optional configuration file. | |
IF "x%STANDALONE_CONF%" == "x" ( | |
SET "STANDALONE_CONF=%CDIR%\standalone.conf.bat" | |
) | |
IF EXIST "%STANDALONE_CONF%" ( | |
ECHO Calling "%STANDALONE_CONF%" | |
CALL "%STANDALONE_CONF%" %* | |
) ELSE ( | |
ECHO Config file not found "%STANDALONE_CONF%" | |
) | |
IF "%OS%" == "Windows_NT" ( | |
SET "PROGNAME=%~nx0%" | |
) ELSE ( | |
SET "PROGNAME=standalone.bat" | |
) | |
SET JAVA_OPTS=-Dprogram.name=%PROGNAME% %JAVA_OPTS% | |
IF "x%JAVA_HOME%" == "x" ( | |
SET JAVA=java | |
ECHO JAVA_HOME is not set. Unexpected results may occur. | |
ECHO SET JAVA_HOME to the directory of your local JDK to avoid this message. | |
) ELSE ( | |
SET "JAVA=%JAVA_HOME%\bin\java" | |
) | |
IF NOT "%PRESERVE_JAVA_OPTS%" == "true" ( | |
:: Add -client to the JVM options, IF supported (32 bit VM), and not overriden | |
ECHO "%JAVA_OPTS%" | findstr /I \-server > nul | |
IF ERRORLEVEL == 1 ( | |
"%JAVA%" -client -version 2>&1 | findstr /I /C:"Client VM" > nul | |
IF NOT ERRORLEVEL == 1 ( | |
SET "JAVA_OPTS=-client %JAVA_OPTS%" | |
) | |
) | |
) | |
IF NOT "%PRESERVE_JAVA_OPTS%" == "true" ( | |
:: Add compressed oops, IF supported (64 bit VM), and not overriden | |
ECHO "%JAVA_OPTS%" | findstr /I "\-XX:\-UseCompressedOops \-client" > nul | |
IF ERRORLEVEL == 1 ( | |
"%JAVA%" -XX:+UseCompressedOops -version > nul 2>&1 | |
IF NOT ERRORLEVEL == 1 ( | |
SET "JAVA_OPTS=-XX:+UseCompressedOops %JAVA_OPTS%" | |
) | |
) | |
) | |
IF NOT "%PRESERVE_JAVA_OPTS%" == "true" ( | |
:: Add tiered compilation, IF supported (64 bit VM), and not overriden | |
ECHO "%JAVA_OPTS%" | findstr /I "\-XX:\-TieredCompilation \-client" > nul | |
IF ERRORLEVEL == 1 ( | |
"%JAVA%" -XX:+TieredCompilation -version > nul 2>&1 | |
IF NOT ERRORLEVEL == 1 ( | |
SET "JAVA_OPTS=-XX:+TieredCompilation %JAVA_OPTS%" | |
) | |
) | |
) | |
:: Find jboss-modules.jar, or we can't continue | |
IF exist "%JBOSS_HOME%\jboss-modules.jar" ( | |
SET "RUNJAR=%JBOSS_HOME%\jboss-modules.jar" | |
) ELSE ( | |
ECHO Could not locate "%JBOSS_HOME%\jboss-modules.jar". | |
ECHO Please check that you are in the bin directory when running this script. | |
GOTO :END | |
) | |
:: Setup JBoss specific properties | |
:: Setup the java endorsed dirs | |
SET JBOSS_ENDORSED_DIRS=%JBOSS_HOME%\lib\endorsed | |
:: SET default module root paths | |
IF "x%JBOSS_MODULEPATH%" == "x" ( | |
SET "JBOSS_MODULEPATH=%JBOSS_HOME%\modules" | |
) | |
:: SET the standalone base dir | |
IF "x%JBOSS_BASE_DIR%" == "x" ( | |
SET "JBOSS_BASE_DIR=%JBOSS_HOME%\standalone" | |
) | |
:: SET the standalone log dir | |
IF "x%JBOSS_LOG_DIR%" == "x" ( | |
SET "JBOSS_LOG_DIR=%JBOSS_BASE_DIR%\log" | |
) | |
:: SET the standalone configuration dir | |
IF "x%JBOSS_CONFIG_DIR%" == "x" ( | |
SET "JBOSS_CONFIG_DIR=%JBOSS_BASE_DIR%/configuration" | |
) | |
ECHO =============================================================================== | |
echo. | |
ECHO JBoss Bootstrap Environment | |
echo. | |
ECHO JBOSS_HOME: %JBOSS_HOME% | |
echo. | |
ECHO JAVA: %JAVA% | |
echo. | |
ECHO JAVA_OPTS: %JAVA_OPTS% | |
echo. | |
ECHO =============================================================================== | |
echo. | |
:RESTART | |
"%JAVA%" %JAVA_OPTS% ^ | |
"-Dorg.jboss.boot.log.file=%JBOSS_LOG_DIR%\boot.log" ^ | |
"-Dlogging.configuration=file:%JBOSS_CONFIG_DIR%/logging.properties" ^ | |
-jar "%JBOSS_HOME%\jboss-modules.jar" ^ | |
-mp "%JBOSS_MODULEPATH%" ^ | |
-jaxpmodule "javax.xml.jaxp-provider" ^ | |
org.jboss.as.standalone ^ | |
-Djboss.home.dir="%JBOSS_HOME%" ^ | |
%* | |
IF ERRORLEVEL 10 GOTO :RESTART | |
:END | |
IF NOT DEFINED NOPAUSE pause | |
:END_NO_PAUSE | |
ECHO End of %~nx0 script. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:: ## -*- batch file -*- ###################################################### | |
:: ## | |
:: JBoss Bootstrap Script Configuration ## | |
:: ## | |
:: ############################################################################ | |
:: $Id: run.conf.bat 88820 2009-05-13 15:25:44Z dimitris@jboss.org $ | |
:: | |
:: This batch file is executed by run.bat to initialize the environment | |
:: variables that run.bat uses. It is recommended to use this file to | |
:: configure these variables, rather than modifying run.bat itself. | |
:: | |
:: Uncomment the following line to disable manipulation of JAVA_OPTS (JVM parameters) | |
:: set PRESERVE_JAVA_OPTS=true | |
set "JAVA_OPTS=%JAVA_OPTS% -Xrs" | |
:: | |
:: Specify the JBoss Profiler configuration file to load. | |
:: | |
:: Default is to not load a JBoss Profiler configuration file. | |
:: | |
:: set "PROFILER=%JBOSS_HOME%\bin\jboss-profiler.properties" | |
:: | |
:: Specify the location of the Java home directory (it is recommended that | |
:: this always be set). If set, then "%JAVA_HOME%\bin\java" will be used as | |
:: the Java VM executable; otherwise, "%JAVA%" will be used (see below). | |
:: | |
:: set "JAVA_HOME=C:\opt\jdk1.6.0_23" | |
:: | |
:: Specify the exact Java VM executable to use - only used if JAVA_HOME is | |
:: not set. Default is "java". | |
:: | |
:: set "JAVA=C:\opt\jdk1.6.0_23\bin\java" | |
:: Handle arguments given to this script | |
IF "%~1"=="" ECHO Script %~nx0 expects to get -Djboss.server.base.dir argument and did not. | |
IF NOT "%~2"=="" ECHO Script %~nx0 does not expect more than one argument. | |
IF NOT "%~1"=="" ECHO First arg passed to %~nx0 as JAVA_OPTS option: | |
ECHO %~1 | |
ECHO. | |
:: Append first arg to JAVA_OPTS | |
set "JAVA_OPTS=%JAVA_OPTS% -Xrs %~1" | |
:: | |
:: Specify options to pass to the Java VM. Note, there are some additional | |
:: options that are always passed by run.bat. | |
:: | |
:: JVM memory allocation pool parameters - modify as appropriate. | |
set "JAVA_OPTS=%JAVA_OPTS% -Xms1303M -Xmx1303M -XX:MaxPermSize=256M" | |
:: Reduce the RMI GCs to once per hour for Sun JVMs. | |
set "JAVA_OPTS=%JAVA_OPTS% -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -Djava.net.preferIPv4Stack=true" | |
:: Warn when resolving remote XML DTDs or schemas. | |
set "JAVA_OPTS=%JAVA_OPTS% -Dorg.jboss.resolver.warning=true" | |
:: Make Byteman classes visible in all module loaders | |
:: This is necessary to inject Byteman rules into AS7 deployments | |
set "JAVA_OPTS=%JAVA_OPTS% -Djboss.modules.system.pkgs=org.jboss.byteman" | |
:: Set the default configuration file to use if -c or --server-config are not used | |
set "JAVA_OPTS=%JAVA_OPTS% -Djboss.server.default.config=standalone.xml" | |
:: Sample JPDA settings for remote socket debugging | |
:: set "JAVA_OPTS=%JAVA_OPTS% -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n" | |
:: Sample JPDA settings for shared memory debugging | |
:: set "JAVA_OPTS=%JAVA_OPTS% -Xrunjdwp:transport=dt_shmem,address=jboss,server=y,suspend=n" | |
:: Use JBoss Modules lockless mode | |
:: set "JAVA_OPTS=%JAVA_OPTS% -Djboss.modules.lockless=true" | |
ECHO Options set by %~nx0 are: | |
ECHO JAVA_OPTS: %JAVA_OPTS% | |
ECHO. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment