bookkeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From si...@apache.org
Subject bookkeeper git commit: A few changes to the shell scripts to start bookies
Date Mon, 11 Jul 2016 18:54:23 GMT
Repository: bookkeeper
Updated Branches:
  refs/heads/master ab069c362 -> 319644863


A few changes to the shell scripts to start bookies

Author: Franck Cuny <franckcuny@gmail.com>

Reviewers: Sijie Guo <sijie@apache.org>

Closes #43 from franckcuny/fcuny/scripts-start-server


Project: http://git-wip-us.apache.org/repos/asf/bookkeeper/repo
Commit: http://git-wip-us.apache.org/repos/asf/bookkeeper/commit/31964486
Tree: http://git-wip-us.apache.org/repos/asf/bookkeeper/tree/31964486
Diff: http://git-wip-us.apache.org/repos/asf/bookkeeper/diff/31964486

Branch: refs/heads/master
Commit: 3196448632fd93b53964d58aaf070709d2bb050c
Parents: ab069c3
Author: Franck Cuny <franckcuny@gmail.com>
Authored: Mon Jul 11 11:54:15 2016 -0700
Committer: Sijie Guo <sijie@apache.org>
Committed: Mon Jul 11 11:54:15 2016 -0700

----------------------------------------------------------------------
 bookkeeper-server/bin/bookkeeper            | 134 +++++++++++++----------
 bookkeeper-server/bin/bookkeeper-cluster.sh | 128 +++++++++++-----------
 bookkeeper-server/bin/bookkeeper-daemon.sh  | 117 ++++++++++----------
 3 files changed, 200 insertions(+), 179 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/31964486/bookkeeper-server/bin/bookkeeper
----------------------------------------------------------------------
diff --git a/bookkeeper-server/bin/bookkeeper b/bookkeeper-server/bin/bookkeeper
index daa4991..54be3fe 100755
--- a/bookkeeper-server/bin/bookkeeper
+++ b/bookkeeper-server/bin/bookkeeper
@@ -35,18 +35,18 @@ fi
 # by default we allow local JMX connections
 if [ "x$JMXLOCALONLY" = "x" ]
 then
-    JMXLOCALONLY=false
+  JMXLOCALONLY=false
 fi
 
 if [ "x$JMXDISABLE" = "x" ]
 then
-    echo "JMX enabled by default" >&2
-    # for some reason these two options are necessary on jdk6 on Ubuntu
-    #   accord to the docs they are not necessary, but otw jconsole cannot
-    #   do a local attach
-    JMX_ARGS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=$JMXLOCALONLY"
+  echo "JMX enabled by default" >&2
+  # for some reason these two options are necessary on jdk6 on Ubuntu
+  #   accord to the docs they are not necessary, but otw jconsole cannot
+  #   do a local attach
+  JMX_ARGS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=$JMXLOCALONLY"
 else
-    echo "JMX disabled by user request" >&2
+  echo "JMX disabled by user request" >&2
 fi
 
 BINDIR=`dirname "$0"`
@@ -59,31 +59,51 @@ source $BK_HOME/conf/bkenv.sh
 
 # Check for the java to use
 if [[ -z $JAVA_HOME ]]; then
-    JAVA=$(which java)
-    if [ $? = 0 ]; then
-        echo "JAVA_HOME not set, using java from PATH. ($JAVA)"
-    else
-        echo "Error: JAVA_HOME not set, and no java executable found in $PATH." 1>&2
-        exit 1
-    fi
+  JAVA=$(which java)
+  if [ $? = 0 ]; then
+    echo "JAVA_HOME not set, using java from PATH. ($JAVA)"
+  else
+    echo "Error: JAVA_HOME not set, and no java executable found in $PATH." 1>&2
+    exit 1
+  fi
 else
-    JAVA=$JAVA_HOME/bin/java
+  JAVA=$JAVA_HOME/bin/java
 fi
 
 # exclude tests jar
-RELEASE_JAR=`ls $BK_HOME/bookkeeper-server-*.jar 2> /dev/null | grep -v tests | tail -1`

