You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zookeeper.apache.org by si...@apache.org on 2012/07/05 07:26:10 UTC

svn commit: r1357466 - in /zookeeper/bookkeeper/trunk: CHANGES.txt bookkeeper-server/bin/bookkeeper bookkeeper-server/bin/bookkeeper-daemon.sh bookkeeper-server/conf/bkenv.sh bookkeeper-server/conf/log4j.properties

Author: sijie
Date: Thu Jul  5 05:26:09 2012
New Revision: 1357466

URL: http://svn.apache.org/viewvc?rev=1357466&view=rev
Log:
BOOKKEEPER-296: It's better provide stop script for bookie (nijel via sijie)

Added:
    zookeeper/bookkeeper/trunk/bookkeeper-server/bin/bookkeeper-daemon.sh   (with props)
Modified:
    zookeeper/bookkeeper/trunk/CHANGES.txt
    zookeeper/bookkeeper/trunk/bookkeeper-server/bin/bookkeeper
    zookeeper/bookkeeper/trunk/bookkeeper-server/conf/bkenv.sh
    zookeeper/bookkeeper/trunk/bookkeeper-server/conf/log4j.properties

Modified: zookeeper/bookkeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/CHANGES.txt?rev=1357466&r1=1357465&r2=1357466&view=diff
==============================================================================
--- zookeeper/bookkeeper/trunk/CHANGES.txt (original)
+++ zookeeper/bookkeeper/trunk/CHANGES.txt Thu Jul  5 05:26:09 2012
@@ -34,6 +34,8 @@ Trunk (unreleased changes)
 
         BOOKKEEPER-318: Spelling mistake in MultiCallback log message. (surendra via sijie)
 
+        BOOKKEEPER-296: It's better provide stop script for bookie (nijel via sijie)
+
       hedwig-client:
 
         BOOKKEEPER-274: Hedwig cpp client library should not link to cppunit which is just used for test. (sijie via ivank)

Modified: zookeeper/bookkeeper/trunk/bookkeeper-server/bin/bookkeeper
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-server/bin/bookkeeper?rev=1357466&r1=1357465&r2=1357466&view=diff
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-server/bin/bookkeeper (original)
+++ zookeeper/bookkeeper/trunk/bookkeeper-server/bin/bookkeeper Thu Jul  5 05:26:09 2012
@@ -149,6 +149,18 @@ OPTS="$OPTS $BOOKIE_EXTRA_OPTS"
 # Disable ipv6 as it can cause issues
 OPTS="$OPTS -Djava.net.preferIPv4Stack=true"
 
+# log directory & file
+BOOKIE_ROOT_LOGGER=${BOOKIE_ROOT_LOGGER:-"INFO,CONSOLE"}
+BOOKIE_LOG_DIR=${BOOKIE_LOG_DIR:-"$BK_HOME/logs"}
+BOOKIE_LOG_FILE=${BOOKIE_LOG_FILE:-"bookkeeper-server.log"}
+
+#Configure log configuration system properties
+OPTS="$OPTS -Dbookkeeper.root.logger=$BOOKIE_ROOT_LOGGER"
+OPTS="$OPTS -Dbookkeeper.log.dir=$BOOKIE_LOG_DIR"
+OPTS="$OPTS -Dbookkeeper.log.file=$BOOKIE_LOG_FILE"
+
+#Change to BK_HOME to support relative paths
+cd "$BK_HOME"
 if [ $COMMAND == "bookie" ]; then
     exec java $OPTS $JMX_ARGS org.apache.bookkeeper.proto.BookieServer --conf $BOOKIE_CONF $@
 elif [ $COMMAND == "localbookie" ]; then

