accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From els...@apache.org
Subject accumulo git commit: ACCUMULO-925 Add pidfile support to scripts
Date Tue, 30 Jun 2015 01:11:36 GMT
Repository: accumulo
Updated Branches:
  refs/heads/master 414c140f5 -> b10c172ea


ACCUMULO-925 Add pidfile support to scripts

Signed-off-by: Josh Elser <elserj@apache.org>


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

Branch: refs/heads/master
Commit: b10c172ea3ee009864bd406b6c8a09233ecb55a3
Parents: 414c140
Author: Billie Rinaldi <billie@apache.org>
Authored: Wed Jun 24 22:13:58 2015 -0400
Committer: Josh Elser <elserj@apache.org>
Committed: Mon Jun 29 21:10:08 2015 -0400

----------------------------------------------------------------------
 assemble/bin/config-server.sh           | 12 +++-
 assemble/bin/start-all.sh               |  2 +-
 assemble/bin/start-daemon.sh            | 94 ++++++++++++++++++++++++++++
 assemble/bin/start-here.sh              |  4 +-
 assemble/bin/start-server.sh            | 68 +++++---------------
 assemble/bin/stop-here.sh               |  8 +--
 assemble/bin/stop-server.sh             | 20 +++---
 assemble/bin/tup.sh                     |  2 +-
 assemble/conf/templates/accumulo-env.sh |  1 +
 9 files changed, 137 insertions(+), 74 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/b10c172e/assemble/bin/config-server.sh
----------------------------------------------------------------------
diff --git a/assemble/bin/config-server.sh b/assemble/bin/config-server.sh
index eb3fd55..dad3e81 100755
--- a/assemble/bin/config-server.sh
+++ b/assemble/bin/config-server.sh
@@ -15,7 +15,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-# Guarantees that Accumulo and its environment variables are set.
+# Guarantees that Accumulo and its environment variables are set for start
+# and stop scripts.  Should always be run after config.sh.
 #
 # Parameters checked by script
 #  ACCUMULO_VERIFY_ONLY set to skip actions that would alter the local filesystem
@@ -70,3 +71,12 @@ SSH='ssh -qnf -o ConnectTimeout=2'
 
 # ACCUMULO-1985 provide a way to use the scripts and still bind to all network interfaces
 export ACCUMULO_MONITOR_BIND_ALL=${ACCUMULO_MONITOR_BIND_ALL:-"false"}
+
+if [[ -z "${ACCUMULO_PID_DIR}" ]]; then
+  export ACCUMULO_PID_DIR="${ACCUMULO_HOME}/run"
+fi
+[[ -z ${ACCUMULO_VERIFY_ONLY} ]] && mkdir -p "${ACCUMULO_PID_DIR}" 2>/dev/null
+
+if [[ -z "${ACCUMULO_IDENT_STRING}" ]]; then
+  export ACCUMULO_IDENT_STRING="$USER"
+fi

http://git-wip-us.apache.org/repos/asf/accumulo/blob/b10c172e/assemble/bin/start-all.sh
----------------------------------------------------------------------
diff --git a/assemble/bin/start-all.sh b/assemble/bin/start-all.sh
index a4596db..975d306 100755
--- a/assemble/bin/start-all.sh
+++ b/assemble/bin/start-all.sh
@@ -70,7 +70,7 @@ for master in $(egrep -v '(^#|^\s*$)' "$ACCUMULO_CONF_DIR/masters"); do
 done
 
 for gc in $(egrep -v '(^#|^\s*$)' "$ACCUMULO_CONF_DIR/gc"); do
-   ${bin}/start-server.sh $gc gc "garbage collector"
+   ${bin}/start-server.sh $gc gc
 done
 
 for tracer in $(egrep -v '(^#|^\s*$)' "$ACCUMULO_CONF_DIR/tracers"); do

