#!/bin/bash
#
# We use the jobtracker as provisioning server
#
# Correct start order (reverse to obtain the stop order):
#
# • HDFS
# • MapReduce
# • Zookeeper
# • HBase
# (• Hive Metastore )
# (• Hue )
# (• Oozie)
# • Ganglia
# • Nagios
#
HOSTNAME=$( hostname -f )
DOMAIN_N="t.hadoop.research-infrastructures.eu"
SERVICES_START_ORDER="service-global-zookeeper service-global-hdfs service-global-mapred service-global-hbase"
SERVICES_STOP_ORDER="service-global-hbase service-global-mapred service-global-hdfs service-global-zookeeper"

SH_LIB_PATH=/usr/local/lib
if [ -f $SH_LIB_PATH/service-hadoop-common-functions ] ; then
    . $SH_LIB_PATH/service-hadoop-common-functions
else
    echo "Library file: $SH_LIB_PATH/service-hadoop-common-functions is missing"
    exit 1
fi

SERVICES=$SERVICES_START_ORDER
ARG=$1

function action_loop(){
    ACTION=$ARG
    if [ "$ACTION" == "stop" ] ; then
	SERVICES=$SERVICES_STOP_ORDER
    fi
    for SRV in $SERVICES ; do 
	$SRV $ACTION
    done
}

case "$ARG" in
  start|restart|reload|force-reload|status|stop)
        action_loop
        ;;
  *)
        echo "Usage: $0 start|stop|restart|status" >&2
        exit 3
        ;;
esac

exit 0
