0

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.

4
  • Does sh /home/user/SoftZ/jboss-5.1.0.GA/bin/run.sh -c all & work correctly off the command line ? I always try to put the full path into shell scripts for cron, ie /bin/sh. Apr 2, 2011 at 16:22
  • Doing kill -9 is very drastic. Are you OK with the potential data loss this might produce?
    – Bittrance
    Apr 2, 2011 at 19:01
  • the data loss is not a problem, it's on a testing environment.
    – HowHigH
    Apr 2, 2011 at 22:04
  • i've tried with /bin/sh without success. the script works correctly when I launch it from the console, that's why it's weird
    – HowHigH
    Apr 2, 2011 at 22:05

2 Answers 2

2

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.

3
  • the solution with the jboss_init_redhat works. So in my script, because I need to understand, I must set console configuration?
    – HowHigH
    Apr 3, 2011 at 0:06
  • @HowHigH I am not sure if I understand your question. You want to know if you have to redirect outpu from console to /dev/null if you use jboss_init_redhat.sh? In that case it is not necessery, by default if you run JBoss using these script all output is redirect to /dev/null. If you want to check it you can open script and find JBOSS_CONSOLE variable. In that variable you have definition where to redirect output from JBoss. Apr 3, 2011 at 10:38
  • no, with my own script. With jboss_init_redhat.sh all works fine :) Thanks for your help.
    – HowHigH
    Apr 3, 2011 at 11:42
2

I am not really certain about this, but maybe your call to the run.sh script gets killed after your cron script finishes, since you are starting it in the background (&). You could try calling it with nohup to keep it running even when the cron process finishes, e. g.

/usr/bin/nohup /home/user/SoftZ/jboss-5.1.0.GA/bin/run.sh -c all &

This also works when you want to run a process on a remote machine but log out after starting it. Maybe give it a try.

1
  • it doesn't work. thanks for your attention
    – HowHigH
    Apr 3, 2011 at 0:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .