diff --git bin/ext/hiveserver2.sh bin/ext/hiveserver2.sh index 45d7893..521f746 100644 --- bin/ext/hiveserver2.sh +++ bin/ext/hiveserver2.sh @@ -13,21 +13,117 @@ # See the License for the specific language governing permissions and # limitations under the License. +bin=`which $0` +bin=`dirname ${bin}` +bin=`cd "$bin"; pwd` +logdir=`dirname ${bin}` + + +LOG_DIR=${LOG_DIR:-"$logdir"/var/log} +PID_DIR=${PID_DIR:-$LOG_DIR} + THISSERVICE=hiveserver2 export SERVICE_LIST="${SERVICE_LIST}${THISSERVICE} " - + + hiveserver2() { - echo "Starting HiveServer2" - CLASS=org.apache.hive.service.server.HiveServer2 + + THISSERVICE=hiveserver2 + SERVER_NAME=${THISSERVICE} + SLEEP_TIME_AFTER_START=2 + JAR=${HIVE_LIB}/hive-service-*.jar + CLASS=org.apache.hive.service.server.HiveServer2 + PID_FILE=${PID_DIR}/${THISSERVICE}.pid + + echo "SERVICE_LIST: $SERVICE_LIST" + + echo "Starting ${SERVER_NAME}" if $cygwin; then HIVE_LIB=`cygpath -w "$HIVE_LIB"` fi - JAR=${HIVE_LIB}/hive-service-*.jar + + + #create if the dir not exist + if [ ! -f "${LOG_DIR}" ]; then + mkdir -p "${LOG_DIR}" + fi + + + # check if service is already running, if so exit + if [ -s "$PID_FILE" ] + then + echo "${SERVER_NAME} appears to be running. If you are SURE it is not," \ + "remove $PID_FILE and re-run this script." + exit 1 + fi + + nohup $HADOOP jar $JAR $CLASS $HIVE_OPTS "$@" >${LOG_DIR}/${THISSERVICE}.out 2>${LOG_DIR}/${THISSERVICE}.err & - exec $HADOOP jar $JAR $CLASS $HIVE_OPTS "$@" + PID=$! + + if [ "${PID}x" == "x" ] ; then # we failed right off + echo "${SERVER_NAME} startup failed:" + cat ${LOG_DIR}/${THISSERVICE}.err + cat ${LOG_DIR}/${THISSERVICE}.out + exit 1 + fi + + echo Started ${SERVER_NAME} init, testing if initialized correctly... + sleep $SLEEP_TIME_AFTER_START + + if ps -p $PID > /dev/null + then + echo $PID > $PID_FILE + echo "${SERVER_NAME} initialized successfully." + else + echo "${SERVER_NAME} startup failed:" + cat ${LOG_DIR}/${THISSERVICE}.err + cat ${LOG_DIR}/${THISSERVICE}.out + exit 1 + fi } -hiveserver2_help() { - hiveserver2 -H +stop_hiveserver2() { + + THISSERVICE=hiveserver2 + SERVER_NAME=${THISSERVICE} + SLEEP_TIME_AFTER_KILL=2 + JAR=${HIVE_LIB}/hive-service-*.jar + CLASS=org.apache.hive.service.server.HiveServer2 + PID_FILE=${PID_DIR}/${THISSERVICE}.pid + + + # check if service is already running, if so exit + if [ -s "$PID_FILE" ] ; then + echo "Stopping ${SERVER_NAME}" + PID=`cat $PID_FILE` + echo "Found ${SERVER_NAME} process $PID, killing..." + kill $PID + sleep $SLEEP_TIME_AFTER_KILL + + # if process is still around, use kill -9 + if ps -p $PID > /dev/null ; then + echo "Initial kill failed, getting serious now..." + kill -9 $PID + fi + if ps -p $PID > /dev/null ; then + echo "Wow, even kill -9 failed, giving up; sorry" + exit 1 + else + rm -rf $PID_FILE + echo "Successfully shutdown ${SERVER_NAME}" + fi + else + echo "${SERVER_NAME} appears to not be running. If you are SURE it is," \ + "someone removed $PID_FILE, and you've to manually kill the daemon, sorry" + fi } +hiveserver2_help() { + + JAR=${HIVE_LIB}/hive-service-*.jar + CLASS=org.apache.hive.service.server.HiveServer2 + + HIVE_OPTS="${HIVE_OPTS} -H" + exec $HADOOP jar $JAR $CLASS $HIVE_OPTS "$@" +} \ No newline at end of file diff --git bin/ext/metastore.sh bin/ext/metastore.sh index 22b2d5d..9c34da1 100644 --- bin/ext/metastore.sh +++ bin/ext/metastore.sh @@ -13,24 +13,119 @@ # See the License for the specific language governing permissions and # limitations under the License. + +bin=`which $0` +bin=`dirname ${bin}` +bin=`cd "$bin"; pwd` +logdir=`dirname ${bin}` + + +LOG_DIR=${LOG_DIR:-"$logdir"/var/log} +PID_DIR=${PID_DIR:-$LOG_DIR} + + THISSERVICE=metastore export SERVICE_LIST="${SERVICE_LIST}${THISSERVICE} " + metastore() { - echo "Starting Hive Metastore Server" - CLASS=org.apache.hadoop.hive.metastore.HiveMetaStore + + THISSERVICE=metastore + SERVER_NAME="hive ${THISSERVICE} server" + SLEEP_TIME_AFTER_START=2 + JAR=${HIVE_LIB}/hive-service-*.jar + CLASS=org.apache.hadoop.hive.metastore.HiveMetaStore + PID_FILE=${PID_DIR}/${THISSERVICE}.pid + + echo "Starting ${SERVER_NAME}" if $cygwin; then HIVE_LIB=`cygpath -w "$HIVE_LIB"` fi - JAR=${HIVE_LIB}/hive-service-*.jar + + + #create if the dir not exist + if [ ! -f "${LOG_DIR}" ]; then + mkdir -p "${LOG_DIR}" + fi + + # check if service is already running, if so exit + if [ -s "$PID_FILE" ] + then + echo "${SERVER_NAME} appears to be running. If you are SURE it is not," \ + "remove $PID_FILE and re-run this script." + exit 1 + fi + + + export HADOOP_OPTS="$HIVE_METASTORE_HADOOP_OPTS $HADOOP_OPTS" + nohup $HADOOP jar $JAR $CLASS "$@" >${LOG_DIR}/${THISSERVICE}.out 2>${LOG_DIR}/${THISSERVICE}.err & - # hadoop 20 or newer - skip the aux_jars option and hiveconf + PID=$! + + if [ "${PID}x" == "x" ] ; then # we failed right off + echo "${SERVER_NAME} startup failed:" + cat ${LOG_DIR}/${THISSERVICE}.err + cat ${LOG_DIR}/${THISSERVICE}.out + exit 1 + fi + + echo Started ${SERVER_NAME} init, testing if initialized correctly... + sleep $SLEEP_TIME_AFTER_START - export HADOOP_OPTS="$HIVE_METASTORE_HADOOP_OPTS $HADOOP_OPTS" - exec $HADOOP jar $JAR $CLASS "$@" + if ps -p $PID > /dev/null + then + echo $PID > $PID_FILE + echo "${SERVER_NAME} initialized successfully." + else + echo "${SERVER_NAME} startup failed:" + cat ${LOG_DIR}/${THISSERVICE}.err + cat ${LOG_DIR}/${THISSERVICE}.out + exit 1 + fi } -metastore_help() { - metastore -h + +stop_metastore() { + + THISSERVICE=metastore + SERVER_NAME="hive ${THISSERVICE} server" + SLEEP_TIME_AFTER_KILL=2 + JAR=${HIVE_LIB}/hive-service-*.jar + CLASS=org.apache.hadoop.hive.metastore.HiveMetaStore + PID_FILE=${PID_DIR}/${THISSERVICE}.pid + + # check if service is already running, if so exit + if [ -s "$PID_FILE" ] ; then + echo "Stopping ${SERVER_NAME}" + PID=`cat $PID_FILE` + echo "Found ${SERVER_NAME} process $PID, killing..." + kill $PID + sleep $SLEEP_TIME_AFTER_KILL + + # if process is still around, use kill -9 + if ps -p $PID > /dev/null ; then + echo "Initial kill failed, getting serious now..." + kill -9 $PID + fi + if ps -p $PID > /dev/null ; then + echo "Wow, even kill -9 failed, giving up; sorry" + exit 1 + else + rm -rf $PID_FILE + echo "Successfully shutdown ${SERVER_NAME}" + fi + else + echo "${SERVER_NAME} appears to not be running. If you are SURE it is," \ + "someone removed $PID_FILE, and you've to manually kill the daemon, sorry" + fi } + +metastore_help() { + + JAR=${HIVE_LIB}/hive-service-*.jar + CLASS=org.apache.hadoop.hive.metastore.HiveMetaStore + + HIVE_OPTS="${HIVE_OPTS} -h" + exec $HADOOP jar $JAR $CLASS $HIVE_OPTS "$@" +} diff --git bin/hive bin/hive index fcf38b1..4b6a530 100755 --- bin/hive +++ bin/hive @@ -27,6 +27,7 @@ bin=`cd "$bin"; pwd` SERVICE="" HELP="" +STOP="" while [ $# -gt 0 ]; do case "$1" in --version) @@ -46,10 +47,22 @@ while [ $# -gt 0 ]; do SERVICE=orcfiledump shift ;; + --stop) + STOP=stop_ + shift + ;; --help) HELP=_help shift ;; + -H) + HELP=_help + shift + ;; + -h) + HELP=_help + shift + ;; --debug*) DEBUG=$1 shift @@ -266,10 +279,17 @@ for j in $SERVICE_LIST ; do fi done + if [ "$TORUN" = "" ] ; then echo "Service $SERVICE not found" echo "Available Services: $SERVICE_LIST" exit 7 +fi + + +if [ "$STOP" != "" ] ; then + STOP=${STOP}${SERVICE} + $STOP "$@" else $TORUN "$@" fi diff --git metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java index 487d292..0ecc646 100644 --- metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java +++ metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java @@ -4993,7 +4993,13 @@ public HiveMetastoreCli() { .withDescription("Hive Metastore port number, default:" + DEFAULT_HIVE_METASTORE_PORT) .create('p')); - + + // --stop + OPTIONS.addOption(OptionBuilder + .hasArgs(0) + .withLongOpt("stop") + .withDescription("Stop service") + .create()); } @Override diff --git service/src/java/org/apache/hive/service/server/ServerOptionsProcessor.java service/src/java/org/apache/hive/service/server/ServerOptionsProcessor.java index bbb2a42..f2b2615 100644 --- service/src/java/org/apache/hive/service/server/ServerOptionsProcessor.java +++ service/src/java/org/apache/hive/service/server/ServerOptionsProcessor.java @@ -55,7 +55,13 @@ public ServerOptionsProcessor(String serverName) { .create()); options.addOption(new Option("H", "help", false, "Print help information")); - + + // --stop + options.addOption(OptionBuilder + .hasArgs(0) + .withLongOpt("stop") + .withDescription("Stop service") + .create()); } public boolean process(String[] argv) {