How do you kill your jboss instance. -- GNU/Linux

2,506 views
Skip to first unread message

Kadinamkulam

unread,
Sep 5, 2012, 6:01:58 PM9/5/12
to atg_...@googlegroups.com

Hi,

I am using the below script to kill my jboss instance, lets say estore..
But it takes a while to complete..

Any help, pleae share the command which you guys use in ur your project , if you are  running under GNU/Linux



> ps -ef | grep jboss-mybccserver-ca



> kill `pstree -p 20169 | sed 's/(/\n(/g' | grep '(' | sed 's/(\(.*\)).*/\1/' | tr "\n" " "`

ecom:/data/atg/jboss-eap-4.3/jboss-as>$ uname -a

Linux  2.6.32-220.7.1.el6.x86_64 #1 SMP Fri Feb 10 15:22:22 EST 2012 x86_64 x86_64 x86_64 GNU/Linux

Warm Regards
KdM

Shailendra Pateria

unread,
Sep 5, 2012, 6:14:11 PM9/5/12
to atg_...@googlegroups.com
We have simple solution, not sure if it fits with what you need...

JAVAPID=$(ps -ef | grep -v grep | grep -v $SCRIPT | grep java | grep $INSTANCE | awk '{print $2}')

function checkIfStopped() {
        echo "Waiting for $INSTANCE service to stop completely"
        local c=0
        local i=0
        while [ $c -eq $i ]
        do
                if ps -ef | grep -v grep | grep -v $SCRIPT | grep java | grep $INSTANCE > /dev/null
                then
                        if [ $c -gt 6 ]; then
                                echo "JBoss took long time to stop. Do you want to just kill it? [Y/N]"
                                read KILLER
                                if [[ $KILLER =~ ^[Yy]$ ]]; then
                                        kill -9 $JAVAPID
                                fi
                        fi
                        (( c++ ))
                        echo "."
                        sleep 10
                fi
                (( i++ ))
        done
        echo "Stopped.."
}



--
--
You received this message because you are subscribed to the Google Groups "ATG_Tech" group.
To post to this group, send email to atg_...@googlegroups.com
To unsubscribe from this group, send email to atg_tech-u...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/atg_tech?hl=en
 
 



--
Cheers,
Shailendra

Kadinamkulam

unread,
Sep 5, 2012, 6:17:57 PM9/5/12
to atg_...@googlegroups.com
Hi Shailendra,

What is this $SCRIPT ? is it specific to your env ?

Warm Regards
KdM

Shailendra Pateria

unread,
Sep 5, 2012, 6:19:51 PM9/5/12
to atg_...@googlegroups.com
$SCRIPT is basically the name of the script used to start JBOSS instance...

Gordon Cooke

unread,
Sep 5, 2012, 6:40:40 PM9/5/12
to atg_...@googlegroups.com
Shailendra - I do not know if it is your script or just that you only pasted a partial script but this will always loop 6 times and then issue a kill -9 (after prompting)

Doing a kill -9 is not advisable.  The initial way without the -9 is much cleaner (it looks like your script may do this somewhere else?).  It will take time to shut your server down but it also allows it to clean up the DMS/JMS/DAS_GSA_SUBSCRIBER (among other) queues and tables.  This will prevent issues as you stop and start servers. 

kill -9 is great IF the server is a state that it is totally hung and not recovering or shutting down.

Our stop scripts typically issue the kill <pid>, wait for a period of time (2-5 minutes) and then, if the process is still running, reissues the kill with the -9 option.

KdM : 
What you are doing is not wrong but more complicated then it needs to be.  Sending a kill to the pid (in your example 20169) should shut down the JBoss instance cleanly with no issues (assuming that 20169 is your java process).  Is this locally in a development env or a managed/production environment?

The pstree and sed commands below are unnecesary as near as I can tellcd

 kill `pstree -p 20169 | sed 's/(/\n(/g' | grep '(' | sed 's/(\(.*\)).*/\1/' | tr "\n" " "`


There are a dozen ways to pull the PID out (the awk Shailendra has below is fine).  Pass that to the following :

function stopInstance {
        PID=$1

        #sending a QUIT to do a thread dump to console
        kill -QUIT $PID

        #sending a interrupt which should stop jboss
        kill $PID

        # give the instance 2 minutes to shut down, and then kill it if it hasn't
        waitTime=0
        until [  $waitTime -gt 120 ]; do
                sleep 2
                ps -p $PID>/dev/null
                if [ $? != 0 ]; then
                        break
                fi
                let waitTime+=2
    done

        ps -p $PID>/dev/null
        if [ $? = 0 ]; then
          kill -9 $PID
        fi
}



Spark::red
Gordon Cooke, Partner
Spark::red
8201 1564th Ave NE Suite 200, Redmond, WA, 98052
Main: 888.666.5582 | Mobile: 206.384.1314
Twitter Facebook Blog

 

Kadinamkulam

unread,
Sep 5, 2012, 7:46:25 PM9/5/12
to atg_...@googlegroups.com
Hi Gordon,

Mostly i am concerned about the timing.

In Redhat,

just find the PID ..
Then ptree the PID.

Kill the process, it will terminate all the parent and its child process immediately.

But In GNU/Linux. it is taking time by stopping each process one by one and is eating time mostly 1 min.

Warm Regards
KdM

Shailendra Pateria

unread,
Sep 5, 2012, 9:10:31 PM9/5/12
to atg_...@googlegroups.com
Calling the Kill function threw me off since we wouldn't use it as preferred way of stopping the jboss...

Here is how we do start stops normally...

JBOSS_CMD_START="$JBOSS_HOME/bin/run.sh -c  $JBOSS_CONF -Dsun.rmi.dgc.server.gcInterval=3600000 -Djboss.server.log
.dir=$JBOSS_LOG -b $JBOSS_HOST -g STORE-PS -u $JBOSS_MCAST"


JBOSS_CMD_STOP=${JBOSS_CMD_STOP:-"java -classpath $JBOSS_HOME/bin/shutdown.jar:$JBOSS_HOME/client/jnet.jar org.jboss.Shutdown -u admin -p admin -s jnp://$JBOSS_HOST:$JBOSS_RMI "}

Unless you do a hard kill it will always wait for threads to release and as Gordon mentioned, clearing the temp data.

AVINEET SHARMA

unread,
Sep 10, 2012, 11:54:18 PM9/10/12
to atg_...@googlegroups.com

Plus the advantage of using atg shutdown cmd is that it cleans up the servers heap and cache as well. However, using a kill will not clean up the no more used memory elements from the heap.
Avineet

Reply all
Reply to author
Forward
0 new messages