#!/bin/sh # # # 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. # JAVA=`type -p java` JAVA_OPTS="-Xmx20m" FLUME_NODE_CLASS="org.apache.flume.node.Application" FLUME_AVRO_CLIENT_CLASS="org.apache.flume.client.avro.AvroCLIClient" FLUME_CLASSPATH="" warn() { local msg=$1 echo "Warning: $msg" } error() { local msg=$1 local exit_code=$2 echo "Error: $msg" if [ -n "$exit_code" ] ; then exit $exit_code fi } display_help() { cat < use configs in directory --no-env,-E do not source the flume-env.sh file --classpath,-C override the classpath completely node options --data,-d store internal flume data in avro-client options --host,-H hostname to which events will be sent --port,-p port of the avro source Note that the conf directory is always included in the classpath. EOF } run_node() { local final_cp if [ -n "$opt_conf" ] ; then final_cp="$opt_conf:" fi final_cp="${final_cp}${FLUME_CLASSPATH}" [ -n "$JAVA" ] || error "Unable to find java executable. Is it in your PATH?" 1 [ -n "$FLUME_CLASSPATH" ] || error "Flume classpath is not set! Use flume-env.sh or --classpath ." 1 [ -n "$opt_conf" ] || warn "No configuration directory set! Use --conf to override." 1 FLUME_APPLICATION_CLASS=$FLUME_NODE_CLASS $JAVA $JAVA_OPTS -cp $final_cp $FLUME_APPLICATION_CLASS $* } run_avro_client() { local final_cp if [ -n "$opt_conf" ] ; then final_cp="$opt_conf:" fi final_cp="${final_cp}${FLUME_CLASSPATH}" [ -n "$JAVA" ] || error "Unable to find java executable. Is it in your PATH?" 1 [ -n "$FLUME_CLASSPATH" ] || error "Flume classpath is not set! Use flume-env.sh or --classpath ." 1 [ -n "$opt_conf" ] || warn "No configuration directory set! Use --conf to override." 1 FLUME_APPLICATION_CLASS=$FLUME_AVRO_CLIENT_CLASS $JAVA $JAVA_OPTS -cp $final_cp $FLUME_APPLICATION_CLASS $* } validate_env() { [ -z "$CLASSPATH" ] || warn "You have CLASSPATH set to $CLASSPATH - you better know what you're doing!" } opt_help= opt_no_env= opt_conf= opt_datadir= mode=$1 shift case "$mode" in help) opt_help=1 ;; node) opt_node=1 ;; avro-client) opt_avro_client=1 ;; *) error "Unknown or unspecified command '$mode'" opt_help=1 ;; esac while [ -n "$*" ] ; do arg=$1 shift case "$arg" in --no-env|-E) opt_no_env=1 ;; --conf|-c) [ -n "$1" ] || error "Option --conf requires an argument" 1 opt_conf=$1 shift ;; --classpath|-C) [ -n "$1" ] || error "Option --classpath requires an argument" 1 FLUME_CLASSPATH=$1 shift ;; --data|-d) [ -n "$1" ] || error "Option --data requires an argument" 1 opt_datadir=$1 shift ;; *) args="$args $arg" ;; esac done if [ -n "$opt_help" ] ; then display_help elif [ -n "$opt_node" ] ; then run_node $args elif [ -n "$opt_avro_client" ] ; then run_avro_client $args fi