-if [ $? == 0 ]; then
-    BOOKIE_JAR=$RELEASE_JAR
+RELEASE_JAR=$(ls ${BK_HOME}/bookkeeper-server-*.jar 2> /dev/null | grep -v tests | tail
-1)
+if [ -n "${RELEASE_JAR}" ]; then
+  BOOKIE_JAR=$RELEASE_JAR
 fi
 
 # exclude tests jar
-BUILT_JAR=`ls $BK_HOME/target/bookkeeper-server-*.jar 2> /dev/null | grep -v tests | tail
-1`
-if [ $? != 0 ] && [ ! -e "$BOOKIE_JAR" ]; then 
-    echo "\nCouldn't find bookkeeper jar.";
-    echo "Make sure you've run 'mvn package'\n";
-    exit 1;
-elif [ -e "$BUILT_JAR" ]; then
+BUILT_JAR=$(ls ${BK_HOME}/target/bookkeeper-server-*.jar 2> /dev/null | grep -v tests
| tail -1)
+
+if [ -z "${BUILT_JAR}" ] && [ -z "${BOOKIE_JAR}" ]; then
+  echo "Couldn't find bookkeeper jar."
+  read -p "Do you want me to run \`mvn package -DskiptTests\` for you ? " answer
+  case "${answer:0:1}" in
+    y|Y )
+      mvn package -DskipTests
+      ;;
+    * )
+      exit 1
+      ;;
+  esac
+
+  BUILT_JAR=$(ls ${BK_HOME}/target/bookkeeper-server-*.jar 2> /dev/null | grep -v tests
| tail -1)
+  if [ -n "${BUILT_JAR}" ]; then
     BOOKIE_JAR=$BUILT_JAR
+  fi
+fi
+
+if [ -e "${BUILT_JAR}" ]; then
+  BOOKIE_JAR="${BUILT_JAR}"
+fi
+
+if [ ! -e "${BOOKIE_JAR}" ]; then
+  echo "Could not find bookkeeper jar."
+  exit 1
 fi
 
 bookkeeper_help() {
@@ -113,34 +133,34 @@ EOF
 }
 
 add_maven_deps_to_classpath() {
-    MVN="mvn"
-    if [ "$MAVEN_HOME" != "" ]; then
-	MVN=${MAVEN_HOME}/bin/mvn
-    fi
-    
-    # Need to generate classpath from maven pom. This is costly so generate it
-    # and cache it. Save the file into our target dir so a mvn clean will get
-    # clean it up and force us create a new one.
-    f="${BK_HOME}/target/cached_classpath.txt"
-    if [ ! -f "${f}" ]
-    then
-	${MVN} -f "${BK_HOME}/pom.xml" dependency:build-classpath -Dmdep.outputFile="${f}" &>
/dev/null
-    fi
-    BOOKIE_CLASSPATH=${CLASSPATH}:`cat "${f}"`
+  MVN="mvn"
+  if [ "$MAVEN_HOME" != "" ]; then
+    MVN=${MAVEN_HOME}/bin/mvn
+  fi
+
+  # Need to generate classpath from maven pom. This is costly so generate it
+  # and cache it. Save the file into our target dir so a mvn clean will get
+  # clean it up and force us create a new one.
+  f="${BK_HOME}/target/cached_classpath.txt"
+  if [ ! -f "${f}" ]
+  then
+    ${MVN} -f "${BK_HOME}/pom.xml" dependency:build-classpath -Dmdep.outputFile="${f}" &>
/dev/null
+  fi
+  BOOKIE_CLASSPATH=${CLASSPATH}:`cat "${f}"`
 }
 
 if [ -d "$BK_HOME/lib" ]; then
