| #! /usr/bin/env bash |
| #/** |
| # *(C) Copyright 2013 Hewlett-Packard Development Company, L.P. |
| # * |
| # * Licensed 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. |
| # */ |
| #/** |
| # * Copyright 2007 The Apache Software Foundation |
| # * |
| # * 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. |
| # */ |
| # |
| # The dcs command script. |
| # |
| # Environment Variables: |
| # |
| # JAVA_HOME The java implementation to use. Overrides JAVA_HOME. |
| # |
| # DCS_CLASSPATH Extra Java CLASSPATH entries. |
| # |
| # DCS_HEAPSIZE The maximum amount of heap to use, in MB. |
| # Default is 128. |
| # |
| # DCS_LIBRARY_PATH DCS additions to JAVA_LIBRARY_PATH for adding |
| # native libaries. |
| # |
| # DCS_OPTS Extra Java runtime options. |
| # |
| # DCS_CONF_DIR Alternate conf dir. Default is ${DCS_HOME}/conf. |
| # |
| # DCS_ROOT_LOGGER The root appender. Default is INFO,console |
| # |
| # |
| bin=`dirname "$0"` |
| bin=`cd "$bin">/dev/null; pwd` |
| |
| # This will set DCS_HOME, etc. |
| . "$bin"/dcs-config.sh |
| |
| cygwin=false |
| case "`uname`" in |
| CYGWIN*) cygwin=true;; |
| esac |
| |
| # Detect if we are in dcs sources dir |
| in_dev_env=false |
| if [ -d "${DCS_HOME}/target" ]; then |
| in_dev_env=true |
| fi |
| |
| # if no args specified, show usage |
| if [ $# = 0 ]; then |
| echo "Usage: dcs <command>" |
| echo "where <command> an option from one of these categories:" |
| echo "" |
| echo "DBA TOOLS" |
| echo " zkcli run the ZooKeeper shell" |
| echo "" |
| echo "PROCESS MANAGEMENT" |
| echo " master run a dcs master" |
| echo " server run a dcs server" |
| echo " zookeeper run a Zookeeper server" |
| echo " rest run a dcs REST server" |
| echo "" |
| echo "PACKAGE MANAGEMENT" |
| echo " classpath dump dcs CLASSPATH" |
| echo " version print the version" |
| echo "" |
| echo " or" |
| echo " CLASSNAME run the class named CLASSNAME" |
| echo "Most commands print help when invoked w/o parameters." |
| exit 1 |
| fi |
| |
| # get arguments |
| COMMAND=$1 |
| shift |
| |
| JAVA=$JAVA_HOME/bin/java |
| JAVA_HEAP_MAX=-Xmx128m |
| |
| MVN="mvn" |
| if [ "$MAVEN_HOME" != "" ]; then |
| MVN=${MAVEN_HOME}/bin/mvn |
| fi |
| |
| # override default settings for this command, if applicable |
| if [ -f "$DCS_HOME/conf/dcs-env-$COMMAND.sh" ]; then |
| . "$DCS_HOME/conf/dcs-env-$COMMAND.sh" |
| fi |
| |
| # check envvars which might override default args |
| if [ "$DCS_HEAPSIZE" != "" ]; then |
| #echo "run with heapsize $DCS_HEAPSIZE" |
| JAVA_HEAP_MAX="-Xmx""$DCS_HEAPSIZE""m" |
| #echo $JAVA_HEAP_MAX |
| fi |
| |
| # so that filenames w/ spaces are handled correctly in loops below |
| IFS= |
| |
| # CLASSPATH initially contains $DCS_CONF_DIR |
| CLASSPATH="${DCS_CONF_DIR}" |
| CLASSPATH=${CLASSPATH}:$JAVA_HOME/lib/tools.jar |
| |
| add_maven_deps_to_classpath() { |
| # Need to generate classpath from maven pom. This is costly so generate it |
| # and cache it. Save the file into our target dir so a mvn clean will get |
| # clean it up and force us create a new one. |
| f="${DCS_HOME}/target/cached_classpath.txt" |
| if [ ! -f "${f}" ] |
| then |
| ${MVN} -f "${DCS_HOME}/pom.xml" dependency:build-classpath -Dmdep.outputFile="${f}" &> /dev/null |
| fi |
| CLASSPATH=${CLASSPATH}:`cat "${f}"` |
| } |
| |
| add_maven_main_classes_to_classpath() { |
| if [ -d "$DCS_HOME/target/classes" ]; then |
| CLASSPATH=${CLASSPATH}:$DCS_HOME/target/classes |
| fi |
| } |
| |
| add_maven_test_classes_to_classpath() { |
| # For developers, add dcs classes to CLASSPATH |
| f="$DCS_HOME/target/test-classes" |
| if [ -d "${f}" ]; then |
| CLASSPATH=${CLASSPATH}:${f} |
| fi |
| } |
| |
| # Add maven target directory |
| if $in_dev_env; then |
| add_maven_deps_to_classpath |
| add_maven_main_classes_to_classpath |
| add_maven_test_classes_to_classpath |
| fi |
| |
| # For releases, add dcs to CLASSPATH |
| for f in $DCS_HOME/dcs*.jar; do |
| if [[ $f = *sources.jar ]] |
| then |
| : # Skip sources.jar |
| elif [ -f $f ] |
| then |
| CLASSPATH=${CLASSPATH}:$f; |
| fi |
| done |
| |
| # Add libs to CLASSPATH |
| for f in $DCS_HOME/lib/*.jar; do |
| CLASSPATH=${CLASSPATH}:$f; |
| done |
| |
| # default log directory & file |
| if [ "$DCS_LOG_DIR" = "" ]; then |
| DCS_LOG_DIR="$DCS_HOME/logs" |
| fi |
| if [ "$DCS_LOGFILE" = "" ]; then |
| DCS_LOGFILE='dcs.log' |
| fi |
| |
| # cygwin path translation |
| if $cygwin; then |
| CLASSPATH=`cygpath -p -w "$CLASSPATH"` |
| DCS_HOME=`cygpath -d "$DCS_HOME"` |
| DCS_LOG_DIR=`cygpath -d "$DCS_LOG_DIR"` |
| fi |
| |
| function append_path() { |
| if [ -z "$1" ]; then |
| echo $2 |
| else |
| echo $1:$2 |
| fi |
| } |
| |
| JAVA_PLATFORM="" |
| |
| #If avail, add Trafodion to the JAVA_LIBRARY_PATH |
| if [ "$MY_SQROOT" != "" ]; then |
| if [ -d $MY_SQROOT ]; then |
| export LD_PRELOAD=$JAVA_HOME/jre/lib/amd64/libjsig.so:$MY_SQROOT/export/lib$SQ_MBTYPE/libseabasesig.so; |
| fi |
| fi |
| |
| # Add user-specified CLASSPATH last |
| if [ "$DCS_CLASSPATH" != "" ]; then |
| CLASSPATH=${CLASSPATH}:${DCS_CLASSPATH} |
| fi |
| |
| # cygwin path translation |
| if $cygwin; then |
| JAVA_LIBRARY_PATH=`cygpath -p "$JAVA_LIBRARY_PATH"` |
| fi |
| |
| # restore ordinary behaviour |
| unset IFS |
| |
| #Set the right GC options based on the what we are running |
| declare -a client_cmds=("shell" "zkcli") |
| for cmd in $client_cmds; do |
| if [[ $cmd == $COMMAND ]]; then |
| client=true |
| break |
| fi |
| done |
| |
| if [[ $client ]]; then |
| DCS_OPTS="$DCS_OPTS $CLIENT_GC_OPTS" |
| else |
| DCS_OPTS="$DCS_OPTS $SERVER_GC_OPTS" |
| fi |
| |
| # figure out which class to run |
| if [ "$COMMAND" = "zkcli" ] ; then |
| # ZooKeeperMainServerArg returns '-server HOST:PORT' or empty string. |
| SERVER_ARG=`"$bin"/dcs --config "$DCS_CONF_DIR" org.trafodion.dcs.zookeeper.ZooKeeperMainServerArg` |
| CLASS="org.apache.zookeeper.ZooKeeperMain ${SERVER_ARG}" |
| elif [ "$COMMAND" = "master" ] ; then |
| CLASS='org.trafodion.dcs.master.DcsMaster' |
| if [ "$1" != "stop" ] ; then |
| DCS_OPTS="$DCS_OPTS $DCS_MASTER_OPTS" |
| fi |
| elif [ "$COMMAND" = "server" ] ; then |
| CLASS=`$bin/dcs --config "${DCS_CONF_DIR}" org.trafodion.dcs.util.DcsConfTool dcs.server.class.name` |
| if [ "$1" != "stop" ] ; then |
| DCS_OPTS="$DCS_OPTS $DCS_SERVER_OPTS" |
| fi |
| elif [ "$COMMAND" = "zookeeper" ] ; then |
| CLASS='org.trafodion.dcs.zookeeper.DcsQuorumPeer' |
| if [ "$1" != "stop" ] ; then |
| DCS_OPTS="$DCS_OPTS $DCS_ZOOKEEPER_OPTS" |
| fi |
| elif [ "$COMMAND" = "rest" ] ; then |
| CLASS='org.trafodion.dcs.rest.DcsRest' |
| if [ "$1" != "stop" ] ; then |
| DCS_OPTS="$DCS_OPTS $DCS_REST_OPTS" |
| fi |
| |
| elif [ "$COMMAND" = "classpath" ] ; then |
| echo $CLASSPATH |
| exit 0 |
| elif [ "$COMMAND" = "version" ] ; then |
| CLASS='org.trafodion.dcs.util.VersionInfo' |
| else |
| CLASS=$COMMAND |
| fi |
| |
| # Have JVM dump heap if we run out of memory. Files will be 'launch directory' |
| # and are named like the following: java_pid21612.hprof. Apparently it doesn't |
| # 'cost' to have this flag enabled. Its a 1.6 flag only. See: |
| # http://blogs.sun.com/alanb/entry/outofmemoryerror_looks_a_bit_better |
| DCS_OPTS="$DCS_OPTS -Ddcs.log.dir=$DCS_LOG_DIR" |
| DCS_OPTS="$DCS_OPTS -Ddcs.log.file=$DCS_LOGFILE" |
| DCS_OPTS="$DCS_OPTS -Ddcs.home.dir=$DCS_HOME" |
| DCS_OPTS="$DCS_OPTS -Ddcs.id.str=$DCS_IDENT_STRING" |
| DCS_OPTS="$DCS_OPTS -Ddcs.root.logger=${DCS_ROOT_LOGGER:-INFO,console}" |
| |
| if [ "x$JAVA_LIBRARY_PATH" != "x" ]; then |
| DCS_OPTS="$DCS_OPTS -Djava.library.path=$JAVA_LIBRARY_PATH" |
| export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$JAVA_LIBRARY_PATH" |
| fi |
| DCS_OPTS="$DCS_OPTS -Ddcs.user.program.home=$DCS_USER_PROGRAM_HOME" |
| DCS_OPTS="$DCS_OPTS -Ddcs.conf.dir=$DCS_CONF_DIR" |
| DCS_OPTS="$DCS_OPTS -Ddcs.trafodion.home=$MY_SQROOT" |
| |
| # Exec unless DCS_NOEXEC is set. |
| if [ "${DCS_NOEXEC}" != "" ]; then |
| "$JAVA" -XX:OnOutOfMemoryError="kill -9 %p" $JAVA_HEAP_MAX $DCS_OPTS -classpath "$CLASSPATH" $CLASS "$@" |
| else |
| exec "$JAVA" -XX:OnOutOfMemoryError="kill -9 %p" $JAVA_HEAP_MAX $DCS_OPTS -classpath "$CLASSPATH" $CLASS "$@" |
| fi |