spark 服务启停管理脚本 留存备用

B站影视 2024-12-26 17:49 1

摘要:echo "I'm Engine-Spark, starting......!"

#!/bin/bash

WORK_HOME=$(cd "$(dirname "$0")"; pwd)

cd $WORK_HOME

umask 077

INSTALL_DIR=$WORK_HOME/..

export SPARK_HOME=$INSTALL_DIR/spark

IS_HAS_SET_SPARK_HOME=$(echo $PATH | grep "$SPARK_HOME")

if [[ "$IS_HAS_SET_SPARK_HOME" == "" ]];then

export PATH="$SPARK_HOME/bin:$SPARK_HOME/bin:$PATH"

fi

source ./props.sh ./config.properties

schedule_clear_spark {

echo "schedule process clear spark function..."

while true

do

clear_spark

sleep 10000

done

}

clear_spark {

echo "clear the spark work dir......"

nohup sh clear_spark3.sh > $INSTALL_DIR/logs/clear_spark_result.log 2>&1 &

}

stop_clear{

echo "stop clear ......"

if [ -n "$(ps aux | grep 'spark' | grep 'manage.sh' | grep -v grep)" ]; then

ps -ef | grep 'spark' | grep 'manage.sh' | grep -v grep | head -n 1 |awk '{print $2}'| xargs kill -9

fi

}

start {

if [[ "${INSTALL_ROLE}" == "slave" ]] ; then

echo "I am not master, only start slave......"

$INSTALL_DIR/spark/sbin/start-slave.sh spark://${SPARK_MASTER_IP}:7077

$INSTALL_DIR/spark/sbin/start-shuffle-service.sh

#nohup sh $INSTALL_DIR/sbin/spark-standlaone-logcleaner.sh > /dev/null 2>&1 &

echo "I'm Engine-Spark, starting......!"

sleep 3

elif [[ "${INSTALL_ROLE}" == "master" ]];then

echo "I am master, only start master......"

$INSTALL_DIR/spark/sbin/start-master.sh

#$INSTALL_DIR/spark/sbin/start-history-server.sh

sleep 3

else

echo "I am single, start master and slave......"

$INSTALL_DIR/spark/sbin/start-slave.sh spark://${SPARK_MASTER_IP}:7077

$INSTALL_DIR/spark/sbin/start-shuffle-service.sh

#nohup sh $INSTALL_DIR/sbin/spark-standlaone-logcleaner.sh > /dev/null 2>&1 &

sleep 3

fi

nohup sh clear.sh $INSTALL_DIR >/dev/null 2>&1 &

}

stop {

if [[ "${INSTALL_ROLE}" == "slave" ]] ; then

echo "I am not master, only stop slave......"

$INSTALL_DIR/spark/sbin/stop-slave.sh spark://${SPARK_MASTER_IP}:7077

$INSTALL_DIR/spark/sbin/stop-shuffle-service.sh

echo "I'm Engine-Spark,stopping......!"

sleep 3

elif [[ "${INSTALL_ROLE}" == "master" ]] ; then

echo "I am master, stop master......"

$INSTALL_DIR/spark/sbin/stop-master.sh

$INSTALL_DIR/spark/sbin/stop-history-server.sh

sleep 3

else

echo "I am master, stop master and slave......"

sleep 3

fi

sleep 3

echo "Stop the Spark Master And Worker......"

if [ -n "$(ps aux | grep spark | grep master.Master | grep cp | grep -v grep)" ]; then

ps -ef |grep spark | grep master.Master | grep cp| grep -v grep|awk '{print $2}'| xargs kill -9

fi

if [ -n "$(ps aux | grep spark | grep worker.Worker | grep cp | grep -v grep)" ]; then

ps -ef |grep spark | grep worker.Worker | grep cp| grep -v grep|awk '{print $2}'| xargs kill -9

fi

if [ -n "$(ps aux | grep spark | grep ExternalShuffleService | grep cp | grep -v grep)" ]; then

ps -ef |grep spark | grep ExternalShuffleService | grep cp| grep -v grep|awk '{print $2}'| xargs kill -9

fi

if [ -n "$(ps aux | grep spark | grep org.apache.spark.deploy.history.HistoryServer | grep cp | grep -v grep)" ]; then

ps -ef |grep spark | grep org.apache.spark.deploy.history.HistoryServer | grep cp| grep -v grep|awk '{print $2}'| xargs kill -9

fi

if [ -n "$(ps aux | grep spark-standlaone-logcleaner | grep -v grep)" ]; then

ps -ef | grep spark-standlaone-logcleaner | grep -v grep|awk '{print $2}'| xargs kill -9

fi

if [ -n "$(ps aux | grep 'clear.sh' | grep -v grep)" ]; then

ps -ef | grep 'clear.sh' | grep -v grep|awk '{print $2}'| xargs kill -9

fi

echo "I'm stoped!"

}

status {

#echo "checking status"

if [[ "${INSTALL_ROLE}" == "slave" ]] ; then

#echo "I am not master, only status slave......"

if [ -n "$(ps aux | grep worker.Worker |grep -v grep)" ]; then

exit 0

else

exit 1

fi

else

#echo "I am master, status master and slave......"

if [ -n "$(ps aux | grep master.Master |grep -v grep)" ]; then

exit 0

else

exit 1

fi

fi

}

case "$1" in

'start')

start

;;

'stop')

stop

;;

'restart')

stop

start

;;

'status')

status

;;

*)

echo "Usage: $0 {start|stop|restart|status|info}"

exit 1

esac

来源:凯哥聊科技

相关推荐