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.

48 comments:

BorntoCode said...

Hi,
Just wanted to know if you any idea on how to make this run.log file a role over append log file.

thanks,
Adnan

Vijesh Aaniyamveetil said...

As run.log file is created to redirect the output to console, there is no direct support from JBoss for file rotation. You have to run some cron job to do this.

But ideally your run.log file shouldn't contain JBoss server logging output in it. The server log output will gets written in the server.log (or whatever the name u've given) file of JBoss, right?

Just comment appender-ref ref="CONSOLE" in the log4j file. So run.log file will not contain same output as in server.log file hence will be smaller in size and the file rotation/roll over is not necessary

Shyam said...

is there a way to run multiple instances of jboss service ??/

consider i have two configurations under the server folder..can i start two services each pointing to the configuration using -c command ???

or do i need to have two separate jboss server ??

Vijesh Aaniyamveetil said...

Yes, you can.
either
create a separate service.bat file for each jboss instance and add the -c switch next to the call run ...

call run.bat -c node1 -b 127.0.0.1 < .r.lock >> run.log 2>&1

Or

you can pass the configuration name as a switch to service.bat and use the variable against the -c switch

call run.bat -c $1 -b 127.0.0.1 < .r.lock >> run.log 2>&1

pramod said...

For running multiple instance I tried to create another copy of service.bat and entered the parameters in the call routine and successfully installed the service. But when I try to ctart the service I get a WIndows Service error --> "Some services stop automatically if they have no work to do, for example the Performance Log"
I tried to create another .log and .lock files and it did not help. Advise please...

pramod said...

To add to my earlier blog --> Althoug the service does not start when I try service2.bat start the server starts successfully(using run2.lo and .r2.lock). Any idea why it fails from Windows service?

pramod said...

I was using the wrong bat file. My problem.

Vijesh Aaniyamveetil said...

Glad to know that you were able to make it work

ajay said...

hello,

I have an issue, where in i am able to run the JBoss as windows service in XP.
I am using two approach :
1) Approach 1: Using JBoss native connector:
Issue with this service: Not able to start the service. Getting an error message “service started and stopped”. Tried setting with account also but it didn’t work.
2) Approach 2: Adding a batch script in registry of windows service to start JBoss:
Issue with this service: we are able to start and stop this service but when we logoff Jboss running as service gets stopped.

Appriciate your valuable inputs.

sunny said...

I have the similar problem as promod said when I am trying to run two instances. I have created a copy of service.bat and renamed it as service2.bat.

Done the below changes to service2.bat
1. Updated the bat file name as serrvice2.bat in :cmdInstall section
2. Changed the changed the run.log to run2.log in all the places.
3.Changed shutdown.log to shutdown2.log.
4. Updated :cmdStart section as below:
call run.bat -c instance2 -b hostname < .r.lock >> run2.log 2>&1

Did I miss anything here?

When I tried to start service2 i am getting the WIndows Service error --> "Some services stop automatically if they have no work to do, for example the Performance Log"

Any advice please...

Thanks
Sunil

sunny said...

Problem got fixed. Changed r.lock to r2.lock and s.lock to s2.loack in all the palces of service2.bat. Now two jobss services are running without any problem.

Thanks

Vijesh Aaniyamveetil said...

I was about to look into this. You beat me :)

James said...

I would like to say that you really made my day, it's wonderful when you just look around the web
and find something like this, reminds me of that ''How to make a dinner for a romantic...'' by Elsa Thomas,
you're a wonderful writer let me tell you!!! ñ_ñ

Buy Viagra
James Maverick (maverickhunterjames@gmail.com)
3453 Rardin Drive
San Mateo, CA 94403
Project Manager
650-627-8033

Giorgio said...

hi,
I have the same problem as ajay.
after an access using the /console parameter via rdp, when we log off from the system the service is stopped.
any ideas?

Nish said...

Hi, I am using JBoss 5.1 as windows service. I am installing it by using IZ pack. After installation, service get started with service type as manual. I want to make it as AUTOMATIC. So after machine restart I should able to see service has been started, no need to go in services.msc and start the service each time. Please let me know how to do this?

jhonny said...

Hi Nish,