Added: zookeeper/bookkeeper/trunk/bookkeeper-server/bin/bookkeeper-daemon.sh
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-server/bin/bookkeeper-daemon.sh?rev=1357466&view=auto
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-server/bin/bookkeeper-daemon.sh (added)
+++ zookeeper/bookkeeper/trunk/bookkeeper-server/bin/bookkeeper-daemon.sh Thu Jul  5 05:26:09 2012
@@ -0,0 +1,146 @@
+#!/usr/bin/env bash
+#
+#/**
+# * Licensed to the Apache Software Foundation (ASF) under one
+# * or more contributor license agreements.  See the NOTICE file
+# * distributed with this work for additional information
+# * regarding copyright ownership.  The ASF licenses this file
+# * to you under the Apache License, Version 2.0 (the
+# * "License"); you may not use this file except in compliance
+# * with the License.  You may obtain a copy of the License at
+# *
+# *     http://www.apache.org/licenses/LICENSE-2.0
+# *
+# * Unless required by applicable law or agreed to in writing, software
+# * distributed under the License is distributed on an "AS IS" BASIS,
+# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# * See the License for the specific language governing permissions and
+# * limitations under the License.
+# */
+
+usage="Usage: bookkeeper-daemon.sh (start|stop) <command> <args...>"
+supportedargs="Supported args : -force (accepted only with stop command) - Decides whether to stop the Bookie Server forcefully if not stopped by normal shutdown"
+
+BINDIR=`dirname "$0"`
+BK_HOME=`cd $BINDIR/..;pwd`
+
+if [ -f $BK_HOME/conf/bkenv.sh ]
+then
+ . $BK_HOME/conf/bkenv.sh
+fi
+
+BOOKIE_LOG_DIR=${BOOKIE_LOG_DIR:-"$BK_HOME/logs"}
+
+BOOKIE_ROOT_LOGGER=${BOOKIE_ROOT_LOGGER:-'INFO,ROLLINGFILE'}
+
+BOOKIE_STOP_TIMEOUT=${BOOKIE_STOP_TIMEOUT:-30}
+
+BOOKIE_PID_DIR=${BOOKIE_PID_DIR:-$BK_HOME/bin}
+
+startStop=$1
+shift
+command=$1
+shift
+
+export BOOKIE_LOG_DIR=$BOOKIE_LOG_DIR
+export BOOKIE_ROOT_LOGGER=$BOOKIE_ROOT_LOGGER
+export BOOKIE_LOG_FILE=bookkeeper-$command-$HOSTNAME.log
+
+pid=$BOOKIE_PID_DIR/bookkeeper-$command.pid
+out=$BOOKIE_LOG_DIR/bookkeeper-$command-$HOSTNAME.out
+logfile=$BOOKIE_LOG_DIR/$BOOKIE_LOG_FILE
+
+rotate_out_log ()
+{
+    log=$1;
+    num=5;
+    if [ -n "$2" ]; then
+       num=$2
+    fi
+    if [ -f "$log" ]; then # rotate logs
+        while [ $num -gt 1 ]; do
+            prev=`expr $num - 1`
+            [ -f "$log.$prev" ] && mv "$log.$prev" "$log.$num"
+            num=$prev
+        done
+        mv "$log" "$log.$num";
+    fi
+}
+
+mkdir -p "$BOOKIE_LOG_DIR"
+
+case $startStop in
+  (start)
+    if [ -f $pid ]; then
+      if kill -0 `cat $pid` > /dev/null 2>&1; then
+        echo $command running as process `cat $pid`.  Stop it first.
+        exit 1
+      fi
+    fi
+
+    rotate_out_log $out
+    echo starting $command, logging to $logfile
+    bookkeeper=$BK_HOME/bin/bookkeeper
+    nohup $bookkeeper $command "$@" > "$out" 2>&1 < /dev/null &
+    echo $! > $pid
+    sleep 1; head $out
+    sleep 2;
+    if ! ps -p $! > /dev/null ; then
+      exit 1
+    fi
+    ;;
+
+  (stop)
+    if [ -f $pid ]; then
+      TARGET_PID=`cat $pid`
+      if kill -0 $TARGET_PID > /dev/null 2>&1; then
+        echo stopping $command
+        kill $TARGET_PID
+
+        count=0
+        location=$BOOKIE_LOG_DIR
+        while ps -p $TARGET_PID > /dev/null;
+         do
+          echo "Shutdown is in progress... Please wait..."
+          sleep 1
+          count=`expr $count + 1`
+         
+          if [ "$count" = "$BOOKIE_STOP_TIMEOUT" ]; then
+                break
+          fi
+         done
+        
+        if [ "$count" != "$BOOKIE_STOP_TIMEOUT" ]; then
+                 echo "Shutdown completed."
+                exit 0
+        fi
+                 
+        if kill -0 $TARGET_PID > /dev/null 2>&1; then
+              fileName=$location/$command.out
+              $JAVA_HOME/bin/jstack $TARGET_PID > $fileName
+              echo Thread dumps are taken for analysis at $fileName
+              if [ "$1" == "-force" ]
+              then
+                 echo forcefully stopping $command
+                 kill -9 $TARGET_PID >/dev/null 2>&1
+                 echo Successfully stopped the process
+              else
+                 echo "WARNNING :  Bookie Server is not stopped completely."
+                 exit 1
+              fi
+        fi
+      else
+        echo no $command to stop
+      fi
+      rm $pid
+    else
+      echo no $command to stop
+    fi
+    ;;
+
+  (*)
+    echo $usage
+    echo $supportedargs
+    exit 1
+    ;;
+esac

