Run JBoss as Service HowTo
A short tutorial for JBoss administrator which illustrates how to
start JBoss AS as Service both in Windows environment and in
Unix-Linux environment.
WINDOWS
users - JBOSS AS 7
The latest release of the application server requires the
following steps to be installed as a service:
Download the JBoss Web native connectors which
contain the jbosssvc.exe and service.bat. These files are necessary to start
JBoss AS 7 as service for Windows users.
You can download the latest stable release for your platform at:
http://www.jboss.org/jbossweb/downloads.html
You can download the latest stable release for your platform at:
http://www.jboss.org/jbossweb/downloads.html
Then unzip the file into your JBoss AS distribution directory.
Adapting service.bat
Now the
little hack: as a matter of fact the service.bat file
is based on the JBoss AS 5 platform. The most notable difference is that JBoss
AS 7 uses standalone.bat instead of run.bat (although a run.bat file has been
added for comtability reason).
So replace the service.bat with the following (just adapt your JBOSS_HOME variable to your environment):
So replace the service.bat with the following (just adapt your JBOSS_HOME variable to your environment):
@echo off
REM JBoss, the OpenSource webOS
REM
REM Distributable under LGPL license.
REM See terms of license at gnu.org.
REM
REM -------------------------------------------------------------------------
REM JBoss Service Script for Windows
REM -------------------------------------------------------------------------
@if not "%ECHO%" == "" echo %ECHO%
@if "%OS%" == "Windows_NT" setlocal
set DIRNAME=%CD%
REM
REM VERSION, VERSION_MAJOR and VERSION_MINOR are populated
REM during the build with ant filter.
REM
set SVCNAME=JBAS711SVC
set SVCDISP=JBoss Application Server 7.1.1
set SVCDESC=JBoss Application Server 7.1.1 GA/Platform: Windows x86
set NOPAUSE=Y
REM Suppress killing service on logoff event
set JAVA_OPTS=-Xrs
SET JBOSS_HOME=C:\jboss-as-7.1.1.Final
REM Figure out the running mode
if /I "%1" == "install" goto cmdInstall
if /I "%1" == "uninstall" goto cmdUninstall
if /I "%1" == "start" goto cmdStart
if /I "%1" == "stop" goto cmdStop
if /I "%1" == "restart" goto cmdRestart
if /I "%1" == "signal" goto cmdSignal
echo Usage: service install^|uninstall^|start^|stop^|restart^|signal
goto cmdEnd
REM jbosssvc retun values
REM ERR_RET_USAGE 1
REM ERR_RET_VERSION 2
REM ERR_RET_INSTALL 3
REM ERR_RET_REMOVE 4
REM ERR_RET_PARAMS 5
REM 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%
goto cmdEnd
:cmdInstall
jbosssvc.exe -imwdc %SVCNAME% "%DIRNAME%" "%SVCDISP%" "%SVCDESC%" service.bat
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
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%" > %JBOSS_HOME%\standalone\log\standalone.log
call standalone.bat --server-config=standalone.xml < .r.lock >> %JBOSS_HOME%\standalone\log\standalone.log 2>&1
jbosssvc.exe -p 1 "Shutdown %SVCDISP% service" >> %JBOSS_HOME%\standalone\log\standalone.log
del .r.lock
goto cmdEnd
:cmdStop
REM Executed on service stop
echo Y > .s.lock
jbosssvc.exe -p 1 "Shutting down %SVCDISP%" > %JBOSS_HOME%\standalone\log\shutdown.log
call jboss-cli.bat --connect command=:shutdown >> %JBOSS_HOME%\standalone\log\shutdown.log 2>&1
jbosssvc.exe -p 1 "Shutdown %SVCDISP% service" >> %JBOSS_HOME%\standalone\log\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%" >> %JBOSS_HOME%\standalone\log\shutdown.log
call jboss-cli.bat --connect command=:shutdown >> %JBOSS_HOME%\standalone\log\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%" >> %JBOSS_HOME%\standalone\log\standalone.log
call standalone.bat --server-config=standalone.xml < .r.lock >> %JBOSS_HOME%\standalone\log\standalone.log 2>&1
jbosssvc.exe -p 1 "Shutdown %SVCDISP% service" >> %JBOSS_HOME%\standalone\log\standalone.log
del .r.lock
goto cmdEnd
:cmdSignal
REM Send signal to the service.
REM Requires jbosssch.dll to be loaded in JVM
@if not ""%2"" == """" goto execSignal
echo Missing signal parameter.
echo Usage: service signal [0...9]
goto cmdEnd
:execSignal
jbosssvc.exe -k%2 %SVCNAME%
goto cmdEnd
:cmdEnd
REM JBoss, the OpenSource webOS
REM
REM Distributable under LGPL license.
REM See terms of license at gnu.org.
REM
REM -------------------------------------------------------------------------
REM JBoss Service Script for Windows
REM -------------------------------------------------------------------------
@if not "%ECHO%" == "" echo %ECHO%
@if "%OS%" == "Windows_NT" setlocal
set DIRNAME=%CD%
REM
REM VERSION, VERSION_MAJOR and VERSION_MINOR are populated
REM during the build with ant filter.
REM
set SVCNAME=JBAS711SVC
set SVCDISP=JBoss Application Server 7.1.1
set SVCDESC=JBoss Application Server 7.1.1 GA/Platform: Windows x86
set NOPAUSE=Y
REM Suppress killing service on logoff event
set JAVA_OPTS=-Xrs
SET JBOSS_HOME=C:\jboss-as-7.1.1.Final
REM Figure out the running mode
if /I "%1" == "install" goto cmdInstall
if /I "%1" == "uninstall" goto cmdUninstall
if /I "%1" == "start" goto cmdStart
if /I "%1" == "stop" goto cmdStop
if /I "%1" == "restart" goto cmdRestart
if /I "%1" == "signal" goto cmdSignal
echo Usage: service install^|uninstall^|start^|stop^|restart^|signal
goto cmdEnd
REM jbosssvc retun values
REM ERR_RET_USAGE 1
REM ERR_RET_VERSION 2
REM ERR_RET_INSTALL 3
REM ERR_RET_REMOVE 4
REM ERR_RET_PARAMS 5
REM 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%
goto cmdEnd
:cmdInstall
jbosssvc.exe -imwdc %SVCNAME% "%DIRNAME%" "%SVCDISP%" "%SVCDESC%" service.bat
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
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%" > %JBOSS_HOME%\standalone\log\standalone.log
call standalone.bat --server-config=standalone.xml < .r.lock >> %JBOSS_HOME%\standalone\log\standalone.log 2>&1
jbosssvc.exe -p 1 "Shutdown %SVCDISP% service" >> %JBOSS_HOME%\standalone\log\standalone.log
del .r.lock
goto cmdEnd
:cmdStop
REM Executed on service stop
echo Y > .s.lock
jbosssvc.exe -p 1 "Shutting down %SVCDISP%" > %JBOSS_HOME%\standalone\log\shutdown.log
call jboss-cli.bat --connect command=:shutdown >> %JBOSS_HOME%\standalone\log\shutdown.log 2>&1
jbosssvc.exe -p 1 "Shutdown %SVCDISP% service" >> %JBOSS_HOME%\standalone\log\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%" >> %JBOSS_HOME%\standalone\log\shutdown.log
call jboss-cli.bat --connect command=:shutdown >> %JBOSS_HOME%\standalone\log\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%" >> %JBOSS_HOME%\standalone\log\standalone.log
call standalone.bat --server-config=standalone.xml < .r.lock >> %JBOSS_HOME%\standalone\log\standalone.log 2>&1
jbosssvc.exe -p 1 "Shutdown %SVCDISP% service" >> %JBOSS_HOME%\standalone\log\standalone.log
del .r.lock
goto cmdEnd
:cmdSignal
REM Send signal to the service.
REM Requires jbosssch.dll to be loaded in JVM
@if not ""%2"" == """" goto execSignal
echo Missing signal parameter.
echo Usage: service signal [0...9]
goto cmdEnd
:execSignal
jbosssvc.exe -k%2 %SVCNAME%
goto cmdEnd
:cmdEnd
Now from the DOS prompt run:
C:\jboss-as-7.1.1.Final\bin>service.bat
install
Installed JBAS711SVC
Service JBoss Application Server 7.1.1 installed
Installed JBAS711SVC
Service JBoss Application Server 7.1.1 installed
This will install JBoss AS 7 in the list of Services.
WINDOWS
users - JBOSS AS 4-5-6
Earlier releases of JBoss ship out of the box with the service.bat shell command which is located into
the JBOSS_HOME/bin folder. The service.bat commands needs at least one
parameter to run:
C:\jboss-5.0.0.GA\bin>service
Usage: service install|uninstall|start|stop|restart|signal
Usage: service install|uninstall|start|stop|restart|signal
In order
to install JBoss AS as Windows service launch:
C:\jboss-5.0.0.GA\bin>service install
Now JBoss AS should me enlisted in the Windows Service List, which
can be found in the control panel.
Now you can use both the Windows service applet or the service.bat
command to start the service. Example:
Starting
JBoss AS service:
C:\jboss-5.0.0.GA\bin>service start
Linux
users - JBOSS AS 7
Linux applications
use System V Init scripts to run an application when the
machine boots.
Basically, the scripts which start a service are placed in:
/etc/rc.d/init.d/ (other distributions: /etc/init.d/)
The same scripts need to be linked as:
/etc/rc.(x)/ (Prefixed with S for start and K for stop)
We suggest you reading a good tutorial about Linux Init scripts if you are new to this:
http://www.linux.com/news/enterprise/systems-management/8116-an-introduction-to-services-runlevels-and-rcd-scripts
Basically, the scripts which start a service are placed in:
/etc/rc.d/init.d/ (other distributions: /etc/init.d/)
The same scripts need to be linked as:
/etc/rc.(x)/ (Prefixed with S for start and K for stop)
We suggest you reading a good tutorial about Linux Init scripts if you are new to this:
http://www.linux.com/news/enterprise/systems-management/8116-an-introduction-to-services-runlevels-and-rcd-scripts
In order to install JBoss AS 7 on your Linux distribution pickup
the file jboss-as-standalone.sh located inJBOSS_HOME/bin/init.d. This file needs to be placed in
init.d to launch jboss as a service.
cp jboss_as-standalone.sh /etc/rc.d/init.d/jboss
Remember to edit the file jboss-as-standalone.sh to
adapt it to your environment:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
....
# Load JBoss AS init.d configuration.
if [
-z "$JBOSS_CONF" ]; then
JBOSS_CONF="/etc/jboss-as/jboss-as.conf"
fi
[ -r "$JBOSS_CONF"
] && . "${JBOSS_CONF}"
# Set defaults.
if [
-z "$JBOSS_HOME" ]; then
JBOSS_HOME=/usr/share/jboss-as
fi
export JBOSS_HOME
....
|
Now you should create a link for each System level so that
Linux/Unix knows at which level the application server needs to be started:
ln -s
/etc/rc.d/init.d/jboss /etc/rc3.d/S84jboss
ln -s /etc/rc.d/init.d/jboss /etc/rc5.d/S84jboss
ln -s /etc/rc.d/init.d/jboss /etc/rc4.d/S84jboss
ln -s /etc/rc.d/init.d/jboss /etc/rc6.d/K15jboss
ln -s /etc/rc.d/init.d/jboss /etc/rc0.d/K15jboss
ln -s /etc/rc.d/init.d/jboss /etc/rc1.d/K15jboss
ln -s /etc/rc.d/init.d/jboss /etc/rc2.d/K15jboss
ln -s /etc/rc.d/init.d/jboss /etc/rc5.d/S84jboss
ln -s /etc/rc.d/init.d/jboss /etc/rc4.d/S84jboss
ln -s /etc/rc.d/init.d/jboss /etc/rc6.d/K15jboss
ln -s /etc/rc.d/init.d/jboss /etc/rc0.d/K15jboss
ln -s /etc/rc.d/init.d/jboss /etc/rc1.d/K15jboss
ln -s /etc/rc.d/init.d/jboss /etc/rc2.d/K15jboss
We don't go deep into the details of Linux startup system but the
links targeted as "S" are launched to start the service at a certain
system level. The scripts marked with "K" are launched when the
server is shuitting down.JBoss AS distribution includes a few shell commands
which are located in the JBOSS_HOME/bin folder.
Linux
users - JBOSS AS 4-5-6
The main difference with the AS 7 distribution is that you have a
set of different shell command for each operating system:
jboss_init_hpux.sh
jboss_init_redhat.sh
jboss_init_suse.sh
jboss_init_hpux.sh
jboss_init_redhat.sh
jboss_init_suse.sh
Copy the
appropriate file for your distribution into the /etc/rc.d/init.d folder
cp jboss_init_redhat.sh /etc/rc.d/init.d/jboss
The rest of the procedure stays the same as for AS 7.
Reference: https://community.jboss.org/wiki/RunningJBossAS7AsAWindowsService