Thursday, January 8, 2009

Running JBoss as a Windows Service


What you need to know to run a JBoss server instance as a Windows Service.

Until recently it was done by using JavaService.exe or tanuki wrapper. Both involved quite a bit of configurations compared to what's available directly from JBoss.

Please note that this features is available in JBoss 5 by default. No need to download the files from jboss-native.

This solution will work with JBoss 4 too. I have tested it on JBoss 4.0.3, JBoss 4.2.3 and JBoss 5.0.0.

Some information is available at http://jboss.org/community/docs/DOC-10679


You will find links for different windows versions, select the appropriate one.

The downloaded file will be in .zip format, unzip it somewhere.

Copy jbosssvc.exe, service.bat and README-service.txt to your JBOSS_HOME/bin folder.

The file README-service.txt contains instructions on configurations changes.

Unfortunately the above file doesn't explain the part about service name related configuration

By default the service.bat contains settings entered for JBoss 5.

set SVCNAME=JBAS50SVC
set SVCDISP=JBoss Application Server 5.0
set SVCDESC=JBoss Application Server 5.0.0 GA/Platform: Windows x86

You may want to change it you describe your environment. If you are running multiple JBoss instances in machine, make sure you are using different values for SVNNAME in each instance.

Let's say you are using it with JBoss 4.0.3:

set SVCNAME=JBAS403SVC
set SVCDISP=JBoss Application Server 4.0.3
set SVCDESC=JBoss Application Server 4.0.3 GA/Platform: Windows x86

Next part to look at is where run.bat and shutdown.bat is referred. You may want to modify there if you want to pass arguments these batch files.

e.g.

jbosssvc.exe -p 1 "Starting %SVCDISP%" > run.log
call run.bat -c all -b 127.0.0.1 < .r.lock >> run.log 2>&1
jbosssvc.exe -p 1 "Shutdown %SVCDISP% service" >> run.log

run.log file is where console output is written to. 

jbosssvc.exe -p 1 "Shutting down %SVCDISP%" > shutdown.log
call shutdown -S --server=myserver:2099 < .s.lock >> shutdown.log 2>&1
jbosssvc.exe -p 1 "Shutdown %SVCDISP% service" >> shutdown.log

shutdown.log contains console outputs after service is stopped

To create/register the JBoss service with the windows service manager (This needs to be done only once)

JBOSS_HOME/bin> service.bat install.

Now the service will be available in the windows services manager. It can be modified and operated just like any other service.

If you ever want to remove the JBoss service from Windows, use the following command:

JBOSS_HOME/bin> service.bat uninstall.

That's all....

BTW, why JBoss is run as a Windows Service?
  • Automatically starts the process on system startup, and closes it on shutdown (when automatic) 
  • It launches the application as Windows service at system boot, before user logon and runs it without the need of a user session. 
  • Standard windows service monitoring mechanism can be utilized to check the application availability 
  • The application can be started using 'service account' without having to login as that user.