Propchange: zookeeper/bookkeeper/trunk/bookkeeper-server/bin/bookkeeper-daemon.sh
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: zookeeper/bookkeeper/trunk/bookkeeper-server/conf/bkenv.sh
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-server/conf/bkenv.sh?rev=1357466&r1=1357465&r2=1357466&view=diff
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-server/conf/bkenv.sh (original)
+++ zookeeper/bookkeeper/trunk/bookkeeper-server/conf/bkenv.sh Thu Jul  5 05:26:09 2012
@@ -28,8 +28,17 @@
 # Log4j configuration file
 # BOOKIE_LOG_CONF=
 
+# Logs location
+# BOOKIE_LOG_DIR=
+
 # Extra options to be passed to the jvm
 # BOOKIE_EXTRA_OPTS=
 
 # Add extra paths to the bookkeeper classpath
 # BOOKIE_EXTRA_CLASSPATH=
+
+#Folder where the Bookie server PID file should be stored
+#BOOKIE_PID_DIR=
+
+#Wait time before forcefully kill the Bookie server instance, if the stop is not successful
+#BOOKIE_STOP_TIMEOUT=
\ No newline at end of file

Modified: zookeeper/bookkeeper/trunk/bookkeeper-server/conf/log4j.properties
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-server/conf/log4j.properties?rev=1357466&r1=1357465&r2=1357466&view=diff
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-server/conf/log4j.properties (original)
+++ zookeeper/bookkeeper/trunk/bookkeeper-server/conf/log4j.properties Thu Jul  5 05:26:09 2012
@@ -26,7 +26,12 @@
 # Format is "<default threshold> (, <appender>)+
 
 # DEFAULT: console appender only
-log4j.rootLogger=WARN, CONSOLE
+# Define some default values that can be overridden by system properties
+bookkeeper.root.logger=WARN,CONSOLE
+bookkeeper.log.dir=.
+bookkeeper.log.file=bookkeeper-server.log
+
+log4j.rootLogger=${bookkeeper.root.logger}
 
 # Example with rolling log file
 #log4j.rootLogger=DEBUG, CONSOLE, ROLLINGFILE
@@ -46,20 +51,20 @@ log4j.appender.CONSOLE.layout.Conversion
 # Add ROLLINGFILE to rootLogger to get log file output
 #    Log DEBUG level and above messages to a log file
 log4j.appender.ROLLINGFILE=org.apache.log4j.DailyRollingFileAppender
+
 log4j.appender.ROLLINGFILE.Threshold=INFO
-log4j.appender.ROLLINGFILE.File=bookkeeper-server.log
+log4j.appender.ROLLINGFILE.File=${bookkeeper.log.dir}/${bookkeeper.log.file}
 log4j.appender.ROLLINGFILE.layout=org.apache.log4j.PatternLayout
 log4j.appender.ROLLINGFILE.layout.ConversionPattern=%d{ISO8601} - %-5p - [%t:%C{1}@%L] - %m%n
 
 # Max log file size of 10MB
-log4j.appender.ROLLINGFILE.MaxFileSize=10MB
+#log4j.appender.ROLLINGFILE.MaxFileSize=10MB
 # uncomment the next line to limit number of backup files
 #log4j.appender.ROLLINGFILE.MaxBackupIndex=10
 
 log4j.appender.ROLLINGFILE.layout=org.apache.log4j.PatternLayout
 log4j.appender.ROLLINGFILE.layout.ConversionPattern=%d{ISO8601} - %-5p [%t:%C{1}@%L] - %m%n
 
-
 #
 # Add TRACEFILE to rootLogger to get log file output
 #    Log DEBUG level and above messages to a log file