blob: 32832670807235b768ebf41d87df889f82b47280 [file] [log] [blame]
#!/usr/bin/env bash
#
# The Pig command script
#
# Environment Variables
#
# JAVA_HOME The java implementation to use. Overrides JAVA_HOME.
#
# PIG_CLASSPATH Extra Java CLASSPATH entries.
#
# PIG_HEAPSIZE The maximum amount of heap to use, in MB.
# Default is 1000.
#
# PIG_OPTS Extra Java runtime options.
#
# PIG_CONF_DIR Alternate conf dir. Default is ${PIG_HOME}/conf.
#
# PIG_ROOT_LOGGER The root appender. Default is INFO,console
#
# PIG_HADOOP_VERSION Version of hadoop to run with. Default is 17 (0.17).
cygwin=false
case "`uname`" in
CYGWIN*) cygwin=true;;
esac
debug=false
# filter command line parameter
for f in $@; do
if [[ $f = "-secretDebugCmd" ]]; then
debug=true
else
remaining="${remaining} $f"
fi
done
# resolve links - $0 may be a softlink
this="$0"
while [ -h "$this" ]; do
ls=`ls -ld "$this"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '.*/.*' > /dev/null; then
this="$link"
else
this=`dirname "$this"`/"$link"
fi
done
# convert relative path to absolute path
bin=`dirname "$this"`
script=`basename "$this"`
bin=`unset CDPATH; cd "$bin"; pwd`
this="$bin/$script"
# the root of the Pig installation
export PIG_HOME=`dirname "$this"`/..
#check to see if the conf dir is given as an optional argument
if [ $# -gt 1 ]
then
if [ "--config" = "$1" ]
then
shift
confdir=$1
shift
PIG_CONF_DIR=$confdir
fi
fi
# Allow alternate conf dir location.
PIG_CONF_DIR="${PIG_CONF_DIR:-$PIG_HOME/conf}"
if [ -f "${PIG_CONF_DIR}/pig-env.sh" ]; then
. "${PIG_CONF_DIR}/pig-env.sh"
fi
# some Java parameters
if [ "$JAVA_HOME" != "" ]; then
#echo "run java in $JAVA_HOME"
JAVA_HOME=$JAVA_HOME
fi
if [ "$JAVA_HOME" = "" ]; then
echo "Error: JAVA_HOME is not set."
exit 1
fi
JAVA=$JAVA_HOME/bin/java
JAVA_HEAP_MAX=-Xmx1000m
# check envvars which might override default args
if [ "$PIG_HEAPSIZE" != "" ]; then
JAVA_HEAP_MAX="-Xmx""$PIG_HEAPSIZE""m"
fi
# CLASSPATH initially contains $PIG_CONF_DIR
CLASSPATH="${PIG_CONF_DIR}"
CLASSPATH=${CLASSPATH}:$JAVA_HOME/lib/tools.jar
# for developers, add Pig classes to CLASSPATH
if [ -d "$PIG_HOME/build/classes" ]; then
CLASSPATH=${CLASSPATH}:$PIG_HOME/build/classes
fi
if [ -d "$PIG_HOME/build/test/classes" ]; then
CLASSPATH=${CLASSPATH}:$PIG_HOME/build/test/classes
fi
# so that filenames w/ spaces are handled correctly in loops below
IFS=
# for releases, add core pig to CLASSPATH
for f in $PIG_HOME/pig-*-core.jar; do
CLASSPATH=${CLASSPATH}:$f;
done
# during development pig jar might be in build
for f in $PIG_HOME/build/pig-*-core.jar; do
CLASSPATH=${CLASSPATH}:$f;
done
# Set the version for Hadoop, default to 17
PIG_HADOOP_VERSION="${PIG_HADOOP_VERSION:-17}"
# add libs to CLASSPATH. There can be more than one version of the hadoop
# libraries in the lib dir, so don't blindly add them all. Only add the one
# that matche PIG_HADOOP_VERSION.
for f in $PIG_HOME/lib/*.jar; do
IS_HADOOP=`echo $f | grep hadoop`
if [ "${IS_HADOOP}x" == "x" ]; then
CLASSPATH=${CLASSPATH}:$f;
else
IS_RIGHT_VER=`echo $f | grep hadoop${PIG_HADOOP_VERSION}.jar`
if [ "${IS_RIGHT_VER}x" != "x" ]; then
CLASSPATH=${CLASSPATH}:$f;
fi
fi
done
# add user-specified CLASSPATH last
if [ "$PIG_CLASSPATH" != "" ]; then
CLASSPATH=${CLASSPATH}:${PIG_CLASSPATH}
fi
# default log directory & file
if [ "$PIG_LOG_DIR" = "" ]; then
PIG_LOG_DIR="$PIG_HOME/logs"
fi
if [ "$PIG_LOGFILE" = "" ]; then
PIG_LOGFILE='pig.log'
fi
# cygwin path translation
if $cygwin; then
CLASSPATH=`cygpath -p -w "$CLASSPATH"`
PIG_HOME=`cygpath -d "$PIG_HOME"`
PIG_LOG_DIR=`cygpath -d "$PIG_LOG_DIR"`
fi
# restore ordinary behaviour
unset IFS
CLASS=org.apache.pig.Main
PIG_OPTS="$PIG_OPTS -Dpig.log.dir=$PIG_LOG_DIR"
PIG_OPTS="$PIG_OPTS -Dpig.log.file=$PIG_LOGFILE"
PIG_OPTS="$PIG_OPTS -Dpig.home.dir=$PIG_HOME"
PIG_OPTS="$PIG_OPTS -Dpig.root.logger=${PIG_ROOT_LOGGER:-INFO,console,DRFA}"
# run it
if [ "$debug" == "true" ]; then
echo "dry run:"
echo "$JAVA" $JAVA_HEAP_MAX $PIG_OPTS -classpath "$CLASSPATH" $CLASS ${remaining}
echo
else
exec "$JAVA" $JAVA_HEAP_MAX $PIG_OPTS -classpath "$CLASSPATH" $CLASS ${remaining}
fi