Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- #made by Kevin Lefevre
- #propriétés du cluster
- HOSTNAME="evl2400469.eu.verio.net:7180"
- CLUSTER_NAME=SFR
- LOGIN=admin
- PASS=admin
- ES_HOME="/opt/elasticsearch-1.2.0/"
- LOG_HOME="/opt/logstash/"
- #/opt/logstash/bin/logstash agent -f /etc/logstash/conf.d/logstash.conf
- LOG_CONF="/etc/logstash/conf.d/logstash.conf"
- #Version de Cloudera Manager:
- #Cloudera Manager 5.0
- CV="v6"
- #Cloudera Manager 4.8
- #CV="v5"
- #liste des services (dans l'ordre de démarrage)
- #LIST="ZOOKEEPER HDFS SOLR SPARK HBASE KS_INDEXER YARN HIVE IMPALA OOZIE SQOOP HUE"
- LIST=$@
- ALL=0
- #Specific Cloudera 5.0: Spark
- ZOOKEEPER=0
- HDFS=0
- SOLR=0
- SPARK=0
- HBASE=0
- KS_INDEXER=0
- #MAPREDUCE=0
- YARN=0
- OOZIE=0
- SQOOP=0
- #FLUME=0
- HIVE=0
- IMPALA=0
- HUE=0
- START=0
- STOP=0
- PARAM=""
- function start_elasticsearch()
- {
- if [ -f es.pid ]; then
- ES_PID=$(read es.pid)
- echo "Elasticsearch already started with PID: $ES_PID"
- else
- nohup $ES_HOME/bin/elasticsearch &
- ES_PID=$!
- echo $ES_PID >> es.pid
- echo "Starting Elasticsearch with PID: $ES_PID"
- fi
- }
- function stop_elasticsearch()
- {
- if [ -f es.pid ]; then
- while read ES_PID; do
- echo "Stopping Elasticsearch with PID: $ES_PID"
- kill -9 $ES_PID || echo "could not kill Elasticsearch"
- done < es.pid
- rm -rf es.pid
- else
- echo "Elasticsearch is not started"
- fi
- }
- function start_logstash()
- {
- if [ -f ls.pid ]; then
- LS_PID=$(read ls.pid)
- echo "Logstash agent already started with PID: $LS_PID"
- else
- nohup $LOG_HOME/bin/logstash agent -f $LOG_CONF &
- LS_PID=$!
- echo $LS_PID >> ls.pid
- echo "Starting Logstash agent with PID: $LS_PID"
- fi
- }
- function stop_logstash()
- {
- if [ -f ls.pid ]; then
- while read LS_PID; do
- echo "Stopping Logstash agent with PID: $LS_PID"
- kill -9 $LS_PID || "could not kill Logstash agent."
- done < ls.pid
- else
- echo "Logstash agent is not started"
- fi
- }
- function check_args()
- {
- for service in $LIST; do
- case "$service" in
- "all")
- ALL=1
- ;;
- "elk")
- if [ $STOP -eq 1 ]; then
- stop_elasticsearch
- stop_logstash
- fi
- if [ $START -eq 1 ]; then
- start_elasticsearch
- start_logstash
- fi
- ;;
- "zookeeper")
- ZOOKEEPER=1
- if [ $STOP -eq 1 ]; then
- HUE=1
- SOLR=1
- HDFS=1
- YARN=1
- HIVE=1
- OOZIE=1
- fi
- ;;
- "hdfs")
- HDFS=1
- if [ $STOP -eq 1 ]; then
- IMPALA=1
- SPARK=1
- SOLR=1
- HBASE=1
- YARN=1
- fi
- if [ $START -eq 1 ]; then
- ZOOKEEPER=1
- fi
- ;;
- "solr")
- SOLR=1
- if [ $STOP -eq 1 ]; then
- HUE=1
- KS_INDEXER=1
- fi
- if [ $START -eq 1 ]; then
- HDFS=1
- ZOOKEEPER=1
- KS_INDEXER=1
- fi
- ;;
- "spark")
- SPARK=1
- if [ $START -eq 1 ]; then
- HDFS=1
- ZOOKEEPER=1
- fi
- ;;
- "yarn")
- YARN=1
- if [ $START -eq 1 ]; then
- HDFS=1
- ZOOKEEPER=1
- fi
- ;;
- # "mapreduce")
- # MAPREDUCE=1
- # if [ $START -eq 1 ]; then
- # HDFS=1
- # ZOOKEEPER=1
- # fi
- # ;;
- "ks_indexer")
- KS_INDEXER=1
- if [ $START -eq 1 ]; then
- SOLR=1
- HBASE=1
- HDFS=1
- ZOOKEEPER=1
- fi
- ;;
- "hbase")
- HBASE=1
- if [ $STOP -eq 1 ]; then
- HUE=1
- IMPALA=1
- KS_INDEXER=1
- fi
- if [ $START -eq 1 ]; then
- HDFS=1
- ZOOKEEPER=1
- KS_INDEXER=1
- fi
- ;;
- "hive")
- HIVE=1
- if [ $STOP -eq 1 ]; then
- HUE=1
- IMPALA=1
- fi
- if [ $START -eq 1 ]; then
- ZOOKEEPER=1
- fi
- ;;
- "impala")
- IMPALA=1
- if [ $START -eq 1 ]; then
- HDFS=1
- ZOOKEEPER=1
- HBASE=1
- fi
- ;;
- "oozie")
- OOZIE=1
- if [ $STOP -eq 1 ]; then
- HUE=1
- fi
- ;;
- "sqoop")
- SQOOP=1
- if [ $STOP -eq 1 ]; then
- HUE=1
- fi
- ;;
- # "flume")
- # FLUME=1
- # if [ $START -eq 1 ]; then
- # fi
- # ;;
- "hue")
- HUE=1
- if [ $START -eq 1 ]; then
- ZOOKEEPER=1
- HBASE=1
- HIVE=1
- HDFS=1
- OOZIE=1
- YARN=1
- SQOOP=1
- SOLR=1
- IMPALA=1
- fi
- ;;
- esac
- done
- }
- function if_command ()
- {
- STRING="{\n\t\"items\" : [ ] }\n"
- RES=$(curl -sX GET -u "$LOGIN:$PASS" "http://""$HOSTNAME"/api/$CV/clusters/$CLUSTER_NAME/commands)
- sleep 1000
- if [ "$STRING"="$RES" ]; then
- return 1
- else
- return 0
- fi
- }
- function wait_command ()
- {
- echo "Waiting "
- while if_command;do
- echo -n "."
- sleep 2000
- done
- echo ""
- }
- function start()
- {
- START=1
- check_args
- if [ $ALL -eq 1 ]; then
- PARAM="/api/$CV/clusters/$CLUSTER_NAME/commands/start"
- echo "starting all services"
- curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
- fi
- if [ $ZOOKEEPER -eq 1 ]; then
- wait_command
- PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/zookeeper/commands/start"
- echo "starting Zookeeper"
- curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
- fi
- if [ $HDFS -eq 1 ]; then
- wait_command
- PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/hdfs/commands/start"
- echo "starting HDFS"
- curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
- fi
- if [ $SOLR -eq 1 ]; then
- wait_command
- PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/solr/commands/start"
- echo "starting SolR"
- curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
- fi
- if [ $HBASE -eq 1 ]; then
- wait_command
- PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/hbase/commands/start"
- echo "starting HBase"
- curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
- fi
- if [ $KS_INDEXER -eq 1 ]; then
- wait_command
- PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/ks_indexer/commands/start"
- echo "starting ks_indexer"
- curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
- fi
- if [ $YARN -eq 1 ]; then
- wait_command
- PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/yarn/commands/start"
- echo "starting YARN"
- curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
- fi
- #
- # if [ $MAPREDUCE -eq 1 ]; then
- #wait_command
- # PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/mapreduce/commands/start"
- # echo "starting MapReduce"
- # curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
- # fi
- if [ $SPARK -eq 1 ]; then
- wait_command
- PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/spark/commands/start"
- echo "starting Spark"
- curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
- fi
- if [ $SQOOP -eq 1 ]; then
- wait_command
- PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/sqoop/commands/start"
- echo "starting Sqoop"
- curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
- fi
- if [ $OOZIE -eq 1 ]; then
- wait_command
- PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/oozie/commands/start"
- echo "starting Oozie"
- curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
- fi
- #
- # if [ $FLUME -eq 1 ]; then
- #wait_command
- # PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/flume/commands/start"
- # echo "starting Flume"
- # curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
- # fi
- if [ $HIVE -eq 1 ]; then
- wait_command
- PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/hive/commands/start"
- echo "starting Hive"
- curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
- fi
- if [ $IMPALA -eq 1 ]; then
- wait_command
- PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/impala/commands/start"
- echo "starting Impala"
- curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
- fi
- if [ $HUE -eq 1 ]; then
- wait_command
- PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/hue/commands/start"
- echo "starting HUE"
- curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
- fi
- }
- function stop()
- {
- STOP=1
- check_args
- if [ $ALL -eq 1 ]; then
- wait_command
- PARAM="/api/$CV/clusters/$CLUSTER_NAME/commands/stop"
- echo "stopping all services"
- curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
- fi
- if [ $HUE -eq 1 ]; then
- wait_command
- PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/hue/commands/stop"
- echo "stopping HUE"
- curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
- fi
- if [ $SQOOP -eq 1 ]; then
- wait_command
- PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/sqoop/commands/stop"
- echo "stopping Sqoop"
- curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
- fi
- if [ $OOZIE -eq 1 ]; then
- wait_command
- PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/oozie/commands/stop"
- echo "stopping Oozie"
- curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
- fi
- if [ $IMPALA -eq 1 ]; then
- wait_command
- PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/impala/commands/stop"
- echo "stopping Impala"
- curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
- fi
- if [ $SPARK -eq 1 ]; then
- wait_command
- PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/spark/commands/stop"
- echo "stopping Spark"
- curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
- fi
- if [ $HIVE -eq 1 ]; then
- wait_command
- PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/hive/commands/stop"
- echo "stopping Hive"
- curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
- fi
- #
- # if [ $FLUME -eq 1 ]; then
- #wait_command
- # PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/flume/commands/stop"
- # echo "stopping Flume"
- # curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
- # fi
- if [ $YARN -eq 1 ]; then
- wait_command
- PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/yarn/commands/stop"
- echo "stopping YARN"
- curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
- fi
- #
- # if [ $MAPREDUCE -eq 1 ]; then
- #wait_command
- # PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/mapreduce/commands/stop"
- # echo "stopping MapReduce"
- # curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
- # fi
- if [ $KS_INDEXER -eq 1 ]; then
- wait_command
- PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/ks_indexer/commands/stop"
- echo "stopping ks_indexer"
- curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
- fi
- if [ $HBASE -eq 1 ]; then
- wait_command
- PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/hbase/commands/stop"
- echo "stopping HBase"
- curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
- fi
- if [ $SOLR -eq 1 ]; then
- wait_command
- PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/solr/commands/stop"
- echo "stopping SolR"
- curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
- fi
- if [ $HDFS -eq 1 ]; then
- wait_command
- PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/hdfs/commands/stop"
- echo "stopping HDFS"
- curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
- fi
- if [ $ZOOKEEPER -eq 1 ]; then
- wait_command
- PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/zookeeper/commands/stop"
- echo "stopping Zookeeper"
- curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
- fi
- }
- function restart ()
- {
- stop
- wait_command
- start
- }
- function usage()
- {
- echo "Usage: $0 (start|stop|restart) (all|services) (elk)"
- echo "Example: \"\$ $0 start all\" \"\$ $0 stop hbase\" \"\$ $0 restart elk\""
- }
- if [ $# -eq 0 ]; then
- usage
- exit 1
- fi
- case "$1" in
- "start")
- start
- ;;
- "stop")
- stop
- ;;
- "restart")
- restart
- ;;
- *)
- usage
- exit 1
- ;;
- esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement