Skip to content

Commit

Permalink
Solve #761, Refine boot scripts and provide standalone script for dat…
Browse files Browse the repository at this point in the history
…abase formatting
  • Loading branch information
littlezhou committed Jul 21, 2017
1 parent 0733749 commit 4980038
Show file tree
Hide file tree
Showing 5 changed files with 288 additions and 91 deletions.
52 changes: 44 additions & 8 deletions bin/common.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
Expand Down Expand Up @@ -143,17 +143,16 @@ function start_smart_server() {

if [[ "${SMART_VARGS}" =~ " -format" ]]; then
echo "Start formatting database ..."
exec $SMART_RUNNER $JAVA_OPTS -cp "${SMART_CLASSPATH}" $SMART_SERVER $SMART_VARGS
exit $?
exec $SMART_RUNNER $JAVA_OPTS -cp "${SMART_CLASSPATH}" $SMART_CLASSNAME $SMART_VARGS
fi

echo "Starting SmartServer ..."
ssh ${SSH_OPTIONS} ${servers} "cd ${SMART_HOME}; ${SMART_HOME}/bin/start-smart.sh ${SMART_VARGS} --daemon"
echo "Starting SmartServer ..."
smart_start_daemon ${SMART_PID_FILE}
}

function stop_smart_server() {
local servers=localhost
ssh ${SSH_OPTIONS} ${servers} "cd ${SMART_HOME}; ${SMART_HOME}/bin/stop-smart.sh --daemon"
smart_stop_daemon ${SMART_PID_FILE}
}

function smart_start_daemon() {
Expand Down Expand Up @@ -201,7 +200,7 @@ function start_daemon() {
echo "ERROR: Can NOT write PID file ${pidfile}."
fi

exec $SMART_RUNNER $JAVA_OPTS -cp "${SMART_CLASSPATH}" $SMART_SERVER $SMART_VARGS
exec $SMART_RUNNER $JAVA_OPTS -cp "${SMART_CLASSPATH}" $SMART_CLASSNAME $SMART_VARGS
}

function smart_stop_daemon() {
Expand Down Expand Up @@ -238,4 +237,41 @@ function smart_stop_daemon() {
else
echo "Service not found on node '${HOSTNAME}'"
fi
}
}

function init_command() {
local subcmd=$1
shift

case ${subcmd} in
formatdatabase)
SMART_CLASSNAME=org.smartdata.server.SmartDaemon
SMART_PID_FILE=/tmp/SmartServer.pid
ALLOW_DAEMON_OPT=true
SMART_VARGS+=" -format"
;;
smartserver)
SMART_CLASSNAME=org.smartdata.server.SmartDaemon
SMART_PID_FILE=/tmp/SmartServer.pid
ALLOW_DAEMON_OPT=true
;;
getconf)
SMART_CLASSNAME=org.smartdata.server.utils.tools.GetConf
;;
*)
echo "Unkown command ${subcmd}"
exit 1;
;;
esac
}

function remote_execute() {
local host=$1
shift

ssh ${SSH_OPTIONS} ${host} "$@"
}

function local_execute() {
exec $SMART_RUNNER $JAVA_OPTS -cp "${SMART_CLASSPATH}" $SMART_CLASSNAME $SMART_VARGS
}
60 changes: 60 additions & 0 deletions bin/format-database.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/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.
#

bin=$(dirname "${BASH_SOURCE-$0}")
bin=$(cd "${bin}">/dev/null; pwd)
HOSTNAME=$(hostname)

SMART_VARGS=
while [ $# != 0 ]; do
case "$1" in
"--config")
shift
conf_dir="$1"
if [[ ! -d "${conf_dir}" ]]; then
echo "ERROR : ${conf_dir} is not a directory"
echo ${USAGE}
exit 1
else
export SMART_CONF_DIR="${conf_dir}"
echo "SMART_CONF_DIR="$SMART_CONF_DIR
fi
shift
;;
*)
SMART_VARGS+=" $1"
shift
;;
esac
done

. "${bin}/common.sh"

