Browse Source

adding startup and shutdown scripts for zookeeper servers. Also adding a script to startup the zookeeper client interface. The log4 file is included in the jar now. The users can change the log4j properties by setting evn variables in the script and also by adding log4j.properties in the classpath.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/zookeeper/trunk@670945 13f79535-47bb-0310-9956-ffa450edef68
17 năm trước cách đây
mục cha
commit
f976de7506
5 tập tin đã thay đổi với 141 bổ sung3 xóa
  1. 21 0
      zookeeper/bin/zkCleanup.sh
  2. 21 0
      zookeeper/bin/zkCli.sh
  3. 52 0
      zookeeper/bin/zkEnv.sh
  4. 43 0
      zookeeper/bin/zkServer.sh
  5. 4 3
      zookeeper/build.xml

+ 21 - 0
zookeeper/bin/zkCleanup.sh

@@ -0,0 +1,21 @@
+#!/bin/sh
+#
+# This script cleans up old transaction logs and snapshots
+#
+
+#
+# If this scripted is run out of /usr/bin or some other system bin directory
+# it should be linked to and not copied. Things like java jar files are found
+# relative to the canonical path of this script.
+#
+
+ZOOBIN=`readlink -f "$0"`
+ZOOBINDIR=`dirname "$ZOOBIN"`
+
+. $ZOOBINDIR/zkEnv.sh
+
+eval `grep -e "^dataDir=" $ZOOCFG`
+
+java "-Dzookeeper.log.dir=${ZOO_LOG_DIR}" "-Dzookeeper.root.logger=${ZOO_LOG4J_PROP}" \
+     -cp $CLASSPATH $JVMFLAGS \
+     com.yahoo.zookeeper.server.PurgeTxnLog $dataDir

+ 21 - 0
zookeeper/bin/zkCli.sh

@@ -0,0 +1,21 @@
+#!/bin/sh
+#
+# This script cleans up old transaction logs and snapshots
+#
+
+#
+# If this scripted is run out of /usr/bin or some other system bin directory
+# it should be linked to and not copied. Things like java jar files are found
+# relative to the canonical path of this script.
+#
+
+ZOOBIN=`readlink -f "$0"`
+ZOOBINDIR=`dirname "$ZOOBIN"`
+
+. $ZOOBINDIR/zkEnv.sh
+
+eval `grep -e "^dataDir=" $ZOOCFG`
+
+java "-Dzookeeper.log.dir=${ZOO_LOG_DIR}" "-Dzookeeper.root.logger=${ZOO_LOG4J_PROP}" \
+     -cp $CLASSPATH $JVMFLAGS \
+     com.yahoo.zookeeper.ZooKeeper $@

+ 52 - 0
zookeeper/bin/zkEnv.sh

