2016-05-10 12:00:13 -04:00
|
|
|
#!/bin/bash -eu
|
2018-09-18 11:39:26 -04:00
|
|
|
# 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.
|
2016-05-10 12:00:13 -04:00
|
|
|
|
2016-06-24 18:02:34 -04:00
|
|
|
## Initialization script for druid nodes
|
|
|
|
## Runs druid nodes as a daemon
|
|
|
|
## Environment Variables used by this script -
|
|
|
|
## DRUID_LIB_DIR - directory having druid jar files, default=lib
|
|
|
|
## DRUID_CONF_DIR - directory having druid config files, default=conf/druid
|
|
|
|
## DRUID_LOG_DIR - directory used to store druid logs, default=log
|
|
|
|
## DRUID_PID_DIR - directory used to store pid files, default=var/druid/pids
|
2016-12-16 14:19:15 -05:00
|
|
|
## HADOOP_CONF_DIR - directory used to store hadoop config files
|
2016-05-10 12:00:13 -04:00
|
|
|
|
2016-06-24 18:02:34 -04:00
|
|
|
usage="Usage: node.sh nodeType (start|stop|status)"
|
2016-05-10 12:00:13 -04:00
|
|
|
|
|
|
|
if [ $# -le 1 ]; then
|
|
|
|
echo $usage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
nodeType=$1
|
|
|
|
shift
|
|
|
|
|
2016-06-24 18:02:34 -04:00
|
|
|
command=$1
|
2016-05-10 12:00:13 -04:00
|
|
|
|
2016-06-24 18:02:34 -04:00
|
|
|
LIB_DIR="${DRUID_LIB_DIR:=lib}"
|
|
|
|
CONF_DIR="${DRUID_CONF_DIR:=conf/druid}"
|
|
|
|
PID_DIR="${DRUID_PID_DIR:=var/druid/pids}"
|
2019-12-13 00:36:00 -05:00
|
|
|
WHEREAMI="$(dirname "$0")"
|
|
|
|
WHEREAMI="$(cd "$WHEREAMI" && pwd)"
|
|
|
|
JAVA_BIN_DIR="$(source "$WHEREAMI"/java-util && get_java_bin_dir)"
|
2016-06-24 18:02:34 -04:00
|
|
|
|
2021-12-03 08:32:01 -05:00
|
|
|
# Remove possilble ending slash
|
|
|
|
LOG_DIR="${DRUID_LOG_DIR:=${WHEREAMI}/log}"
|
|
|
|
if [[ $LOG_DIR == */ ]];
|
|
|
|
then
|
|
|
|
LOG_DIR=${LOG_DIR%?}
|
|
|
|
fi
|
|
|
|
|
2016-06-24 18:02:34 -04:00
|
|
|
pid=$PID_DIR/$nodeType.pid
|
|
|
|
|
|
|
|
case $command in
|
2016-05-10 12:00:13 -04:00
|
|
|
|
|
|
|
(start)
|
|
|
|
|
|
|
|
if [ -f $pid ]; then
|
|
|
|
if kill -0 `cat $pid` > /dev/null 2>&1; then
|
|
|
|
echo $nodeType node running as process `cat $pid`. Stop it first.
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
2017-01-02 12:20:22 -05:00
|
|
|
if [ ! -d "$PID_DIR" ]; then mkdir -p $PID_DIR; fi
|
|
|
|
if [ ! -d "$LOG_DIR" ]; then mkdir -p $LOG_DIR; fi
|
2017-12-20 22:38:09 -05:00
|
|
|
|
2019-12-13 00:36:00 -05:00
|
|
|
if [ -z "$JAVA_BIN_DIR" ]; then
|
|
|
|
echo "Could not find java - please run $WHEREAMI/verify-java to confirm it is installed."
|
|
|
|
exit 1
|
2017-12-20 22:38:09 -05:00
|
|
|
fi
|
2019-12-13 00:36:00 -05:00
|
|
|
JAVA="$JAVA_BIN_DIR/java"
|
2017-12-20 22:38:09 -05:00
|
|
|
|
2021-12-03 08:32:01 -05:00
|
|
|
nohup $JAVA -Ddruid.node.type=$nodeType "-Ddruid.log.path=$LOG_DIR" `cat $CONF_DIR/$nodeType/jvm.config | xargs` -cp $CONF_DIR/_common:$CONF_DIR/$nodeType:$LIB_DIR/*:$HADOOP_CONF_DIR org.apache.druid.cli.Main server $nodeType >> /dev/null 2>&1 &
|
2016-05-10 12:00:13 -04:00
|
|
|
nodeType_PID=$!
|
|
|
|
echo $nodeType_PID > $pid
|
2021-12-03 08:32:01 -05:00
|
|
|
echo "Started $nodeType node, pid: $nodeType_PID"
|
|
|
|
echo "Logging to default file[$LOG_DIR/$nodeType.log] if no changes made to log4j2.xml"
|
2016-05-10 12:00:13 -04:00
|
|
|
;;
|
|
|
|
|
|
|
|
(stop)
|
|
|
|
|
|
|
|
if [ -f $pid ]; then
|
|
|
|
TARGET_PID=`cat $pid`
|
|
|
|
if kill -0 $TARGET_PID > /dev/null 2>&1; then
|
|
|
|
echo Stopping process `cat $pid`...
|
|
|
|
kill $TARGET_PID
|
|
|
|
else
|
|
|
|
echo No $nodeType node to stop
|
|
|
|
fi
|
|
|
|
rm -f $pid
|
|
|
|
else
|
|
|
|
echo No $nodeType node to stop
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
|
2016-06-24 18:02:34 -04:00
|
|
|
(status)
|
|
|
|
if [ -f $pid ]; then
|
|
|
|
if kill -0 `cat $pid` > /dev/null 2>&1; then
|
|
|
|
echo RUNNING
|
|
|
|
exit 0
|
|
|
|
else
|
|
|
|
echo STOPPED
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo STOPPED
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
|
2016-05-10 12:00:13 -04:00
|
|
|
(*)
|
|
|
|
echo $usage
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|