Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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/

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

echo restarting jboss >> /home/user/SoftZ/logz.log

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

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

So it's basic... the cron starts well and too, everything is logged in logz.log and active process of jboss is killed but 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.

share|improve this question
Does sh /home/user/SoftZ/jboss-5.1.0.GA/bin/ -c all & work correctly off the command line ? I always try to put the full path into shell scripts for cron, ie /bin/sh. – Jonathan Ross Apr 2 '11 at 16:22
Doing kill -9 is very drastic. Are you OK with the potential data loss this might produce? – Bittrance Apr 2 '11 at 19:01
the data loss is not a problem, it's on a testing environment. – HowHigH Apr 2 '11 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 '11 at 22:05
up vote 2 down vote accepted

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

  1. Redirect output to /dev/null: -c all &> /dev/null &
  2. Turn off console logging in the login-conf.xml.

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

The script is wrapper on 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.

share|improve this answer
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 '11 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 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. – Lukasz Stelmach Apr 3 '11 at 10:38
no, with my own script. With all works fine :) Thanks for your help. – HowHigH Apr 3 '11 at 11:42

I am not really certain about this, but maybe your call to the 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/ -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.

share|improve this answer
it doesn't work. thanks for your attention – HowHigH Apr 3 '11 at 0:04

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.