#---------------------------------------------------------
#

echo -n "Start formatting database ... "

$("${SMART_HOME}/bin/smart" --config "${SMART_CONF_DIR}" formatdatabase 2>/dev/null)

if [ x"$?" = x"0" ]; then
echo "[Success]"
else
echo "[Failed]"
fi
146 changes: 146 additions & 0 deletions bin/smart
Original file line number Diff line number Diff line change
@@ -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="smart --config <config dir> [--daemon] [--hosts <hostA> <hostB> --hostsend] [--daemon start|stop ] [--remote] <command> <command args>"

SCRIPT_ARGS="$*"

bin=$(dirname "${BASH_SOURCE-$0}")
bin=$(cd "${bin}">/dev/null; pwd)
HOSTNAME=$(hostname)

REMOTE_COMMAND=
DAEMON_MOD=
DAEMON_MOD_OP=
REMOTE_MODE=
SMART_VARGS=
while [ $# != 0 ]; do
case "$1" in
"--config")
shift
conf_dir="$1"
if [[ ! -d "${conf_dir}" ]]; then
echo "ERROR : ${conf_dir} is not a directory"
echo ${USAGE}
exit 1
else
export SMART_CONF_DIR="${conf_dir}"
fi
REMOTE_COMMAND+=" --config $1"
shift
;;
"--debug")
JAVA_OPTS+=" -Xdebug -Xrunjdwp:transport=dt_socket,address=8008,server=y,suspend=y"
REMOTE_COMMAND+=" $1"
shift
;;
"--daemon")
REMOTE_COMMAND+=" $1 $2"
DAEMON_MOD=true
shift
DAEMON_MOD_OP=$1
shift
;;
"--remote")
REMOTE_MODE=true
shift
;;
"--hosts")
SMART_HOSTS=
shift
while [ x"$1" != x"--hostsend" ]; do
SMART_HOSTS+=" $1"
shift
done
shift
;;
*)
break;
;;
esac
done

REMOTE_COMMAND+=" $@"
COMMAND=$1
shift
SMART_VARGS="$@"

. "${bin}/common.sh"

init_command ${COMMAND}

JAVA_OPTS+=" -Dsmart.log.dir=${SMART_LOG_DIR}"
JAVA_OPTS+=" -Dsmart.log.file=SmartServer.log"

JAVA_VERSION=$($SMART_RUNNER -version 2>&1 | awk -F '.' '/version/ {print $2}')

if [[ "$JAVA_VERSION" -ge 8 ]]; then
JAVA_OPTS+=" -XX:MaxMetaspaceSize=256m"
else
JAVA_OPTS+=" -XX:MaxPermSize=256m"
fi

addJarInDir "${SMART_HOME}/smart-server/target/lib"
addNonTestJarInDir "${SMART_HOME}/smart-server/target"
addJarInDir "${SMART_HOME}/lib"

if [ "$SMART_CLASSPATH" = "" ]; then
SMART_CLASSPATH="${SMART_CONF_DIR}"
else
SMART_CLASSPATH="${SMART_CONF_DIR}:${SMART_CLASSPATH}"
fi

if [[ ! -d "${SMART_LOG_DIR}" ]]; then
$(mkdir -p "${SMART_LOG_DIR}")
fi

SMART_VARGS+=" -D smart.conf.dir="${SMART_CONF_DIR}
SMART_VARGS+=" -D smart.log.dir="${SMART_LOG_DIR}


#echo "$SMART_RUNNER $JAVA_OPTS -cp ${SMART_CLASSPATH} ${SMART_CLASSNAME} $@"

#exec $SMART_RUNNER $JAVA_OPTS -cp "${SMART_CLASSPATH}" ${SMART_CLASSNAME} $@