@@ -0,0 +1,52 @@
+#!/bin/sh
+
+# This script should be sourced into other zookeeper
+# scripts to setup the env variables
+
+# We use ZOOCFGDIR if defined,
+# otherwise we use /etc/zookeeper
+# or the conf directory that is
+# a sibling of this script's directory
+if [ "x$ZOOCFGDIR" = "x" ]
+then
+    if [ -d "/etc/zookeeper" ]
+    then
+        ZOOCFGDIR="/etc/zookeeper"
+    else
+        ZOOCFGDIR="$ZOOBINDIR/../conf"
+    fi
+fi
+
+if [ -e "$ZOOCFGDIR/java.env" ]
+then
+    . "$ZOOCFGDIR/java.env"
+fi
+
+if [ "x$ZOO_LOG_DIR" = "x" ]
+then 
+    ZOO_LOG_DIR="."
+fi
+
+if [ "x$ZOO_LOG4J_PROP" = "x" ]
+then 
+    ZOO_LOG4J_PROP="INFO,CONSOLE"
+fi
+
+for f in ${ZOOBINDIR}/../zookeeper-*.jar
+do 
+    CLASSPATH="$CLASSPATH:$f"
+done
+
+ZOOLIBDIR=${ZOOLIBDIR:-$ZOOBINDIR/../lib}
+for i in "$ZOOLIBDIR"/*.jar
+do
+    CLASSPATH="$CLASSPATH:$i"
+done
+#make it work for developers
+for d in ${ZOOBINDIR}/../java/lib/*.jar
+do
+   CLASSPATH="$CLASSPATH:$d"
+done
+
+
+ZOOCFG="$ZOOCFGDIR/zoo.cfg"

+ 43 - 0
zookeeper/bin/zkServer.sh

@@ -0,0 +1,43 @@
+#!/bin/sh
+#
+# If this scripted is run out of /usr/bin or some other system bin directory
+# it should be linked to and not copied. Things like java jar files are found
+# relative to the canonical path of this script.
+#
+
+ZOOBIN=`readlink -f "$0"`
+ZOOBINDIR=`dirname "$ZOOBIN"`
+
+. $ZOOBINDIR/zkEnv.sh
+
+case $1 in
+start) 
+    echo -n "Starting zookeeper ... "
+    java  "-Dzookeeper.log.dir=${ZOO_LOG_DIR}" "-Dzookeeper.root.logger=${ZOO_LOG4J_PROP}" \
+    -cp $CLASSPATH $JVMFLAGS com.yahoo.zookeeper.server.quorum.QuorumPeer $ZOOCFG &
+    echo STARTED
+    ;;
+stop) 
+    echo -n "Stopping zookeeper ... "
+    echo kill | nc localhost $(grep clientPort $ZOOCFG | sed -e 's/.*=//')
+    echo STOPPED
+    ;;
+restart)
+    shift
+    $0 stop ${@}
+    sleep 3
+    $0 start ${@}
+    ;;
+status)
+    STAT=`echo stat | nc localhost $(grep clientPort $ZOOCFG | sed -e 's/.*=//') 2> /dev/null| grep Mode`
+    if [ "x$STAT" = "x" ]
+    then
+        echo "Error contacting service. It is probably not running." 
+    else
+        echo $STAT
+    fi
+    ;;
+*)
+    echo "Usage: $0 {start|stop|restart|status}" >&2
+
+esac

+ 4 - 3
zookeeper/build.xml

@@ -25,7 +25,7 @@
     <property name="test.junit.output.format" value="plain" />
     <property name="config.dir" value="${basedir}/test/config" />
     <property name="test.junit.maxmem" value="512m" />
-
+    <property name="conf.dir" value="${basedir}/conf"/>
     <property name="javadoc.link.java" value="http://java.sun.com/j2se/1.5/docs/api/" />
     <property name="javadoc.packages" value="com.yahoo.*" />
     <property name="build.docs" value="${build.dir}/docs" />
@@ -167,7 +167,8 @@
         <exec executable="hostname" outputproperty="host.name"/>
         <jar jarfile="${jar.name}"> 
             <fileset file="LICENSE" />
-            <fileset dir="${build.classes}"/> 
+            <fileset dir="${build.classes}"/>
+            <fileset file="${conf.dir}/log4j.properties"/> 
             <manifest>
                 <attribute name="Main-Class" value="com.yahoo.zookeeper.server.quorum.QuorumPeer" />
                 <attribute name="Built-By" value="${user.name}"/>
@@ -212,10 +213,10 @@
             timeout="${test.timeout}" errorProperty="tests.failed"
             failureProperty="tests.failed">
           <sysproperty key="build.test.dir" value="${test.tmp.dir}" />
+          <classpath refid="test.classpath"/>
           <classpath>
             <pathelement path="${build.testclasses}" />
           </classpath>
-          <classpath refid="test.classpath"/>
           <formatter type="${test.junit.output.format}" />
           <batchtest todir="${test.log.dir}" unless="testcase">
             <fileset dir="${test.src.dir}"