Repository: bigtop Updated Branches: refs/heads/master df35b212b -> acf86f8a2
Changes to support service start|stop|.. of multiple flume agents on a node BIGTOP-1581 Signed-off-by: Bruno Mahé <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/bigtop/repo Commit: http://git-wip-us.apache.org/repos/asf/bigtop/commit/acf86f8a Tree: http://git-wip-us.apache.org/repos/asf/bigtop/tree/acf86f8a Diff: http://git-wip-us.apache.org/repos/asf/bigtop/diff/acf86f8a Branch: refs/heads/master Commit: acf86f8a26e5dfc7ae313136e5d3f81fa5a4485e Parents: df35b21 Author: Biju Nair <[email protected]> Authored: Thu Jan 29 08:20:52 2015 -0500 Committer: Bruno Mahé <[email protected]> Committed: Sun May 17 15:11:14 2015 -0700 ---------------------------------------------------------------------- .../src/common/flume/flume-agent.default | 14 ++ .../src/common/flume/flume-agent.init | 133 ++++++++++++++++--- 2 files changed, 129 insertions(+), 18 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/bigtop/blob/acf86f8a/bigtop-packages/src/common/flume/flume-agent.default ---------------------------------------------------------------------- diff --git a/bigtop-packages/src/common/flume/flume-agent.default b/bigtop-packages/src/common/flume/flume-agent.default index 509a646..5e02f5b 100644 --- a/bigtop-packages/src/common/flume/flume-agent.default +++ b/bigtop-packages/src/common/flume/flume-agent.default @@ -13,6 +13,20 @@ # See the License for the specific language governing permissions and # limitations under the License. +# +# Naming convention for flume agent config file is flume-${FLUME_AGENT_NAME}.conf +# For e.g. the FLUME_AGENT_NAME in this default config file is "agent" and hence +# the config file is named flume-agent.conf. Multiple flume agents can be deployed +# on a single node by creating config files with this naming convention and storing +# it in /etc/flume/conf directory. Refer BIGTOP-1581 for details. +# +# To start|start|restart... a Flume agenti, user can issue the command +# service flume-agent start|stop|... FLUME_AGENT_NAME +# +# If FLUME_AGENT_NAME is not passed, action will be taken on all Flume agents for +# which config file is stored in /etc/flume/conf directory +# + # Set name of flume agent (default: agent) # FLUME_AGENT_NAME=agent http://git-wip-us.apache.org/repos/asf/bigtop/blob/acf86f8a/bigtop-packages/src/common/flume/flume-agent.init ---------------------------------------------------------------------- diff --git a/bigtop-packages/src/common/flume/flume-agent.init b/bigtop-packages/src/common/flume/flume-agent.init index b877434..1d041a2 100644 --- a/bigtop-packages/src/common/flume/flume-agent.init +++ b/bigtop-packages/src/common/flume/flume-agent.init @@ -66,22 +66,34 @@ for dir in "$FLUME_RUN_DIR" "$FLUME_LOCK_DIR"; do [ -d "${dir}" ] || install -d -m 0755 -o $FLUME_USER -g $FLUME_USER ${dir} done - DEFAULT_FLUME_AGENT_NAME="agent" FLUME_AGENT_NAME=${FLUME_AGENT_NAME:-${DEFAULT_FLUME_AGENT_NAME}} FLUME_SHUTDOWN_TIMEOUT=${FLUME_SHUTDOWN_TIMEOUT:-60} +# Update variables if service request is followed by a service name +# e.g. service flume-agent start|stop|status|restart service-name +# Starts a flume agent with the name flume-service-name +# Expects flume-service-name.conf file in FLUME_CONF_DIR +setvariables() { + AGENT_NAME=$1 + LOCKFILE="${FLUME_LOCK_DIR}/flume-${AGENT_NAME}" + FLUME_CONF_FILE=${FLUME_CONF_DIR}/flume-${AGENT_NAME}.conf + FLUME_PID_FILE=${FLUME_RUN_DIR}/flume-${AGENT_NAME}.pid + DEFAULT_FLUME_AGENT_NAME=${AGENT_NAME} + FLUME_AGENT_NAME=${DEFAULT_FLUME_AGENT_NAME} +} + start() { [ -x $exec ] || exit $ERROR_PROGRAM_NOT_INSTALLED checkstatus status=$? if [ "$status" -eq "$STATUS_RUNNING" ]; then - exit 0 + return 0 fi - log_success_msg "Starting $desc (flume-agent): " - /bin/su -s /bin/bash -c "/bin/bash -c 'echo \$\$ >${FLUME_PID_FILE} && exec ${EXEC_PATH} agent --conf $FLUME_CONF_DIR --conf-file $FLUME_CONF_FILE --name $FLUME_AGENT_NAME >>${FLUME_LOG_DIR}/flume-agent.out 2>&1' &" $FLUME_USER + log_success_msg "Starting $desc $FLUME_AGENT_NAME: " + /bin/su -s /bin/bash -c "/bin/bash -c 'echo \$\$ >${FLUME_PID_FILE} && exec ${EXEC_PATH} agent --conf $FLUME_CONF_DIR --conf-file $FLUME_CONF_FILE --name $FLUME_AGENT_NAME >>${FLUME_LOG_DIR}/flume-${FLUME_AGENT_NAME}.out 2>&1' &" $FLUME_USER RETVAL=$? [ $RETVAL -eq 0 ] && touch $LOCKFILE return $RETVAL @@ -89,11 +101,11 @@ start() { stop() { if [ ! -e $FLUME_PID_FILE ]; then - log_failure_msg "Flume agent is not running" - exit 0 + log_failure_msg "Flume agent $FLUME_AGENT_NAME is not running" + return 0 fi - log_success_msg "Stopping $desc (flume-agent): " + log_success_msg "Stopping $desc $FLUME_AGENT_NAME: " FLUME_PID=`cat $FLUME_PID_FILE` if [ -n $FLUME_PID ]; then @@ -119,19 +131,19 @@ checkstatus(){ case "$status" in $STATUS_RUNNING) - log_success_msg "Flume NG agent is running" + log_success_msg "Flume NG agent $FLUME_AGENT_NAME is running" ;; $STATUS_DEAD) - log_failure_msg "Flume NG agent is dead and pid file exists" + log_failure_msg "Flume NG agent $FLUME_AGENT_NAME is dead and pid file exists" ;; $STATUS_DEAD_AND_LOCK) - log_failure_msg "Flume NG agent is dead and lock file exists" + log_failure_msg "Flume NG agent $FLUME_AGENT_NAME is dead and lock file exists" ;; $STATUS_NOT_RUNNING) - log_failure_msg "Flume NG agent is not running" + log_failure_msg "Flume NG agent $FLUME_AGENT_NAME is not running" ;; *) - log_failure_msg "Flume NG agent status is unknown" + log_failure_msg "Flume NG agent $FLUME_AGENT_NAME status is unknown" ;; esac return $status @@ -141,25 +153,110 @@ condrestart(){ [ -e ${LOCKFILE} ] && restart || : } +# +# If user doesn't provide a flume agent name to start, +# will attempt to start all agents based on conf files in ${FLUME_CONF_DIR} +# +startall() { + run_functions_on_conf start +} + +# +# If user doesn't provide a flume agent name to stop, +# will attempt to stop all agents based on conf files in ${FLUME_CONF_DIR} +# +stopall() { + run_functions_on_conf stop +} + +# +# If user doesn't provide a flume agent name to restart, +# will attempt to restart all agents based on conf files in ${FLUME_CONF_DIR} +# +restartall() { + run_functions_on_conf restart +} + +# +# If user doesn't provide a flume agent name to perform cond restart, +# will attempt to do condrestart all agents based on conf files in ${FLUME_CONF_DIR} +# +condrestartall() { + run_functions_on_conf condrestart +} + +# +# If user doesn't provide a flume agent name to check the status, +# status of all agents based on conf files in ${FLUME_CONF_DIR} is checked +# +checkallstatus() { + run_functions_on_conf checkstatus +} + +# +# Common function to perform user action on all flume conf files +# +run_functions_on_conf() { + for f in ${FLUME_CONF_DIR}/* + do + file_ext=${f##*.} + if [ "$file_ext" = "conf" ]; then + conf_file=${f%.*} + file_name=${conf_file##*/} + agent_name=${file_name#*-} + echo $agent_name + setvariables $agent_name + $1 + fi + done +} + +# +# Logic to update variables if service start|stop|... is made with a flume agent name +# +if [ "$#" -eq 2 ]; then + setvariables $2 +fi + case "$1" in start) - start + if [ "$#" -eq 2 ];then + start + else + startall + fi ;; stop) - stop + if [ "$#" -eq 2 ]; then + stop + else + stopall + fi ;; status) - checkstatus + if [ "$#" -eq 2 ]; then + checkstatus + else + checkallstatus + fi ;; restart) - restart + if [ "$#" -eq 2 ]; then + restart + else + restartall + fi ;; condrestart|try-restart) - condrestart + if [ "$#" -eq 2 ]; then + condrestart + else + condrestartall + fi ;; *) echo $"Usage: $0 {start|stop|status|restart|try-restart|condrestart}" - exit 1 + RETVAL=1 esac exit $RETVAL