if [ x"${REMOTE_MODE}" = x"true" ]; then
for host in $SMART_HOSTS
do
echo "Processing on '${host}' ... "
remote_execute ${host} ${SMART_HOME}/bin/smart ${REMOTE_COMMAND}
if [ "$?" = "0" ]; then
echo "Processing on '${host}' completed successfully."
else
echo "ERROR: Processing on '${host}' failed."
fi
done
else
if [ x"${DAEMON_MOD}" = x"true" ]; then
case "${DAEMON_MOD_OP}" in
"start")
smart_start_daemon ${SMART_PID_FILE}
;;
"stop")
smart_stop_daemon ${SMART_PID_FILE}
;;
esac
else
local_execute
fi
fi
exit $?
63 changes: 19 additions & 44 deletions bin/start-smart.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
Expand All @@ -16,17 +16,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Run SmartServer
#
#./bin/start-smart.sh -D smart.dfs.namenode.rpcserver=hdfs://localhost:9000
#./bin/start-smart.sh -D smart.dfs.namenode.rpcserver=hdfs://localhost:9000 -D smart.metastore.db.url=jdbc:sqlite:file-sql.db

USAGE="Usage: bin/start-smart.sh [--config <conf-dir>] [--debug] ..."

bin=$(dirname "${BASH_SOURCE-$0}")
bin=$(cd "${bin}">/dev/null; pwd)
HOSTNAME=$(hostname)

DAEMON_MOD=
SMART_VARGS=
while [ $# != 0 ]; do
case "$1" in
Expand All @@ -44,11 +38,7 @@ while [ $# != 0 ]; do
shift
;;
"--debug")
JAVA_OPTS+=" -Xdebug -Xrunjdwp:transport=dt_socket,address=8008,server=y,suspend=y"
shift
;;
"--daemon")
DAEMON_MOD=1
DEBUG_OPT=$1
shift
;;
*)
Expand All @@ -60,41 +50,26 @@ done

. "${bin}/common.sh"

#---------------------------------------------------------
# Start Smart Servers

HOSTNAME=$(hostname)

SMART_SERVER=org.smartdata.server.SmartDaemon
JAVA_OPTS+=" -Dsmart.log.dir=${SMART_LOG_DIR}"
JAVA_OPTS+=" -Dsmart.log.file=SmartServer.log"

JAVA_VERSION=$($SMART_RUNNER -version 2>&1 | awk -F '.' '/version/ {print $2}')
SMARTSERVERS=$("${SMART_HOME}/bin/smart" getconf SmartServers 2>/dev/null)

if [[ "$JAVA_VERSION" -ge 8 ]]; then
JAVA_OPTS+=" -XX:MaxMetaspaceSize=256m"
else
JAVA_OPTS+=" -XX:MaxPermSize=256m"
if [ "$?" != "0" ]; then
echo "${SMARTSERVERS}"
exit 1
fi

addJarInDir "${SMART_HOME}/smart-server/target/lib"
addNonTestJarInDir "${SMART_HOME}/smart-server/target"
addJarInDir "${SMART_HOME}/lib"

if [ "$SMART_CLASSPATH" = "" ]; then
SMART_CLASSPATH="${SMART_CONF_DIR}"
else
SMART_CLASSPATH="${SMART_CONF_DIR}:${SMART_CLASSPATH}"
fi
#if [[ -z "${SMARTSERVERS}" ]]; then
#SMARTSERVERS=$HOSTNAME
#fi

if [[ ! -d "${SMART_LOG_DIR}" ]]; then
echo "Log dir doesn't exist, create ${SMART_LOG_DIR}"
$(mkdir -p "${SMART_LOG_DIR}")
fi
echo "Starting SmartServers on [${SMARTSERVERS}]"

SMART_VARGS+=" -D smart.conf.dir="${SMART_CONF_DIR}
SMART_VARGS+=" -D smart.log.dir="${SMART_LOG_DIR}
. "${SMART_HOME}/bin/smart" \
--remote \
--config "${SMART_CONF_DIR}" \
--hosts "${SMARTSERVERS}" --hostsend \
--daemon start ${DEBUG_OPT} \
smartserver

if [ -z "$DAEMON_MOD" ]; then
start_smart_server
else
smart_start_daemon ${SMART_SERVER_PID_FILE}
fi
Loading

0 comments on commit 4980038

Please sign in to comment.