Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
@ECHO off
::-------------------------------------------------------------------
:: This is a script that handles the YAJSW Windows service wrapper
:: for Java. Without args, this script will prompt.
:: This script overrides the Jboss run.conf.bat file
:: This script enables JMX console listener for use by JVisualVM
:: This script forces you to run 32bit JBoss with 32bit cmd.exe shell
:: This script should work with JBoss 3, 4, 5, and 6
:: Author: Jon Austen
:: Date: December 2012
::-------------------------------------------------------------------
SETLOCAL ENABLEDELAYEDEXPANSION ENABLEEXTENSIONS
CLS
::-------------------------------------------------------------------
:: JAVA_HOME override
:: Uncomment the next line to override JAVA_HOME on your system
::-------------------------------------------------------------------
::SET JAVA_HOME=C:\Java\jdk1.6.0_33_x64
::-------------------------------------------------------------------
:: Set TITLE, JBOSS_HOME, and DIRNAME variables
::-------------------------------------------------------------------
SET JBOSS_HOME=%~dp0
SET "JBOSS_HOME=%JBOSS_HOME:bin\=%"
IF %JBOSS_HOME:~-1%==\ SET "JBOSS_HOME=%JBOSS_HOME:~0,-1%"
SET "THISFILE=%~n0%~x0"
SET TITLE=Starting %THISFILE%
::-------------------------------------------------------------------
:: Configuration:
:: before running you need to configure these
::-------------------------------------------------------------------
IF "%1"=="" (
SET DELAY=20
) ELSE (
SET DELAY=5
)
SET DEBUGLEVEL=DEBUG
SET DEFAULT_INSTANCE=ports-01
:: comment next line if you want script to prompt user for service startup TYPE
SET STARTUP_TYPE=auto
SET VER=
::-------------------------------------------------------------------
:: Parse script args
::-------------------------------------------------------------------
IF "%3%"=="" (
ECHO There are not 3 args.
IF "%2"=="" (
ECHO There are not 2 args.
IF "%1"=="" (
ECHO There is not even 1 script arg.
SET INSTANCE=%DEFAULT_INSTANCE%
SET TYPE=%STARTUP_TYPE%
SET ACTION=
GOTO :SETTYPE
) ELSE (
ECHO There is 1 arg.
SET ACTION=%1
SET INSTANCE=%DEFAULT_INSTANCE%
SET TYPE=%STARTUP_TYPE%
GOTO :SETTYPE
)
) ELSE (
ECHO There are 2 args.
SET ACTION=%1
ECHO Setting INSTANCE name to second script argument: %2
SET INSTANCE=%2
SET TYPE=%STARTUP_TYPE%
GOTO :SETTYPE
)
) ELSE (
ECHO There are 3 args.
IF NOT "%ACTION%"=="" (
ECHO Setting ACTION to execute: %1
)
SET ACTION=%1
ECHO Setting INSTANCE name of service: %2
SET INSTANCE=%2
ECHO Setting TYPE of service startup: %3
SET TYPE=%3
)
:SETTYPE
:: next, if STARTUP_TYPE is set to blank, prompt for it
IF "%TYPE%"=="" (
SET TYPE=
ECHO.&ECHO.
ECHO --------------------------
ECHO Service can be registered to start in different ways:
ECHO boot,system,auto,demand,disabled, or delayed-auto
ECHO --------------------------
SET /P "TYPE=Choose a service TYPE type: "
) ELSE (
SET TYPE=%TYPE%
)
CALL :verifytype
ECHO.
ECHO Parsed args: 1:%ACTION% 2:%INSTANCE% 3:%TYPE%
:BEGIN
::-------------------------------------------------------------------
:: Main script
::-------------------------------------------------------------------
CALL :mainheader
CALL :checks
CALL :wrappersetup
GOTO :MENU
:MENURESET
SET ACTION=
:MENU
SET TITLETEXT=%THISFILE% running JBOSS in ^"%JBOSS_HOME%\server\%INSTANCE%\^"
TITLE %TITLETEXT%
ECHO.
ECHO -----------------------------
ECHO Options MENU:
ECHO ----------------------------- &ECHO.
ECHO [install] Install service
ECHO [start] Start service
ECHO [stop] Stop service
ECHO [remove] Remove or uninstall service
ECHO [console] Run service as console
ECHO [query] Query service status
ECHO [usage] Display usage help
ECHO [X] Exit script
ECHO.
ECHO -----------------------------
ECHO.
IF "%ACTION%"=="" SET /P "ACTION=Choose an action type in this MENU to execute: "
ECHO.
IF "%ACTION%"=="X" GOTO :EOF
IF "%ACTION%"=="x" GOTO :EOF
IF "%ACTION%"=="usage" (
CALL :usage
PAUSE
IF "%1"=="" GOTO :MENURESET
)
IF "%ACTION%"=="install" (
CALL :startheader
CALL :addservice
IF "%1"=="" GOTO :MENURESET
)
IF "%ACTION%"=="start" (
SC.exe start %SERVICE_NAME%
CALL :servicestatus
IF "%1"=="" GOTO :MENURESET
)
IF "%ACTION%"=="stop" (
SC.exe stop %SERVICE_NAME%
CALL :servicestatus
IF "%1"=="" GOTO :MENURESET
)
IF "%ACTION%"=="remove" (
SC.exe delete %SERVICE_NAME%
IF "%1"=="" GOTO :MENURESET
)
IF "%ACTION%"=="console" (
DEL /Q "%JBOSS_HOME%\wrapper\log\*%INSTANCE%.log*"
SET TITLETEXT=JBOSS wrapper console in ^"%JBOSS_HOME%\server\%INSTANCE%^"
TITLE !TITLETEXT!
CALL :startheader
CALL :consoleservice
IF "%1"=="" GOTO :MENURESET
)
IF "%ACTION%"=="query" (
CALL :startheader
CALL :queryservice
CALL :displayports
IF "%1"=="" GOTO :MENURESET
)
GOTO :END
::-------------------------------------------------------------------
:: Functions
::-------------------------------------------------------------------
:addservice
ECHO Function: addservice
ECHO ***********************
ECHO Using wrapper to install service : service-name=%SERVICE_NAME%, startup-type=%TYPE%
ECHO "%JAVA_HOME%\bin\java.exe" %WRAPPER_ARGS% -jar %JBOSS_HOME%\bin\wrapper\wrapper.jar -i %WRAPPER_CONFIG_FILE%
CALL "%JAVA_HOME%\bin\java.exe" %WRAPPER_ARGS% -jar %JBOSS_HOME%\bin\wrapper\wrapper.jar -i %WRAPPER_CONFIG_FILE%
ECHO.
ECHO ***********************
SC.exe config %SERVICE_NAME% start= %TYPE%
ECHO Installing service ^"%SERVICE_NAME%^" is finished.
ECHO ***********************
ECHO.
EXIT /B 0
:checks
:: TODO: check not JBoss7
IF NOT EXIST wrapper\lib (
ECHO.
ECHO The YAJSW distributions 'lib' directory is needed in a directory called .\wrapper
ECHO that is relative to this script and the run.bat .
ECHO Under .\wrapper you also need the wrapper.jar and wrapper.jboss.conf .
ECHO Download distro from http://sourceforge.net/projects/yajsw/ .
C:
START "%ProgramFiles%\Internet Explorer\iexplore.exe" http://sourceforge.net/projects/yajsw
ECHO.
CALL :waitseconds 10
GOTO :END
)
IF NOT EXIST run.bat (
ECHO This file must be run from the JBoss bin directory
GOTO :END
)
IF NOT DEFINED JAVA_HOME (
ECHO JAVA_HOME must be defined as an environment variable.
GOTO :END
) 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 :END
)
IF "%INSTANCE%"=="" (
ECHO Instance name must be defined in this script file.
ECHO The named instance in directory: %JBOSS_HOME%\server\ .
GOTO :END
)
IF NOT EXIST wrapper\wrapperApp.jar (
ECHO You need to copy the wrapperApp.jar into place at bin\wrapper\wrapperApp.jar
GOTO :END
)
IF NOT EXIST wrapper\wrapper.jar (
ECHO You need to copy the wrapperApp.jar into place at bin\wrapper\wrapper.jar
GOTO :END
)
IF EXIST wrapper\YAJSW.sample.wrapper.conf (
IF NOT EXIST wrapper\%INSTANCE%.wrapper.conf (
COPY wrapper\YAJSW.sample.wrapper.conf wrapper\%INSTANCE%.wrapper.conf
)
) ELSE (
ECHO Missing file YAJSW.sample.wrapper.conf from .\wrapper directory in %JBOSS_HOME%\bin .
GOTO :END
)
::-------------------------------------------------------------------
:: Detect windows shell architecture
::-------------------------------------------------------------------
SET ProgramFiles(x86) | FIND "not defined"
IF %ERRORLEVEL%==1 (
:: if defined then 64
SET CMD_ARCH=64
) ELSE (
:: if not defined then 32
SET CMD_ARCH=32
)
ECHO Command shell architecture is %CMD_ARCH%
::-------------------------------------------------------------------
:: Set memory levels for environment
::-------------------------------------------------------------------
ECHO Checking that JDK bit architecture matches cmd.exe bit architecture...
for /f "tokens=3" %%g in ('%JAVA_HOME%\bin\java.exe -version 2^>^&1 ^| findstr /i "64-bit"') do (
set JARCH64=%%g
)
for /f "tokens=3" %%g in ('%JAVA_HOME%\bin\java.exe -version 2^>^&1 ^| findstr /i "Client"') do (
set JARCH32=%%g
)
IF NOT "%JARCH64%"=="" (
SET JAVA_ARCH=64
)
IF NOT "%JARCH32%"=="" (
SET JAVA_ARCH=32
)
ECHO Java architecture is %JAVA_ARCH%-bit.
SET MS=512M
IF "%JAVA_ARCH%"=="64" (
IF "%CMD_ARCH%"=="64" (
ECHO A 64bit java in a 64bit shell.
SET MM=2048M
SET MPS=256M
ECHO Max memory set to !MM! ^(with !MPS! permsize^) in %JAVA_ARCH%-bit JVM in a %CMD_ARCH%-bit shell.
) ELSE (
ECHO A 64-bit JVM cannot run in a 32-bit shell.
)
) ELSE (
IF "%CMD_ARCH%"=="64" (
ECHO A 32bit java in a 64bit shell.
SET MM=1402M
SET MPS=256M
ECHO Max memory set to !MM! ^(with !MPS! permsize^) in %JAVA_ARCH%-bit JVM in a %CMD_ARCH%-bit shell.
) ELSE (
ECHO A 32bit java in a 32bit shell.
SET MM=1302M
SET MPS=256M
ECHO Max memory set to !MM! ^(with !MPS! permsize^) in %JAVA_ARCH%-bit JVM in a %CMD_ARCH%-bit shell.
)
)
IF NOT EXIST wrapper\tmp (
MKDIR wrapper\tmp
)
IF NOT EXIST "%JBOSS_HOME%\server\%INSTANCE%" (
::RD.exe /S /Q "%JBOSS_HOME%\server\default\tmp"
DEL /S "%JBOSS_HOME%\server\default\data"
DEL /S "%JBOSS_HOME%\server\default\log"
DEL /S "%JBOSS_HOME%\server\default\tmp"
DEL /S "%JBOSS_HOME%\server\default\work"
XCOPY.exe "%JBOSS_HOME%\server\default" "%JBOSS_HOME%\server\%INSTANCE%" /Y /E /F /I
)
IF NOT EXIST "%JBOSS_HOME%\server\ports-bindings.xml" (
COPY /Y "%JBOSS_HOME%\server\%INSTANCE%\conf\bindingservice.beans\META-INF\bindings-jboss-beans.xml" "%JBOSS_HOME%\server\"
)
ECHO.
EXIT /B 0
:consoleservice
ECHO Function: consoleservice
ECHO Run wrapper in console for service ^"%SERVICE_NAME%^"
ECHO ***********************
ECHO Using wrapper to run in console : service-name=%SERVICE_NAME%, startup-type=%TYPE%
ECHO Running service in console...
ECHO "%JAVA_HOME%\bin\java.exe" %WRAPPER_ARGS% -jar %JBOSS_HOME%\bin\wrapper\wrapper.jar -c %WRAPPER_CONFIG_FILE%
CALL "%JAVA_HOME%\bin\java.exe" %WRAPPER_ARGS% -jar %JBOSS_HOME%\bin\wrapper\wrapper.jar -c %WRAPPER_CONFIG_FILE%
ECHO.
ECHO ***********************
EXIT /B 0
:displayports
ECHO Active JBoss ports
EXIT /B 0
:jbossver
FINDSTR.exe /R "JBoss_5" "%JBOSS_HOME%\jar-versions.xml">nul
IF %ERRORLEVEL%==0 SET VER=5
FINDSTR.exe /R "JBoss_6" "%JBOSS_HOME%\jar-versions.xml">nul
IF %ERRORLEVEL%==0 SET VER=6
EXIT /B 0
:mainheader
TITLE %TITLE_TEXT%
ECHO ------------------------------------
EXIT /B 0
:queryservice
ECHO Function: queryservice
ECHO Run wrapper to query ^"%SERVICE_NAME%^"
ECHO ***********************
ECHO "%JAVA_HOME%\bin\java.exe" %WRAPPER_ARGS% -jar %JBOSS_HOME%\bin\wrapper\wrapper.jar -q %WRAPPER_CONFIG_FILE%
CALL "%JAVA_HOME%\bin\java.exe" %WRAPPER_ARGS% -jar %JBOSS_HOME%\bin\wrapper\wrapper.jar -q %WRAPPER_CONFIG_FILE%
ECHO.
ECHO ***********************
EXIT /B 0
:servicestatus
ECHO Checking status of service...
CALL :waitseconds 2
sc.exe query %SERVICE_NAME% | find "STATE">query.tmp
ECHO.
FOR /F "tokens=1,4 delims=, " %%I IN ( query.tmp ) DO (
ECHO Status of ^"%SERVICE_NAME%^" : %%I - %%J
IF "%%J"=="START_PENDING" (
ECHO Service is pending a start.
SET "PENDING=true"
SET "RUNNING=unknown"
) ELSE IF "%%J"=="STOP_PENDING" (
ECHO Service is pending a stop.
SET "PENDING=true"
SET "RUNNING=unknown"
) ELSE IF "%%J"=="STOPPED" (
ECHO Service is stopped.
SET "PENDING=false"
SET "RUNNING=false"
) ELSE IF "%%J"=="RUNNING" (
ECHO Service is running.
SET "PENDING=false"
SET "RUNNING=true"
)
)
DEL /Q query.tmp
IF "%PENDING%"=="true" GOTO :servicestatus
EXIT /B 0
:settitle
SET TITLETEXT=JBoss ^"!SERVICE_NAME!^" Service Controller
TITLE %TITLETEXT%
EXIT /B 0
:startheader
:: Generated by: http://patorjk.com/software/taag/#p=display&f=Star%20Wars&t=JBoss
ECHO __ .______ ______ _______. _______.
ECHO ^| ^| ^| _ \ / __ \ / ^| / ^|
ECHO ^| ^| ^| ^|_) ^| ^| ^| ^| ^| ^| (----` ^| (----`
ECHO .--. ^| ^| ^| _ ^< ^| ^| ^| ^| \ \ \ \
ECHO ^| `--' ^| ^| ^|_) ^| ^| `--' ^| .----) ^| .----) ^|
ECHO \______/ ^|______/ \______/ ^|_______/ ^|_______/
ECHO.
ECHO.
ECHO Script environment:
ECHO JAVA_HOME=%JAVA_HOME%
ECHO JBOSS_HOME=%JBOSS_HOME%
ECHO WRAPPER_ARGS=%WRAPPER_ARGS%
ECHO SERVICE_NAME=%SERVICE_NAME%
ECHO ACTION=%ACTION%
ECHO WRAPPER_CONFIG_FILE: %WRAPPER_CONFIG_FILE%
ECHO ^(STARTUP^) TYPE=%TYPE%
ECHO.
ECHO.
EXIT /B 0
:usage
ECHO.
ECHO -----------------------------
ECHO Usage:
ECHO -----------------------------
ECHO MENU will not be displayed if any arg is passed : &ECHO.
ECHO %~n0%~x0 start JBOSS_%INSTANCE%
ECHO %~n0%~x0 stop
ECHO %~n0%~x0 add JBOSS_%INSTANCE%
ECHO %~n0%~x0 add
ECHO %~n0%~x0 console JBOSS_%INSTANCE%
ECHO %~n0%~x0 query JBOSS_%INSTANCE%
ECHO.
ECHO -----------------------------
ECHO.
EXIT /B 0
:verifytype
SET FAIL=true
IF "%TYPE%"=="boot" SET FAIL=false
IF "%TYPE%"=="system" SET FAIL=false
IF "%TYPE%"=="auto" SET FAIL=false
IF "%TYPE%"=="demand" SET FAIL=false
IF "%TYPE%"=="disabled" SET FAIL=false
IF "%TYPE%"=="delayed-auto" SET FAIL=false
IF "%FAIL%"=="true" (
SET TYPE=
ECHO Invalid TYPE option. Try again.
ECHO.
GOTO :SETTYPE
)
ECHO Startup TYPE is: %TYPE%
EXIT /B 0
:waitseconds timeArg
SET /A VAL=%1
ECHO Pausing for %VAL% seconds.
SET /A DUR=%VAL%*2
PING.exe -n %DUR% -w 1 127.0.0.1>nul
EXIT /B 0
:wrappersetup
SET SERVICE_NAME=JBOSS_%INSTANCE%
SET "WRAPPER_CONFIG_FILE=%JBOSS_HOME%\bin\wrapper\%INSTANCE%.wrapper.conf"
CALL :jbossver
IF "%VER%"=="6" (
SET "WRAPPER_ARGS=-Ddarg1=-Djboss.platform.mbeanserver -Ddarg2=-Djavax.management.builder.initial=org.jboss.system.server.jmx.MBeanServerBuilderImpl"
) ELSE (
SET "WRAPPER_ARGS=-Ddarg1=-Djboss6placeholder1 -Ddarg2=-Djboss6placeholder2"
)
SET "WRAPPER_ARGS=%WRAPPER_ARGS% -Djboss.home="%JBOSS_HOME%" -Dservice.name=%SERVICE_NAME% -Ddebug.level=%DEBUGLEVEL% -Dinstance=%INSTANCE%"
SET "WRAPPER_ARGS=%WRAPPER_ARGS% -Djava.home="%JAVA_HOME%" -Djboss.ms=%MS% -Djboss.mm=%MM% -Djboss.perm=%MPS%"
:: Change back-slashes to forward-slashes before passing options to the wrapper
SET "WRAPPER_ARGS=%WRAPPER_ARGS:\=/%"
EXIT /B 0
::-------------------------------------------------------------------
:: End script
::-------------------------------------------------------------------
:END
ECHO.
ECHO Service script is finished and will close automatically in %DELAY% seconds.
FOR /l %%a IN (%DELAY%,-1,1) DO (TITLE JBoss %APPDIR% -- Closing in %%as&PING.exe -n 2 -w 1 127.0.0.1>nul)
## wrapper.conf
## parsed args from script
wrapper.java.home=${java.home}
wrapper.app.home=${jboss.home}
wrapper.debug.level=${debug.level}
wrapper.app.instance=${instance}
wrapper.app.servicename=${service.name}
wrapper.minheap=${jboss.ms}
wrapper.maxheap=${jboss.mm}
wrapper.permsize=${jboss.perm}
## wrapper configuration
wrapper.java.command=${wrapper.java.home}\\bin\\java.exe
wrapper.java.command.maxVersion=1.6.0
wrapper.java.command.minVersion=1.5.0_14
wrapper.ntservice.java.command=${wrapper.java.command}
wrapper.java.command.preferJdk=true
wrapper.console.loglevel=${wrapper.debug.level}
wrapper.debug=true
wrapper.tray=true
## custom proc name may be problematic with wrapper.tray
#wrapper.java.customProcName=jboss-${wrapper.app.instance}
# enviroment variable JAVA_OPTS
wrapper.java.additional.1=-Dprogram.name=run.bat
wrapper.java.additional.2=-Xms${wrapper.minheap}
wrapper.java.additional.3=-Xmx${wrapper.maxheap}
wrapper.java.additional.4=-XX:MaxPermSize=${wrapper.permsize}
wrapper.java.additional.5=-Dsun.rmi.dgc.client.gcInterval=3600000
wrapper.java.additional.6=-Dsun.rmi.dgc.server.gcInterval=3600000
wrapper.java.additional.7=-Dorg.jboss.resolver.warning=true
wrapper.java.additional.8=-Djava.endorsed.dirs=${wrapper.app.home}/lib/endorsed
wrapper.java.additional.9=-Dsun.lang.ClassLoader.allowArraySyntax=true
#wrapper.java.additional.10=-Dcom.sun.management.jmxremote.port=9999
#wrapper.java.additional.11=-Dcom.sun.management.jmxremote.authenticate=false
#wrapper.java.additional.12=-Dcom.sun.management.jmxremote.ssl=false
wrapper.java.additional.13=-Dsession.serialization.jboss=true
wrapper.java.additional.14=-Djboss.service.binding.set=${wrapper.app.instance}
wrapper.java.additional.15=${darg1}
wrapper.java.additional.16=${darg2}
# wrapper.java.additional.17=-Djava.awt.headless=true
# wrapper.java.additional.18=-Xrunjdwp:transport=dt_shmem,address=jboss,server=y,suspend=n
# wrapper.java.additional.19=-Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n
# Classpath
wrapper.java.classpath.1=${wrapper.app.home}\\bin\\run.jar
# Parameters to be passed to the application
wrapper.java.app.mainclass=org.jboss.Main
wrapper.app.parameter.1=org.jboss.Main
wrapper.app.parameter.2=-c
wrapper.app.parameter.3=${wrapper.app.instance}
wrapper.app.parameter.4=-b
wrapper.app.parameter.5=0.0.0.0
# wrapper JMX (separate from app JMX, which is enabled with -D args)
wrapper.jmx=true
wrapper.jmx.rmi.port=9998
# heap control
# wrapper.java.monitor.heap = true
# wrapper.filter.trigger.heap.tray = wrapper.java.monitor.heap: HEAP SIZE
# wrapper.filter.script.heap.tray = scripts/trayMessage.gv
# wrapper.filter.script.heap.tray.args = Heap Issue Detected
#wrapper.java.monitor.heap.restart = true
#wrapper.java.monitor.heap.threshold.percent=99
#wrapper.ntservice.failure_actions.actions = RESTART
#wrapper.ntservice.failure_actions.actions_delay=60000
# wrapper log location
wrapper.logfile=${wrapper.app.home}/bin/wrapper/log/${wrapper.app.servicename}.log
wrapper.console.title=JBOSS Service YAJSW Console
wrapper.ntservice.name=${wrapper.app.servicename}
wrapper.ntservice.displayname=${wrapper.app.servicename}
wrapper.ntservice.description=JBoss at ${wrapper.app.home}/server/${wrapper.app.instance}/
wrapper.ntservice.autoreport.startup=true
#wrapper.app.account=
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.