I also tried to find how to make JBOSS service as automatic.
There is an alternative approach,any how you are using IZpack.better create an batch file and and make jboss service as automatic.This how i made JBOSS service as automatic.

Thanks
Ravi S

Mayura Wijeyaratne said...

Hi,

is there a way to specify the "log on as" user and the password from the service.bat file itself? so that when installing the service you won't have to manually change from "local system account"?

David Miller said...

Nice one,
I never found in the JBOSS documents that you should copy the files(jbosssvc.exe and service.bat) to the bin directory.

You helped me a lot with this.

Cheers
Dave

Cm punk said...

You hit comprehend out of the most construction topics.
iphone 4 parts

Brain Lara said...

Your blogs and information attracts me to come back again n again.
bad credit short term loans

Sir sheamus said...

I really enjoy while I read your blogs and articles.second dui penalties

Tips Tricks Ideas said...

I am not in favor of this new exam pattern.Its totally an injustice to the regional board aspirants.Its a well known fact that CBSE's marking system is comparatively easier than other regional boards.So,definitely CBSE candidates will score more in ISEET
tachnologys basket

Mark Bintuu said...

Nanotech Patent Lawyer

T Barnaby said...

genetic cavities

shahmat said...

Thank you for your post.

I am trying to install jboss 4.2.3, and I followed the instructions.

I have stopped jboss.

I got this error: "faild installing JBASXXX", this mean errolevel 2.

Any ideas?

Thanks in advance.

Sir Thom said...

The stuff you are penning blows out my mind.flashback counter

Richard Sandberg said...

Your write-ups are far more than wow!best graphics card for gaming

Albert einstien said...

It’s really very informative that I wanted ever, thanks for this.
open multiple url

Elvis Brine said...

Well, They are offering good services for work and I really enjoyed the information you have shared. Download free software

Alvin Paul said...

Can you please provide the complete the details what services you are proving for windows.

I read these one that you have posted here but I would like to know about the complete.

Regards,
Alvin
DDL FOR ALL

Andreea Watson said...

Nice review about JBoss with shares many interesting conceptual information about the blog. I really enjoyed it.
Fully Software Plus

Abell Gilbert said...

some of my concept are still not clear I will mail to know some more things about it. free software

Harry John said...

I consider the use of this software that how it works and its benefits. Thank you so much for sharing this article. free software

Rosalina Howard said...

Well Done Admin ...... you have done Nice Work ....
Portable Software | Free Download

Ellen said...

you might explain in deep.....
Full Softwares | Free Full Version Software

Julia Hernandez said...

valuable post! thankful for interesting and useful sharing.
Full Crack Software | Latest Software Download

Sara Williams said...

helpful sharing! thanks to share...
Crack Software | Software Download Free

Erika Martínez said...

It is Very Helpfull. I like it so much, Thanksss a lot.
Software Full Version | Download Free Software

Ladonns Akins said...

Very useful...!!! thanksss for sharing it.
Software Crack | Free Download Software

William M. Howard said...

Great post! This sites is really helpful for us and I really appreciate it. I learned and many great ideas here. Thanks for sharing!

crack software | download free software

Richard S. Maddox said...

Prevented me from having to do this manually; thus, very useful, and much appreciated.

full version software | photo mechanic 5 crack

Morris David said...

I appreciate thsi posting..its very helpful. Thanks!!!
cracked software download | 4k stogram license key

Marie Caren said...

Helped alot..thanks for sharing!
pftrack crack

Maliha Khan said...

i am really much impressed to see this post it had many useful points and technologies
Quick Heal Total Security 2015 Product Key & Crack

Unknown said...

I’ve to work with Servlets and JSP but having the problem in configuring JBOSS on windows xp platform. I’ve downloaded jboss-4.2.0.GA.zip, jboss_windows_service.zip... apache-ant-1.7.0-bin.zip & jboss-native-2.0.0-window...
Dissertation Help UK

Gerald A. McDade said...

Online diaries are web logs that are invigorated reliably, generally once per day. They contain information related to a specific point like Dissertation Point.Dissertation Services

Unknown said...

The organization is exceedingly devoted to giving finely-composed and truly referenced theses at genuinely reasonable costs. Do My Dissertation

CrackNest Pro said...

Aowsome, Helped alot..thanks for sharing it. license key for need for speed 2016