A customer approached me with a problem: a jboss process needed to be stopped every morning at 3:00am and restarted at 3:30am via cron. There is a shell script for jboss that should accomplish this, but periodically jboss wouldn’t actually stop – resulting in two instances running in the morning.

The solution we came up with was this small bash script that was setup to execute along with the jboss stop shell script, which sets a configurable upper limit for how long to wait before forcefully killing the process corresponding to /home/jboss/jdk1.5.0_12/bin/java.


# Start script configuration options
PROCESS="/home/jboss/jdk1.5.0_12/bin/java"       # The process we are looking for
SLEEPTIME=120         # How many seconds we will wait
# End script configuration options

PID=$(ps auxww | grep $PROCESS | grep -v grep | cut -c10-14 | sed 's/^[ \t]*//;s/[ \t]*$//')

if [ -n "$PID" ]; then
  while [ -d /proc/$PID -a $SLEEPTIME -ne 0 ]
      printf "."
      sleep 1
      SLEEPTIME=`expr $SLEEPTIME - 1`

  if [ -d /proc/$PID ]; then
    echo "Killing process $PID"
    kill -9 $PID
  echo "Process $PROCESS is not running"
(Visited 1 times, 1 visits today)
Tags: ,
Category: Enterprise Linux, SUSE Linux Enterprise Server, Technical Solutions
This entry was posted Tuesday, 14 April, 2009 at 4:38 pm
You can follow any responses to this entry via RSS.

Leave a Reply

Your email address will not be published. Required fields are marked *

No comments yet