cd ~/installsheel
vim stop.cnf
hbase->STOP->Dhbase,HMaster@stop-hbase.sh
zookeeper->STOP->zoo.cfg@zkServer.sh
hive->KILL->HiveMetaStore,HiveServer2
hadoop->STOP->NameNode,SecondaryNameNode,DataNode@stop-dfs.sh;ResourceManager,NodeManager@stop-yarn.sh
zeppelin->STOP->ZeppelinServer@zeppelin-daemon.sh
vim stopservice.sh
source /etc/profile
CNF_FILE="stop.cnf"
CNF_LINES=(`cat $CNF_FILE`)
COUNT=0
for item in ${CNF_LINES[@]}
do
((COUNT++))
item=(${item/->/ })
echo $COUNT"."${item[0]}
done
read -p '请输入选择: ' choice
if [[ $choice =~ ^[0-9]+$ ]]
then
if [ $choice -gt $COUNT -o $choice -lt 1 ]
then
echo "选择必须是1到 $COUNT 的数字"
exit 0
fi
else
echo '选择必须是数字,并在提示的范围内'
exit 0
fi
function stopSers(){
LINE=$1
LINE=(${LINE//@/ })
SERS=${LINE[0]}
SERS=${SERS//,/ }
COUNT=0
for item in $SERS
do
RST=`jps -ml|grep -w $item`
if [[ $RST ]]
then
COUNT=1
break
fi
done
if [ $COUNT -eq 1 ]
then
RST=`${LINE[1]//
echo "STOPPED"
else
echo "NONE"
fi
}
function killSers(){
LINE=$1
LINE=${LINE//,/ }
COUNT=0
for item in $LINE
do
PID=`jps -ml|grep -w $item|awk {'print $1'}`
if [[ $PID ]]
then
((COUNT++))
kill -9 $PID
fi
done
if [ $COUNT -gt 0 ]
then
echo "STOPPED"
else
echo "NONE"
fi
}
function stopByLine(){
SIGN=$1
TYPE=$2
LINE=$3
case $TYPE in
"STOP")
LINE=${LINE//;/ }
for item in $LINE
do
RST=`stopSers $item`
item=(${item//@/ })
item=${item[0]}
case $RST in
"STOPPED")
echo '服务_[_'$item'_]_停止'
;;
"NONE")
echo '没有此服务_[_'$item'_]_存在'
;;
esac
done
;;
"KILL")
RST=`killSers $LINE`
case $RST in
"STOPPED")
echo '服务_[_'$LINE'_]_停止'
;;
"NONE")
echo '没有此服务_[_'$LINE'_]_存在'
;;
esac
;;
esac
}
COUNT=0
while (( $COUNT<$choice ))
do
LINE=${CNF_LINES[$COUNT]}
LINE=(${LINE//->/ })
SIGN=${LINE[0]}
TYPE=${LINE[1]}
LINE=${LINE[2]}
RST=`stopByLine $SIGN $TYPE $LINE`
for item in $RST
do
echo ${item//_/ }
done
((COUNT++))
done
chmod u+x stopservice.sh
./stopservice.sh
|