Revision: 61449
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at December 14, 2012 05:08 by djangofan
Initial Code
@ECHO off SETLOCAL ENABLEDELAYEDEXPANSION CLS :: place this next to the run.bat in your JBoss distro and run it IF EXIST C:\Users ( ECHO Current User is '%USERNAME%' ECHO INFO: You may need to run this script as 'Administrator' user. ) ::------------------------------------------------------------------- :: Set TITLE, JBOSS_HOME, and DIRNAME variables ::------------------------------------------------------------------- SET JBOSS_HOME=%~dp0 FOR /F "delims=\" %%a IN ("%JBOSS_HOME%") DO SET "DIRNAME=%%~nxa" SET "APPDIR=%DIRNAME%" SET "JBOSS_HOME=%JBOSS_HOME:bin\=%" IF %JBOSS_HOME:~-1%==\ SET "JBOSS_HOME=%JBOSS_HOME:~0,-1%" ::------------------------------------------------------------------- :: Handle script args ::------------------------------------------------------------------- SET PICK=%~1 SET SERVICENAME=%~2 IF "%SERVICENAME%"=="" SET SERVICENAME=JBOSS SET TITLETEXT=%SERVICENAME% Service Controller TITLE %TITLETEXT% ::------------------------------------------------------------------- :: Parse first script argument for service action :: If no args are passed then prompt user ::------------------------------------------------------------------- :MAKECHOICE ECHO.&ECHO.&ECHO. IF "%PICK%"=="" ( ECHO ----------------------------- ECHO Options menu: ECHO ----------------------------- ECHO [auto] Install and start service 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 [status] Query service status ECHO. ) ELSE ( ECHO Running silently since script has arguments. ) IF "%PICK%"=="" SET /P "PICK=Please enter a service action you want to perform [2]: " IF EXIST servicename.txt SET /P SERVICENAME=<servicename.txt IF "%PICK%"=="" ( ECHO Empty answer. Try Again. pause GOTO :MAKECHOICE ) IF "%PICK%"=="auto" ( IF "%SERVICENAME%"=="" ( ECHO Choice fails without a second script argument passing service name. GOTO :END ) ECHO %SERVICENAME%>>servicename.txt SET ACTION=Starting SET OPTION=-t GOTO :ACTIONSET ) IF "%PICK%"=="install" ( IF "%SERVICENAME%"=="" ( ECHO Choice fails without a second script argument passing service name. GOTO :END ) ECHO %SERVICENAME%>>servicename.txt SET ACTION=Installing SET OPTION=-i GOTO :ACTIONSET ) IF "%PICK%"=="start" ( SET ACTION=Starting SET OPTION=-t GOTO :ACTIONSET ) IF "%PICK%"=="stop" ( SET ACTION=Stopping SET OPTION=-p GOTO :ACTIONSET ) IF "%PICK%"=="remove" ( SET ACTION=Uninstalling SET OPTION=-r GOTO :ACTIONSET ) IF "%PICK%"=="console" ( SET ACTION=Console SET OPTION=-c GOTO :ACTIONSET ) IF "%PICK%"=="status" ( SET ACTION=Querying SET OPTION=-q GOTO :ACTIONSET ) IF "%PICK%"=="X" GOTO :EOF IF "%PICK%"=="x" GOTO :EOF :ACTIONSET SET "WRAPPER_CONFIG_FILE=%JBOSS_HOME%\%APPDIR%\wrapper\wrapper.jboss.conf" ::------------------------------------------------------------------- :: Set java options for wrapper :: Change back-slashes to forward-slashes before passing options to the wrapper ::------------------------------------------------------------------- SET "WRAPPER_ARGS=-Djboss.home=%JBOSS_HOME% -Djboss.dir=%APPDIR% -Dservice.name=%SERVICENAME%" SET WRAPPER_ARGS=%WRAPPER_ARGS:\=/% ::------------------------------------------------------------------- :: Info output ::------------------------------------------------------------------- ECHO. ECHO -- These variables are set by this script and passed to the service installation: ECHO JAVA_HOME=%JAVA_HOME% ECHO JBOSS_HOME=%JBOSS_HOME% ECHO APPDIR=%APPDIR% ECHO WRAPPER_CONFIG_FILE: %WRAPPER_CONFIG_FILE% ECHO WRAPPER_ARGS=%WRAPPER_ARGS% ECHO SERVICENAME=%SERVICENAME% ECHO ACTION=%ACTION% ECHO OPTION=%OPTION% ECHO. ::ECHO -- Before you install this service make sure that you properly configured the ::ECHO property called "wrapper.ntservice.account" in the wrapper config file. ::ECHO (It will default to running as the "Local System" user.) ECHO. ::------------------------------------------------------------------- :: Install service ::------------------------------------------------------------------- ECHO. IF "%PICK%"=="remove" ( DEL /Q servicename.txt ) IF "%PICK%"=="auto" ( :: when auto, perform 1 additional action ECHO. ECHO Registering service ... ECHO "%JAVA_HOME%\bin\java.exe" %WRAPPER_ARGS% -jar %JBOSS_HOME%\%APPDIR%\wrapper\wrapper.jar -i %WRAPPER_CONFIG_FILE% CALL "%JAVA_HOME%\bin\java.exe" %WRAPPER_ARGS% -jar %JBOSS_HOME%\%APPDIR%\wrapper\wrapper.jar -i %WRAPPER_CONFIG_FILE% CALL :WAIT ) ECHO. ECHO %ACTION% service ... ECHO "%JAVA_HOME%\bin\java.exe" %WRAPPER_ARGS% -jar %JBOSS_HOME%\%APPDIR%\wrapper\wrapper.jar %OPTION% %WRAPPER_CONFIG_FILE% CALL "%JAVA_HOME%\bin\java.exe" %WRAPPER_ARGS% -jar %JBOSS_HOME%\%APPDIR%\wrapper\wrapper.jar %OPTION% %WRAPPER_CONFIG_FILE% ECHO. ECHO. ECHO %ACTION% service ^"%SERVICENAME%^" is finished. ::------------------------------------------------------------------- :: Functions ::------------------------------------------------------------------- :GET_DIR SET "_TMPDIR=%~dp1" SET "_TMPDIR=%_TMPDIR:~0,-1%" EXIT /B 0 :WAIT PING.exe -n 6 -w 1 127.0.0.1>nul EXIT /B 0 ::------------------------------------------------------------------- :: End script ::------------------------------------------------------------------- :END 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)
Initial URL
https://gist.github.com/4271240
Initial Description
A DOS batch script to handle registering and controlling a JBoss service.
Initial Title
JBoss 5 YAJSW service wrapper script
Initial Tags
service
Initial Language
DOS Batch