http://git-wip-us.apache.org/repos/asf/accumulo/blob/b10c172e/assemble/bin/start-daemon.sh
----------------------------------------------------------------------
diff --git a/assemble/bin/start-daemon.sh b/assemble/bin/start-daemon.sh
new file mode 100755
index 0000000..507fcb0
--- /dev/null
+++ b/assemble/bin/start-daemon.sh
@@ -0,0 +1,94 @@
+#! /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.
+
+# Start: Resolve Script Directory
+SOURCE="${BASH_SOURCE[0]}"
+while [[ -h "$SOURCE" ]]; do # resolve $SOURCE until the file is no longer a symlink
+   bin="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
+   SOURCE="$(readlink "$SOURCE")"
+   [[ $SOURCE != /* ]] && SOURCE="$bin/$SOURCE" # if $SOURCE was a relative symlink,
we need to resolve it relative to the path where the symlink file was located
+done
+bin="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
+script=$( basename "$SOURCE" )
+# Stop: Resolve Script Directory
+
+usage="Usage: start-daemon.sh <host> <service>"
+
+if [[ $# -ne 2 ]]; then
+  echo $usage
+  exit 2
+fi
+
+. "$bin"/config.sh
+. "$bin"/config-server.sh
+
+HOST="$1"
+ADDRESS=$HOST
+host "$1" >/dev/null 2>&1
+if [[ $? != 0 ]]; then
+   LOGHOST=$HOST
+else
+   LOGHOST=$(host "$HOST" | head -1 | cut -d' ' -f1)
+fi
+SERVICE=$2
+
+SLAVES=$(wc -l < "${ACCUMULO_CONF_DIR}/slaves")
+
+# When the hostname provided is the alias/shortname, try to use the FQDN to make
+# sure we send the right address to the Accumulo process.
+if [[ "$HOST" = "$(hostname -s)" ]]; then
+   HOST="$(hostname -f)"
+   ADDRESS="$HOST"
+fi
+
+# ACCUMULO-1985 Allow monitor to bind on all interfaces
+if [[ ${SERVICE} == "monitor" && ${ACCUMULO_MONITOR_BIND_ALL} == "true" ]]; then
+   ADDRESS="0.0.0.0"
+fi
+
+# Check the pid file to figure out if its already running.
+PID_FILE="${ACCUMULO_PID_DIR}/accumulo-${ACCUMULO_IDENT_STRING}-${SERVICE}.pid"
+if [ -f ${PID_FILE} ]; then
+   PID=`cat ${PID_FILE}`
+   if kill -0 $PID 2>/dev/null; then
+      # Starting an already-started service shouldn't be an error per LSB
+      echo "$HOST : $SERVICE already running (${PID})"
+      exit 0
+   fi
+else
+   echo "Starting $SERVICE on $HOST"
+fi
+
+COMMAND="${bin}/accumulo"
+if [ "${ACCUMULO_WATCHER}" = "true" ]; then
+   COMMAND="${bin}/accumulo_watcher.sh ${LOGHOST}"
+fi
+
+# Fork the process, store the pid
+nohup ${NUMA_CMD} "$COMMAND" "${SERVICE}" --address "${ADDRESS}" >"${ACCUMULO_LOG_DIR}/${SERVICE}_${LOGHOST}.out"
2>"${ACCUMULO_LOG_DIR}/${SERVICE}_${LOGHOST}.err" < /dev/null &
+echo $! > ${PID_FILE}
+
+# Check the max open files limit and selectively warn
+MAX_FILES_OPEN=$(ulimit -n)
+
+if [[ -n $MAX_FILES_OPEN && -n $SLAVES ]] ; then
+   MAX_FILES_RECOMMENDED=${MAX_FILES_RECOMMENDED:-32768}
+   if (( SLAVES > 10 )) && (( MAX_FILES_OPEN < MAX_FILES_RECOMMENDED ))
+   then
+      echo "WARN : Max open files on $HOST is $MAX_FILES_OPEN, recommend $MAX_FILES_RECOMMENDED"
>&2
+   fi
+fi

http://git-wip-us.apache.org/repos/asf/accumulo/blob/b10c172e/assemble/bin/start-here.sh
----------------------------------------------------------------------
diff --git a/assemble/bin/start-here.sh b/assemble/bin/start-here.sh
index 76bcc96..dba1779 100755
--- a/assemble/bin/start-here.sh
+++ b/assemble/bin/start-here.sh
@@ -43,7 +43,7 @@ fi
 HOSTS="$(hostname -a 2> /dev/null) $(hostname) localhost 127.0.0.1 $IP"
 for host in $HOSTS; do
    if grep -q "^${host}\$" "$ACCUMULO_CONF_DIR/slaves"; then
-      "${bin}/start-server.sh" "$host" tserver "tablet server"
+      "${bin}/start-server.sh" "$host" tserver
       break
    fi
 done
@@ -58,7 +58,7 @@ done
 
 for host in $HOSTS; do
    if grep -q "^${host}\$" "$ACCUMULO_CONF_DIR/gc"; then
-      "${bin}/start-server.sh" "$host" gc "garbage collector"
+      "${bin}/start-server.sh" "$host" gc
       break
    fi
 done

http://git-wip-us.apache.org/repos/asf/accumulo/blob/b10c172e/assemble/bin/start-server.sh
----------------------------------------------------------------------
diff --git a/assemble/bin/start-server.sh b/assemble/bin/start-server.sh
index 8266457..d5b7594 100755
--- a/assemble/bin/start-server.sh
+++ b/assemble/bin/start-server.sh
@@ -26,72 +26,32 @@ bin="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
 script=$( basename "$SOURCE" )
 # Stop: Resolve Script Directory
 
+# Really, we still support the third <long_name> argument, but let's not tell people
that..
+usage="Usage: start-server.sh <host> <service>"
+
+# Support the 3-arg invocation for backwards-compat
+if [[ $# -ne 2 ]] && [[ $# -ne 3 ]]; then
+  echo $usage
+  exit 2
+fi
+
 . "$bin"/config.sh
 . "$bin"/config-server.sh
 
 HOST="$1"
-host "$1" >/dev/null 2>/dev/null
-if [[ $? != 0 ]]; then
-   LOGHOST="$1"
-else
-   LOGHOST=$(host "$1" | head -1 | cut -d' ' -f1)
-fi
-ADDRESS=$1
-SERVICE=$2
-LONGNAME=$3
-[[ -z $LONGNAME ]] && LONGNAME=$2
-
-SLAVES=$(wc -l < "${ACCUMULO_CONF_DIR}/slaves")
+SERVICE="$2"
 
 IFCONFIG=/sbin/ifconfig
 [[ ! -x $IFCONFIG ]] && IFCONFIG='/bin/netstat -ie'
 
-
 IP=$($IFCONFIG 2>/dev/null| grep "inet[^6]" | awk '{print $2}' | sed 's/addr://' | grep
-v 0.0.0.0 | grep -v 127.0.0.1 | head -n 1)
 if [[ $? != 0 ]] ; then
    IP=$(python -c 'import socket as s; print s.gethostbyname(s.getfqdn())')
 fi
 
-# When the hostname provided is the alias/shortname, try to use the FQDN to make
-# sure we send the right address to the Accumulo process.
-if [[ "$HOST" = "$(hostname -s)" ]]; then
-    HOST="$(hostname -f)"
-    ADDRESS="$HOST"
-fi
-
-# ACCUMULO-1985 Allow monitor to bind on all interfaces
-if [[ ${SERVICE} == "monitor" && ${ACCUMULO_MONITOR_BIND_ALL} == "true" ]]; then
-    ADDRESS="0.0.0.0"
-fi
-
-if [[ $HOST == localhost || $HOST == "$(hostname -f)" || $HOST = "$IP" ]]; then
-   PID=$(ps -ef | egrep ${ACCUMULO_HOME}/.*/accumulo.*.jar | grep "Main $SERVICE" | grep
-v grep | awk {'print $2'} | head -1)
-else
-   PID=$($SSH "$HOST" ps -ef | egrep "${ACCUMULO_HOME}/.*/accumulo.*.jar" | grep "Main $SERVICE"
| grep -v grep | awk {'print $2'} | head -1)
-fi
-
-if [[ -z "$PID" ]]; then
-   echo "Starting $LONGNAME on $HOST"
-   COMMAND="${bin}/accumulo"
-   if [ "${ACCUMULO_WATCHER}" = "true" ]; then
-      COMMAND="${bin}/accumulo_watcher.sh ${LOGHOST}"
-   fi
-
-   if [[ $HOST == localhost || $HOST == "$(hostname -f)" || $HOST = "$IP" ]]; then
-      ${NUMA_CMD} "$COMMAND" "${SERVICE}" --address "${ADDRESS}" >"${ACCUMULO_LOG_DIR}/${SERVICE}_${LOGHOST}.out"
2>"${ACCUMULO_LOG_DIR}/${SERVICE}_${LOGHOST}.err" &
-      MAX_FILES_OPEN=$(ulimit -n)
-   else
-      $SSH "$HOST" "bash -c 'exec nohup ${NUMA_CMD} $COMMAND ${SERVICE} --address ${ADDRESS}
>${ACCUMULO_LOG_DIR}/${SERVICE}_${LOGHOST}.out 2>${ACCUMULO_LOG_DIR}/${SERVICE}_${LOGHOST}.err'
&"
-      MAX_FILES_OPEN=$($SSH "$HOST" "/usr/bin/env bash -c 'ulimit -n'")
-   fi
-
-   if [[ -n $MAX_FILES_OPEN && -n $SLAVES ]] ; then
-      MAX_FILES_RECOMMENDED=${MAX_FILES_RECOMMENDED:-32768}
-      if (( SLAVES > 10 )) && (( MAX_FILES_OPEN < MAX_FILES_RECOMMENDED ))
-      then
-         echo "WARN : Max open files on $HOST is $MAX_FILES_OPEN, recommend $MAX_FILES_RECOMMENDED"
>&2
-      fi
-   fi
+if [[ $HOST == "localhost" || $HOST == $(hostname -f) || $HOST == $(hostname -s) || $HOST
== $IP ]]; then
+   "$bin/start-daemon.sh" "$HOST" "$SERVICE"
 else
-   echo "$HOST : $LONGNAME already running (${PID})"
+   # Ensure that the provided configuration directory is sent with the command
+   echo $($SSH $HOST "bash -c 'ACCUMULO_CONF_DIR=${ACCUMULO_CONF_DIR} $bin/start-daemon.sh
\"$HOST\" \"$SERVICE\"'")
 fi

http://git-wip-us.apache.org/repos/asf/accumulo/blob/b10c172e/assemble/bin/stop-here.sh
----------------------------------------------------------------------
diff --git a/assemble/bin/stop-here.sh b/assemble/bin/stop-here.sh
index 294f2bc..6f0aa7f 100755
--- a/assemble/bin/stop-here.sh
+++ b/assemble/bin/stop-here.sh
@@ -40,7 +40,7 @@ HOSTNAME=$(hostname -a 2> /dev/null | head -1)
 if egrep -q localhost\|127.0.0.1 "$ACCUMULO_CONF_DIR/slaves"; then
    "$bin/accumulo" admin stop localhost
 else
-   for host in "$(hostname -a 2> /dev/null) $(hostname)"; do
+   for host in "$(hostname -a 2> /dev/null)" "$(hostname)"; do
       if grep -q ${host} $ACCUMULO_CONF_DIR/slaves; then
          "${bin}/accumulo" admin stop "$host"
       fi
@@ -49,10 +49,6 @@ fi
 
 for signal in TERM KILL; do
    for svc in tserver gc master monitor tracer; do
-      PID=$(ps -ef | egrep "${ACCUMULO}" | grep "Main $svc" | grep -v grep | grep -v stop-here.sh
| awk '{print $2}' | head -1)
-      if [[ -n $PID ]]; then
-         echo "Stopping ${svc} on ${HOSTNAME} with signal ${signal}"
-         kill -s ${signal} "${PID}"
-      fi
+      $ACCUMULO_HOME/bin/stop-server.sh $HOSTNAME "$ACCUMULO_HOME/lib/accumulo-start.jar"
$svc $signal
    done
 done

http://git-wip-us.apache.org/repos/asf/accumulo/blob/b10c172e/assemble/bin/stop-server.sh
----------------------------------------------------------------------
diff --git a/assemble/bin/stop-server.sh b/assemble/bin/stop-server.sh
index 78ef783..7053ff7 100755
--- a/assemble/bin/stop-server.sh
+++ b/assemble/bin/stop-server.sh
@@ -26,6 +26,7 @@ bin=$( cd -P "$( dirname "$SOURCE" )" && pwd )
 # Stop: Resolve Script Directory
 
 . "$bin"/config.sh
+. "$bin"/config-server.sh
 
 HOST=$1
 
@@ -39,16 +40,17 @@ then
 fi
 
 # only stop if there's not one already running
+PID_FILE="${ACCUMULO_PID_DIR}/accumulo-${ACCUMULO_IDENT_STRING}-${3}.pid"
 if [[ $HOST == localhost || $HOST = "$(hostname -s)" || $HOST = "$(hostname -f)" || $HOST
= "$IP" ]] ; then
-   PID=$(ps -ef | grep "$ACCUMULO_HOME" | egrep ${2} | grep "Main ${3}" | grep -v grep |
grep -v ssh | grep -v stop-server.sh | awk {'print $2'} | head -1)
-   if [[ -n $PID ]]; then
-      echo "Stopping ${3} on $1";
-      kill -s "${4}" "${PID}" 2>/dev/null
+   if [ -f ${PID_FILE} ]; then
+      echo "Stopping $3 on $1";
+      kill -s "$4" `cat ${PID_FILE}` 2>/dev/null
+      rm -f ${PID_FILE} 2>/dev/null
    fi;
 else
-   PID=$(ssh -q -o 'ConnectTimeout 8' "$1" "ps -ef | grep \"$ACCUMULO_HOME\" |  egrep '${2}'
| grep 'Main ${3}' | grep -v grep | grep -v ssh | grep -v stop-server.sh" | awk {'print $2'}
| head -1)
-   if [[ -n $PID ]]; then
-      echo "Stopping ${3} on $1";
-      ssh -q -o 'ConnectTimeout 8' "$1" "kill -s ${4} ${PID} 2>/dev/null"
-   fi;
+   PID=$(ssh -q -o 'ConnectTimeout 8' "$1" cat "${PID_FILE}" 2>/dev/null)
+   if [[ ! -z $PID ]]; then
+      echo "Stopping $3 on $1";
+      ssh -q -o 'ConnectTimeout 8' "$1" "kill -s $4 $PID 2>/dev/null; rm -f ${PID_FILE}
2>/dev/null"
+   fi
 fi

http://git-wip-us.apache.org/repos/asf/accumulo/blob/b10c172e/assemble/bin/tup.sh
----------------------------------------------------------------------
diff --git a/assemble/bin/tup.sh b/assemble/bin/tup.sh
index d89896d..f01aa77 100755
--- a/assemble/bin/tup.sh
+++ b/assemble/bin/tup.sh
@@ -34,7 +34,7 @@ echo -n "Starting tablet servers ..."
 count=1
 for server in $(egrep -v '(^#|^\s*$)' "${SLAVES}"); do
    echo -n "."
-   ${bin}/start-server.sh $server tserver "tablet server" &
+   ${bin}/start-server.sh $server tserver &
    if (( ++count % 72 == 0 )) ;
    then
       echo

http://git-wip-us.apache.org/repos/asf/accumulo/blob/b10c172e/assemble/conf/templates/accumulo-env.sh
----------------------------------------------------------------------
diff --git a/assemble/conf/templates/accumulo-env.sh b/assemble/conf/templates/accumulo-env.sh
index 5be96c0..a8cb917 100644
--- a/assemble/conf/templates/accumulo-env.sh
+++ b/assemble/conf/templates/accumulo-env.sh
@@ -50,6 +50,7 @@ test -z "$ACCUMULO_MONITOR_OPTS" && export ACCUMULO_MONITOR_OPTS="${POLICY}
${mo
 test -z "$ACCUMULO_GC_OPTS"      && export ACCUMULO_GC_OPTS="${gcHigh_gcLow}"
 test -z "$ACCUMULO_GENERAL_OPTS" && export ACCUMULO_GENERAL_OPTS="-XX:+UseConcMarkSweepGC
-XX:CMSInitiatingOccupancyFraction=75 -Djava.net.preferIPv4Stack=true"
 test -z "$ACCUMULO_OTHER_OPTS"   && export ACCUMULO_OTHER_OPTS="${otherHigh_otherLow}"
+test -z "${ACCUMULO_PID_DIR}"    && export ACCUMULO_PID_DIR="${ACCUMULO_HOME}/run"
 # what do when the JVM runs out of heap memory
 export ACCUMULO_KILL_CMD='kill -9 %p'
 


Mime
View raw message