From: <ma...@rh...> - 2009-01-06 22:22:08
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><style type="text/css"><!-- #msg DL { border : 1px #006 solid; background-color : #369; padding : 6px; color : #fff; } #msg DT { float : left; width : 6em; font-weight : bold; } #msg DL, #msg DT, #msg UL, #msg LI { font-family : arial,helvetica,sans-serif; font-size : 10pt; } h3 { font-family : arial,helvetica,sans-serif; font-size : 10pt; font-weight : bold; } #msg PRE { overflow : auto; white-space : normal; background-color : #ffc; border : 1px #fc0 solid; padding : 6px; } #msg UL, PRE, .diff { overflow : auto; } #patch h4 { font-family : arial,helvetica,sans-serif; font-size : 10pt; } #patch h4 { padding: 8px; background : #369; color : #fff; margin : 0; } #patch .propset h4, #patch .binary h4 {margin: 0;} #patch pre {padding:0;line-height:1.2em;margin:0;} #patch .diff {background:#eeeeee;padding: 0 0 10px 0;} #patch .propset .diff, #patch .binary .diff {padding: 10px 0;} #patch span {display:block;padding:0 10px;} #patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;} #patch .add {background:#ddffdd;} #patch .rem {background:#ffdddd;} #patch .lines, .info {color:#888888;background:#ffffff;} .diff { width : 100%; } #msg DL { border : 1px #006 solid; background-color : #369; padding : 6px; color : #fff; } #msg DT { float : left; width : 6em; font-weight : bold; } #msg DL, #msg DT, #msg UL, #msg LI { font-family : arial,helvetica,sans-serif; font-size : 10pt; } h3 { font-family : arial,helvetica,sans-serif; font-size : 10pt; font-weight : bold; } #msg PRE { overflow : auto; white-space : normal; background-color : #ffc; border : 1px #fc0 solid; padding : 6px; } #msg UL, PRE, .diff { overflow : auto; } #patch h4 { font-family : arial,helvetica,sans-serif; font-size : 10pt; } #patch h4 { padding: 8px; background : #369; color : #fff; margin : 0; } #patch .propset h4, #patch .binary h4 {margin: 0;} #patch pre {padding:0;line-height:1.2em;margin:0;} #patch .diff {background:#eeeeee;padding: 0 0 10px 0;} #patch .propset .diff, #patch .binary .diff {padding: 10px 0;} #patch span {display:block;padding:0 10px;} #patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;} #patch .add {background:#ddffdd;} #patch .rem {background:#ffdddd;} #patch .lines, .info {color:#888888;background:#ffffff;} .diff { width : 100%; } --></style> <title>[rhq-project.org rhq] [2565] [RHQ-1325] rhq-server.sh kill really kills the server now (both the run.sh and the VM process).</title> </head> <body> <div id="msg"> <dl> <dt>Revision</dt> <dd>2565</dd> <dt>Author</dt> <dd>mazz</dd> <dt>Date</dt> <dd>2009-01-06 16:21:52 -0600 (Tue, 06 Jan 2009)</dd> </dl> <h3>Log Message</h3> <pre>[RHQ-1325] rhq-server.sh kill really kills the server now (both the run.sh and the VM process). status option also shows you both pids.</pre> <h3>Modified Paths</h3> <ul> <li><a href="#rhqtrunkmodulesenterpriseservercontainersrcmainbinresourcesbinrhqserversh">rhq/trunk/modules/enterprise/server/container/src/main/bin-resources/bin/rhq-server.sh</a></li> <li><a href="#rhqtrunkmodulesenterpriseservercontainersrcmainresourcesjbossasbinrunsh">rhq/trunk/modules/enterprise/server/container/src/main/resources/jbossas/bin/run.sh</a></li> </ul> </div> <div id="patch"> <h3>Diff</h3> <a id="rhqtrunkmodulesenterpriseservercontainersrcmainbinresourcesbinrhqserversh"></a> <div class="modfile"><h4>Modified: rhq/trunk/modules/enterprise/server/container/src/main/bin-resources/bin/rhq-server.sh (2564 => 2565)</h4> <pre class="diff"> <span class="info">--- rhq/trunk/modules/enterprise/server/container/src/main/bin-resources/bin/rhq-server.sh 2009-01-06 21:43:40 UTC (rev 2564) +++ rhq/trunk/modules/enterprise/server/container/src/main/bin-resources/bin/rhq-server.sh 2009-01-06 22:21:52 UTC (rev 2565) </span><span class="lines">@@ -102,35 +102,55 @@ </span><span class="cx"> } # ---------------------------------------------------------------------- </span><span class="rem">-# Sets STATUS, RUNNING and PID based on the status of the RHQ Server </span><span class="add">+# Sets _SERVER_STATUS, _SERVER_RUNNING and _SERVER_PID based on the +# status of the RHQ Server VM start script (run.sh). +# Also sets _JVM_STATUS, _JVM_RUNNING and _JVM_PID based on the +# status of the JBossAS Java Virtual Machine. </span><span class="cx"> # ---------------------------------------------------------------------- check_status () { </span><span class="rem">- if [ -f "$PIDFILE" ]; then - PID=`cat "$PIDFILE"` - if [ -n "$PID" ] && kill -0 $PID 2>/dev/null ; then - STATUS="RHQ Server (pid $PID) is $1" - RUNNING=1 </span><span class="add">+ if [ -f "$_SERVER_PIDFILE" ]; then + _SERVER_PID=`cat "$_SERVER_PIDFILE"` + if [ -n "$_SERVER_PID" ] && kill -0 $_SERVER_PID 2>/dev/null ; then + _SERVER_STATUS="RHQ Server (pid $_SERVER_PID) is $1" + _SERVER_RUNNING=1 </span><span class="cx"> else </span><span class="rem">- STATUS="RHQ Server (pid $PID) is NOT running" - RUNNING=0 </span><span class="add">+ _SERVER_STATUS="RHQ Server (pid $_SERVER_PID) is NOT running" + _SERVER_RUNNING=0 </span><span class="cx"> fi else </span><span class="rem">- STATUS="RHQ Server (no pid file) is NOT running" - RUNNING=0 </span><span class="add">+ _SERVER_STATUS="RHQ Server (no pid file) is NOT running" + _SERVER_RUNNING=0 </span><span class="cx"> fi </span><span class="add">+ + if [ -f "$_JVM_PIDFILE" ]; then + _JVM_PID=`cat "$_JVM_PIDFILE"` + if [ -n "$_JVM_PID" ] && kill -0 $_JVM_PID 2>/dev/null ; then + _JVM_STATUS="JBossAS Java VM child process (pid $_JVM_PID) is $1" + _JVM_RUNNING=1 + else + _JVM_STATUS="JBossAS Java VM child process (pid $_JVM_PID) is NOT running" + _JVM_RUNNING=0 + fi + else + _JVM_STATUS="JBossAS Java VM child process (no pid file) is NOT running" + _JVM_RUNNING=0 + fi </span><span class="cx"> } # ---------------------------------------------------------------------- </span><span class="rem">-# Ensures that the PID file no longer exists </span><span class="add">+# Ensures that the PID files no longer exist </span><span class="cx"> # ---------------------------------------------------------------------- </span><span class="rem">-remove_pid_file () </span><span class="add">+remove_pid_files () </span><span class="cx"> { </span><span class="rem">- if [ -f "$PIDFILE" ]; then - rm "$PIDFILE" </span><span class="add">+ if [ -f "$_SERVER_PIDFILE" ]; then + rm "$_SERVER_PIDFILE" </span><span class="cx"> fi </span><span class="add">+ if [ -f "$_JVM_PIDFILE" ]; then + rm "$_JVM_PIDFILE" + fi </span><span class="cx"> } # ---------------------------------------------------------------------- </span><span class="lines">@@ -268,7 +288,10 @@ </span><span class="cx"> debug_msg "_JBOSS_RUN_SCRIPT: $_JBOSS_RUN_SCRIPT" # ---------------------------------------------------------------------- </span><span class="rem">-# Define where we want to write the pidfile - let user override the dir </span><span class="add">+# Define where we want to write the pidfiles - let user override the dir +# Note that we actually have two pidfiles - one is for the script +# that starts the JBossAS Java virtual machine and the second is the +# actual server's Java virtual machine process itself. </span><span class="cx"> # ---------------------------------------------------------------------- if [ -z "$RHQ_SERVER_PIDFILE_DIR" ]; then </span><span class="lines">@@ -276,7 +299,8 @@ </span><span class="cx"> fi mkdir -p "$RHQ_SERVER_PIDFILE_DIR" </span><span class="rem">-PIDFILE="${RHQ_SERVER_PIDFILE_DIR}/rhq-server.pid" </span><span class="add">+_SERVER_PIDFILE="${RHQ_SERVER_PIDFILE_DIR}/rhq-server.pid" +_JVM_PIDFILE="${RHQ_SERVER_PIDFILE_DIR}/rhq-jvm.pid" </span><span class="cx"> # ---------------------------------------------------------------------- # Execute the command that the user wants us to do </span><span class="lines">@@ -286,35 +310,38 @@ </span><span class="cx"> case "$1" in 'console') </span><span class="rem">- if [ "$RUNNING" = "1" ]; then - echo "$STATUS" </span><span class="add">+ if [ "$_SERVER_RUNNING" = "1" ]; then + echo "$_SERVER_STATUS" </span><span class="cx"> exit 0 fi echo "Starting RHQ Server in console..." </span><span class="rem">- echo "$$" > "$PIDFILE" </span><span class="add">+ # we are running in foreground, make both pids show the same process + echo "$$" > "$_SERVER_PIDFILE" + echo "$$" > "$_JVM_PIDFILE" </span><span class="cx"> # start the server, making sure its working directory is the JBossAS bin directory cd "${RHQ_SERVER_HOME}/jbossas/bin" "$_JBOSS_RUN_SCRIPT" $RHQ_SERVER_CMDLINE_OPTS </span><span class="rem">- JBOSS_STATUS=$? </span><span class="add">+ _JBOSS_STATUS=$? </span><span class="cx"> </span><span class="rem">- rm "$PIDFILE" </span><span class="add">+ rm "$_SERVER_PIDFILE" + rm "$_JVM_PIDFILE" </span><span class="cx"> </span><span class="rem">- exit $JBOSS_STATUS </span><span class="add">+ exit $_JBOSS_STATUS </span><span class="cx"> ;; 'start') </span><span class="rem">- if [ "$RUNNING" = "1" ]; then - echo "$STATUS" </span><span class="add">+ if [ "$_SERVER_RUNNING" = "1" ]; then + echo "$_SERVER_STATUS" </span><span class="cx"> exit 0 fi echo "Trying to start the RHQ Server..." </span><span class="rem">- LAUNCH_JBOSS_IN_BACKGROUND=true </span><span class="add">+ LAUNCH_JBOSS_IN_BACKGROUND="$_JVM_PIDFILE" </span><span class="cx"> export LAUNCH_JBOSS_IN_BACKGROUND # start the server, making sure its working directory is the JBossAS bin directory </span><span class="lines">@@ -325,13 +352,13 @@ </span><span class="cx"> "$_JBOSS_RUN_SCRIPT" $RHQ_SERVER_CMDLINE_OPTS > /dev/null 2>&1 & fi </span><span class="rem">- echo "$!" > "$PIDFILE" </span><span class="add">+ echo "$!" > "$_SERVER_PIDFILE" </span><span class="cx"> sleep 5 check_status "starting" </span><span class="rem">- echo "$STATUS" </span><span class="add">+ echo "$_SERVER_STATUS" </span><span class="cx"> </span><span class="rem">- if [ "$RUNNING" = "1" ]; then </span><span class="add">+ if [ "$_SERVER_RUNNING" = "1" ]; then </span><span class="cx"> exit 0 else echo "Failed to start - make sure the RHQ Server is fully configured properly" </span><span class="lines">@@ -340,51 +367,61 @@ </span><span class="cx"> ;; 'stop') </span><span class="rem">- if [ "$RUNNING" = "0" ]; then - echo "$STATUS" - remove_pid_file </span><span class="add">+ if [ "$_SERVER_RUNNING" = "0" ]; then + echo "$_SERVER_STATUS" + remove_pid_files </span><span class="cx"> exit 0 fi echo "Trying to stop the RHQ Server..." </span><span class="rem">- echo "RHQ Server (pid=${PID}) is stopping..." </span><span class="add">+ echo "RHQ Server (pid=${_SERVER_PID}) is stopping..." </span><span class="cx"> </span><span class="rem">- while [ "$RUNNING" = "1" ]; do - kill -TERM $PID </span><span class="add">+ while [ "$_SERVER_RUNNING" = "1" ]; do + kill -TERM $_SERVER_PID </span><span class="cx"> sleep 2 check_status "stopping..." done </span><span class="rem">- remove_pid_file </span><span class="add">+ remove_pid_files </span><span class="cx"> echo "RHQ Server has stopped." exit 0 ;; 'kill') </span><span class="rem">- if [ "$RUNNING" = "0" ]; then - echo "$STATUS" - remove_pid_file </span><span class="add">+ if [ "$_SERVER_RUNNING" = "0" ]; then + echo "$_SERVER_STATUS" + fi + if [ "$_JVM_RUNNING" = "0" ]; then + echo "$_JVM_STATUS" + remove_pid_files </span><span class="cx"> exit 0 fi echo "Trying to kill the RHQ Server..." </span><span class="rem">- echo "RHQ Server (pid=${PID}) is being killed..." </span><span class="add">+ echo "RHQ Server parent process (pid=${_SERVER_PID}) is being killed..." + while [ "$_SERVER_RUNNING" = "1" ]; do + kill -9 $_SERVER_PID + sleep 2 + check_status "killing..." + done </span><span class="cx"> </span><span class="rem">- while [ "$RUNNING" = "1" ]; do - kill -9 $PID </span><span class="add">+ echo "Java Virtual Machine child process (pid=${_JVM_PID}) is being killed..." + while [ "$_JVM_RUNNING" = "1" ]; do + kill -9 $_JVM_PID </span><span class="cx"> sleep 2 check_status "killing..." done </span><span class="rem">- remove_pid_file </span><span class="add">+ remove_pid_files </span><span class="cx"> echo "RHQ Server has been killed." exit 0 ;; 'status') </span><span class="rem">- echo "$STATUS" </span><span class="add">+ echo "$_SERVER_STATUS" + echo "$_JVM_STATUS" </span><span class="cx"> exit 0 ;; </span></pre></div> <a id="rhqtrunkmodulesenterpriseservercontainersrcmainresourcesjbossasbinrunsh"></a> <div class="modfile"><h4>Modified: rhq/trunk/modules/enterprise/server/container/src/main/resources/jbossas/bin/run.sh (2564 => 2565)</h4> <pre class="diff"> <span class="info">--- rhq/trunk/modules/enterprise/server/container/src/main/resources/jbossas/bin/run.sh 2009-01-06 21:43:40 UTC (rev 2564) +++ rhq/trunk/modules/enterprise/server/container/src/main/resources/jbossas/bin/run.sh 2009-01-06 22:21:52 UTC (rev 2565) </span><span class="lines">@@ -220,6 +220,8 @@ </span><span class="cx"> -classpath "$JBOSS_CLASSPATH" \ org.jboss.Main "$@" & JBOSS_PID=$! </span><span class="add">+ # the LAUNCH_JBOSS_IN_BACKGROUND is actually the full path to the pidfile + echo $JBOSS_PID > $LAUNCH_JBOSS_IN_BACKGROUND </span><span class="cx"> # Trap common signals and relay them to the jboss process trap "kill -HUP $JBOSS_PID" HUP trap "kill -TERM $JBOSS_PID" INT </span> </pre> </div> </div> </body> </html> |