-    for i in $BK_HOME/lib/*.jar; do
-	BOOKIE_CLASSPATH=$BOOKIE_CLASSPATH:$i
-    done
+  for i in $BK_HOME/lib/*.jar; do
+    BOOKIE_CLASSPATH=$BOOKIE_CLASSPATH:$i
+  done
 else
-    add_maven_deps_to_classpath
+  add_maven_deps_to_classpath
 fi
 
 # if no args specified, show usage
 if [ $# = 0 ]; then
-    bookkeeper_help;
-    exit 1;
+  bookkeeper_help;
+  exit 1;
 fi
 
 # get arguments
@@ -148,15 +168,15 @@ COMMAND=$1
 shift
 
 if [ $COMMAND == "shell" ]; then
-    DEFAULT_LOG_CONF=$BK_HOME/conf/log4j.shell.properties
+  DEFAULT_LOG_CONF=$BK_HOME/conf/log4j.shell.properties
 fi
 
 if [ -z "$BOOKIE_CONF" ]; then
-    BOOKIE_CONF=$DEFAULT_CONF
+  BOOKIE_CONF=$DEFAULT_CONF
 fi
 
 if [ -z "$BOOKIE_LOG_CONF" ]; then
-    BOOKIE_LOG_CONF=$DEFAULT_LOG_CONF
+  BOOKIE_LOG_CONF=$DEFAULT_LOG_CONF
 fi
 
 BOOKIE_CLASSPATH="$BOOKIE_JAR:$BOOKIE_CLASSPATH:$BOOKIE_EXTRA_CLASSPATH"
@@ -183,21 +203,21 @@ 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
$@
+  exec $JAVA $OPTS $JMX_ARGS org.apache.bookkeeper.proto.BookieServer --conf $BOOKIE_CONF
$@
 elif [ $COMMAND == "autorecovery" ]; then
-    exec $JAVA $OPTS $JMX_ARGS org.apache.bookkeeper.replication.AutoRecoveryMain --conf
$BOOKIE_CONF $@
+  exec $JAVA $OPTS $JMX_ARGS org.apache.bookkeeper.replication.AutoRecoveryMain --conf $BOOKIE_CONF
$@
 elif [ $COMMAND == "localbookie" ]; then
-    NUMBER=$1
-    shift
-    exec $JAVA $OPTS $JMX_ARGS org.apache.bookkeeper.util.LocalBookKeeper $NUMBER $BOOKIE_CONF
$@
+  NUMBER=$1
+  shift
+  exec $JAVA $OPTS $JMX_ARGS org.apache.bookkeeper.util.LocalBookKeeper $NUMBER $BOOKIE_CONF
$@
 elif [ $COMMAND == "upgrade" ]; then
-    exec $JAVA $OPTS org.apache.bookkeeper.bookie.FileSystemUpgrade --conf $BOOKIE_CONF $@
+  exec $JAVA $OPTS org.apache.bookkeeper.bookie.FileSystemUpgrade --conf $BOOKIE_CONF $@
 elif [ $COMMAND == "shell" ]; then
-    ENTRY_FORMATTER_ARG="-DentryFormatterClass=${ENTRY_FORMATTER_CLASS:-org.apache.bookkeeper.util.StringEntryFormatter}"
-    exec $JAVA $OPTS $ENTRY_FORMATTER_ARG org.apache.bookkeeper.bookie.BookieShell -conf
$BOOKIE_CONF $@
+  ENTRY_FORMATTER_ARG="-DentryFormatterClass=${ENTRY_FORMATTER_CLASS:-org.apache.bookkeeper.util.StringEntryFormatter}"
+  exec $JAVA $OPTS $ENTRY_FORMATTER_ARG org.apache.bookkeeper.bookie.BookieShell -conf $BOOKIE_CONF
$@
 elif [ $COMMAND == "help" ]; then
-    bookkeeper_help;
+  bookkeeper_help;
 else
-    exec $JAVA $OPTS $COMMAND $@
+  exec $JAVA $OPTS $COMMAND $@
 fi
 

http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/31964486/bookkeeper-server/bin/bookkeeper-cluster.sh
----------------------------------------------------------------------
diff --git a/bookkeeper-server/bin/bookkeeper-cluster.sh b/bookkeeper-server/bin/bookkeeper-cluster.sh
index d27236d..3686761 100644
--- a/bookkeeper-server/bin/bookkeeper-cluster.sh
+++ b/bookkeeper-server/bin/bookkeeper-cluster.sh
@@ -41,95 +41,95 @@ EOF
 }
 
 if [ ! -f $CLUSTER ]; then
-    echo -e "\nCluster file ($CLUSTER) does not exist\n"
-    usage
-    exit 1
+  echo -e "\nCluster file ($CLUSTER) does not exist\n"
+  usage
+  exit 1
 fi
 
 NUMHOSTS=$(wc -l $CLUSTER | awk '{print $1}')
 if [ "$NUMHOSTS" = "0" ]; then
-    echo -e "\nCluster file ($CLUSTER) is empty\n"
-    usage
-    exit 1
+  echo -e "\nCluster file ($CLUSTER) is empty\n"
+  usage
+  exit 1
 fi
 
 bookies_list() {
-    $BINDIR/bookkeeper shell listbookies 2> /dev/null
+  $BINDIR/bookkeeper shell listbookies 2> /dev/null
 }
 
 bookies_available() {
-    bookies_list | wc -l
+  bookies_list | wc -l
 }
 
 start() {
-    for B in `cat $CLUSTER`; do
-	echo "Starting bookie on $B"
-	ssh $B $BINDIR/bookkeeper-daemon.sh start bookie
-    done
-
-    BOOKIESSTARTED=0
-    COUNT=0
-
-    while [ $BOOKIESSTARTED -lt $NUMHOSTS ];  do
-	sleep 1
-	COUNT=$(($COUNT+1))
-	if [ $COUNT = 20 ]; then
-	    echo "Could not start all bookies"
-	    exit 1
-	fi
-
-	BOOKIESSTARTED=$(bookies_available)
-
-	echo "$BOOKIESSTARTED bookies started"
-    done
+  for B in `cat $CLUSTER`; do
+    echo "Starting bookie on $B"
+    ssh $B $BINDIR/bookkeeper-daemon.sh start bookie
+  done
+
+  BOOKIESSTARTED=0
+  COUNT=0
+
+  while [ $BOOKIESSTARTED -lt $NUMHOSTS ];  do
+    sleep 1
+    COUNT=$(($COUNT+1))
+    if [ $COUNT = 20 ]; then
+      echo "Could not start all bookies"
+      exit 1
+    fi
+
+    BOOKIESSTARTED=$(bookies_available)
+
+    echo "$BOOKIESSTARTED bookies started"
+  done
 }
 
 stop() {
-    for B in `cat $CLUSTER`; do
-	echo "Stopping bookie on $B"
-	ssh $B $BINDIR/bookkeeper-daemon.sh stop bookie $FORCE
-    done
-
-    COUNT=0
-    BOOKIESSTARTED=$NUMHOSTS
-    while [ $BOOKIESSTARTED -gt 0 ];  do
-	sleep 1
-	
-	COUNT=$((COUNT+1))
-	if [ $COUNT = 20 ]; then
-	    echo "Couldn not stop all bookies. $BOOKIESSTARTED still running"
-	    exit 2
-	fi
-
-	BOOKIESSTARTED=$(bookies_available)
-    done
+  for B in `cat $CLUSTER`; do
+    echo "Stopping bookie on $B"
+    ssh $B $BINDIR/bookkeeper-daemon.sh stop bookie $FORCE
+  done
+
+  COUNT=0
+  BOOKIESSTARTED=$NUMHOSTS
+  while [ $BOOKIESSTARTED -gt 0 ];  do
+    sleep 1
+
+    COUNT=$((COUNT+1))
+    if [ $COUNT = 20 ]; then
+      echo "Couldn not stop all bookies. $BOOKIESSTARTED still running"
+      exit 2
+    fi
+
+    BOOKIESSTARTED=$(bookies_available)
+  done
 }
 
 status() {
-    BOOKIESSTARTED=$(bookies_available)
-    echo "$BOOKIESSTARTED bookies running"
-    COUNT=1
-    for b in $(bookies_list); do
-	echo "$COUNT: $b"
-	COUNT=$(($COUNT+1))
-    done
+  BOOKIESSTARTED=$(bookies_available)
+  echo "$BOOKIESSTARTED bookies running"
+  COUNT=1
+  for b in $(bookies_list); do
+    echo "$COUNT: $b"
+    COUNT=$(($COUNT+1))
+  done
 }
 
 case $1 in
     start)
-	start
-	;;
+      start
+      ;;
     stop)
-	stop
-	;;
+      stop
+      ;;
     kill)
-	FORCE="-force"
-	stop
-	;;
+      FORCE="-force"
+      stop
+      ;;
     status)
-	status
-	;;
+      status
+      ;;
     *)
-	usage
-	;;
+      usage
+      ;;
 esac

http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/31964486/bookkeeper-server/bin/bookkeeper-daemon.sh
----------------------------------------------------------------------
diff --git a/bookkeeper-server/bin/bookkeeper-daemon.sh b/bookkeeper-server/bin/bookkeeper-daemon.sh
index 766f528..dab21f6 100755
--- a/bookkeeper-server/bin/bookkeeper-daemon.sh
+++ b/bookkeeper-server/bin/bookkeeper-daemon.sh
@@ -29,8 +29,8 @@ where argument is one of:
 EOF
 }
 
-BINDIR=`dirname "$0"`
-BK_HOME=`cd $BINDIR/..;pwd`
+BINDIR=$(dirname "$0")
+BK_HOME=$(cd $BINDIR/..;pwd)
 
 if [ -f $BK_HOME/conf/bkenv.sh ]
 then
@@ -47,9 +47,9 @@ BOOKIE_PID_DIR=${BOOKIE_PID_DIR:-$BK_HOME/bin}
 
 if [ $# -lt 2 ]
 then
-    echo "Error: no enough arguments provided."
-    usage
-    exit 1
+  echo "Error: no enough arguments provided."
+  usage
+  exit 1
 fi
 
 startStop=$1
@@ -58,51 +58,52 @@ command=$1
 shift
 
 case $command in
-    (bookie)
-        echo "doing $startStop $command ..."
-        ;;
-    (autorecovery)
-        echo "doing $startStop $command ..."
-        ;;
-    (*)
-        echo "Error: unknown service name $command"
-        usage
-        exit 1
-        ;;
+  (bookie)
+    echo "doing $startStop $command ..."
+    ;;
+  (autorecovery)
+    echo "doing $startStop $command ..."
+    ;;
+  (*)
+    echo "Error: unknown service name $command"
+    usage
+    exit 1
+    ;;
 esac
 
 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
+pid_file="${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
+  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.
+    if [ -f $pid_file ]; then
+      PREVIOUS_PID=$(cat $pid_file)
+      if kill -0 $PREVIOUS_PID > /dev/null 2>&1; then
+        echo $command running as process $PREVIOUS_PID.  Stop it first.
         exit 1
       fi
     fi
@@ -111,56 +112,56 @@ case $startStop in
     echo starting $command, logging to $logfile
     bookkeeper=$BK_HOME/bin/bookkeeper
     nohup $bookkeeper $command "$@" > "$out" 2>&1 < /dev/null &
-    echo $! > $pid
+    echo $! > $pid_file
     sleep 1; head $out
     sleep 2;
-    if ! ps -p $! > /dev/null ; then
+    if ! kill -0 $! > /dev/null ; then
       exit 1
     fi
     ;;
 
   (stop)
-    if [ -f $pid ]; then
-      TARGET_PID=`cat $pid`
+    if [ -f $pid_file ]; then
+      TARGET_PID=$(cat $pid_file)
       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
+        while kill -0 $TARGET_PID > /dev/null;
+        do
           echo "Shutdown is in progress... Please wait..."
           sleep 1
-          count=`expr $count + 1`
-         
+          count=$(expr $count + 1)
+
           if [ "$count" = "$BOOKIE_STOP_TIMEOUT" ]; then
-                break
+            break
           fi
          done
-        
+
         if [ "$count" != "$BOOKIE_STOP_TIMEOUT" ]; then
-            echo "Shutdown completed."
+          echo "Shutdown completed."
         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
+          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
+      rm $pid_file
     else
       echo no $command to stop
     fi


Mime
View raw message