Article
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.
#!/bin/bash
# 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 ]
do
printf "."
sleep 1
SLEEPTIME=`expr $SLEEPTIME - 1`
done
if [ -d /proc/$PID ]; then
echo "Killing process $PID"
kill -9 $PID
fi
else
echo "Process $PROCESS is not running"
fi
Disclaimer: As with everything else at Cool Solutions, this content is definitely not supported by Novell (so don't even think of calling Support if you try something and it blows up).
It was contributed by a community member and is published "as is." It seems to have worked for at least one person, and might work for you. But please be sure to test, test, test before you do anything drastic with it.
Related Articles
User Comments
- Be the first to comment! To leave a comment you need to Login or Register
- 3230 reads


0