Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help Needed: Stopping JBoss when the databse server is down

 
Anand Natraj
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am a newbie to JBoss.

I want to configure my JBoss server in such a way that when my Database server is down my JBoss server should not start. How do i do this.

Please help me out.

Thanks in advance.

Regards,
Anand
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dont see a way of doing that. JBoss might have multiple applications deployed on it, if you would prevent JBoss from starting just because the database for one application is down, the other applications will also be affected. Why would you want this behaviour? Any specific requirement?
 
Anand Natraj
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jaikiran,

Thanks a lot for replying. Yes i have a specifc requirement for stopping the JBoss server if the databse server is down.

Thanks and Regards,
Anand
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a not so elegant method of doing what you want:
(Note that, in this approach, the shutdown of the server will happen only after your application is deployed)
- I guess you are using datasource for connecting to database.
- Once your application is deployed, do a lookup of the datasource and invoke the getConnection method on the datasource. Now since your database is down, you will be getting an exception. Catch the exception.
- Once you have caught the exception, programatically get access to the "jboss.system:type=Server" MBean(for doing this, you will have to get access to MBeanServer first as mentioned here.)
- Now once you have got access to the "jboss.system:type=Server" MBean, you can invoke the shutdown() method which is available on that MBean.

P.S.: I have never tried this before, but this is the only thing that came to my mind looking at your requirement.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But how would you do that if the JBoss Server is already running and the database is already running and something bad happens that the database goes down. JBoss won't be able to know that unless it is constantly requesting information from the database to see if it is still there.

Mark
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are right, that case cannot be handled by the approach mentioned in my post.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now, how about this concept. JBoss allows for validation queries to run when you create a Connection and when you get one out of the Pool. I think you can create your own validation object, that if the connection is bad, it double checks that the database is still up, and then if not, it shutsdown the App Server. That would be scary.

Mark
 
Johny Kk
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI Mark,

i think it can be done in the code level rte? caz i got the same kind of issue. During the start up process if the DB server is not available then i need to stop the application server b4 its getting started? is that possible

Thanks
Karthik
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Karthik Arumugam:
HI Mark,

i think it can be done in the code level rte? caz i got the same kind of issue. During the start up process if the DB server is not available then i need to stop the application server b4 its getting started? is that possible

Thanks
Karthik


Just scroll up and see Jaikiran Pai suggestion in this thread.

Mark
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now, how about this concept. JBoss allows for validation queries to run when you create a Connection and when you get one out of the Pool. I think you can create your own validation object, that if the connection is bad, it double checks that the database is still up, and then if not, it shutsdown the App Server


Are we talking about the <new-connection-sql> or <valid-connection-sql> on the datasource? Yes, this too looks like a option, provided we can create our own validation object(i will have to look at some docs to see if thats possible)
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mark Spritzler:
That would be scary.



The whole requirement of shutting down the app server because the database is down, looks scary. Usually if the database is down, the application would show a page which will mention the same, but the application server will still be running.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jaikiran Pai:


The whole requirement of shutting down the app server because the database is down, looks scary. Usually if the database is down, the application would show a page which will mention the same, but the application server will still be running.


Exactly, it should handle exceptions form the database, and then catch them accordingly.

Also from the stand point of App Server startup, shouldn't you know when you start your App Server if your database is down. I would hope so.

Mark
 
Johny Kk
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply sri and Mark. But i got the requirement like this wat 2 do?
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Karthik Arumugam:
Thanks for your reply sri and Mark. But i got the requirement like this wat 2 do?


Hit the person that made the requirement with a baseball bat, then throw them down the stairs, and yes that is a joke.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic