views:

53

answers:

3

I'm trying find out, how to start jboss with cron job at a particular time.

What I'm doing at the moment is setup a cron, then inside jboss startinstance script I put sleep 700 seconds untill jboss starts.

Is there a better way to actually know when jboss has successfully started and then continue with the flow after, instead of sleeping for 700 seconds? Did anyone do something similar?

I've got something like this, and I don't think this is the right solution :

#!/bin/ksh
#This script accepts one parameter URL which should to tracked

usage() {
    msg=${1}
    echo "ERROR: "
    exit 1
}

args_no=$#

if [[ ${args_no} -ne 1 ]]; then
    usage
fi

URL_to_check=${1}

jboss_status=1

while [[ ${jboss_status} -ne 0 ]]; do
    wget ${URL_to_check} > /dev/null
    jboss_status=$?
    sleep 10
done

exit 0  
+1  A: 

Why is JBoss startup a scheduled job? Shouldn't JBoss just be started and run for a very long time?

The best way to start JBoss is to start the server once, without a sleep, and let it run for months or years. That means that the operating system it's deployed on is stable and your application doesn't leak memory. You should only bring JBoss down for OS patches and application updates.

Anything else and you've got a problem that you should dig into to resolve.

duffymo
@duffymo because each time I start it it will run different war
c0mrade
@duffymo when you deploy a lot to your JBoss instance for testing purposes you have to restart it from time to time. Otherwise it eventually runs into a `OutOfMemoryError`. However, I agree that JBoss can/should run for a very long time without deployment.
kraftan
+1  A: 

You could poll your log file and check for the line

ServerImpl.info: JBoss.*Started in

and sleep in between the polls. For instance:

LOG_FILE=/path/to/jboss.log
start_info=''

while [[ ! -n "${start_info}" ]]; do
    start_info=`grep "ServerImpl.info: JBoss.*Started in" $LOG_FILE`
    sleep 10
done
kraftan
@kraftan I edited my question, did you mean something like this? instead of polling log file its basically the same principle if I understood you correctly
c0mrade
@c0mrade No. I thought about checking your JBoss log file. For instance with a `grep` command. I adjusted my answer accordingly.
kraftan
A: 

The JBoss Maven plugin has a start-and-wait goal which does what you are looking for by checking server state via the JNDI port. If this sounds compelling, you could peek into the source code to see how it does what it does.

Péter Török
@Péter Török tnx Peter I could do that, is it in Java or ?
c0mrade
@c0mrade, yes, see http://mojo.codehaus.org/jboss-maven-plugin/source-repository.html
Péter Török