Crontab to restart jboss server

cronjboss

i want to create a crontab to restart my jboss server every night. Nothing special and i thought it would be easy….

I got this crontab:

0 22 * * * /home/user/SoftZ/jboss-5.1.0.GA/bin/jboss_restart.sh

So every night at 22h it launches jboss_restart.sh which is as this:

#!/bin/sh
echo restarting jboss >> /home/user/SoftZ/logz.log

for pjboss in `ps -Af | grep -v grep | grep jboss | grep -v jboss_restart.sh | awk '{ print $2 }'`
do
    kill -9 ${pjboss}
    echo Killing >> /home/user/SoftZ/logz.log
done

echo Starting >> /home/user/SoftZ/logz.log
sh /home/user/SoftZ/jboss-5.1.0.GA/bin/run.sh -c all &
echo Finish >> /home/user/SoftZ/logz.log

So it's basic… the cron starts well and jboss_restart.sh too, everything is logged in logz.log and active process of jboss is killed but run.sh isn't started….. I tried several things such as chmod on the script, change the synthax of the command and crontab,… but nothing works. It's very annoying.

Could you help me please.
Thanks in advance.

Best Answer

The run.sh script saves logging infomration on console. If you want to run it in background you should:

  1. Redirect output to /dev/null:

    run.sh -c all &> /dev/null &
    
  2. Turn off console logging in the login-conf.xml.

But I think the best solution if will be use jboss_init_redhat.sh script. You can find it in the bin directory (the same where the run.sh script is placed).

The jboss_init_redhat.sh script is wrapper on run.sh which allow you to use it as Init V script - it has such parameters like start, stop. You have to set up it properly but its quite easy - just open it and edit some bash variables.

You can have some problems when you use some user to connect to JMX console. In that case you have to modify that script and add credential - the JMX use used to stop JBoss instance.

You have to modify JBOSS_CMD_STOP variable and add there your credentials.