1. 问题描述
yarn 中mapreduce任务一直在NEW_SAVING状态hold不动,导致后续任务不能正常秩序。
2.脚本内容
现写如下脚本,达到定时监控并处理
oo.sh
#!/bin/bash
if [[ ! -s /usr/local/job_env/shell/NEW_SAVING.txt ]]; then
echo -e `yarn application -list -appStates NEW_SAVING |grep application_ |grep -v yarn-ats |awk '{print $1}' >/usr/local/job_env/shell/NEW_SAVING.txt`
else
appids=$(cat /usr/local/job_env/shell/NEW_SAVING.txt)
current_appids=`yarn application -list -appStates NEW_SAVING |grep application_ |grep -v yarn-ats |awk '{print $1}'`
#echo "---------------------定义空数组------------------------------"
declare -a curr_arr
curr_arr=()
index=0
#echo "---------------------遍历当前appids--------------------------"
for item in $current_appids
do
# echo "###"$item
if [[ "${appids[@]}" =~ "${item}" ]]; then
#echo "$item exists"
echo `yarn app -kill ${item}`
else
#echo "$item not exists"
curr_arr[$index]=$item
let index+=1
fi
done
index=0
#echo "---------------------校验------------------------------------"
if [[ ${#curr_arr[@]} -eq 0 ]];then
echo `cat /dev/null>/usr/local/job_env/shell/NEW_SAVING.txt`
else
echo ${curr_arr[@]}>/usr/local/job_env/shell/NEW_SAVING.txt
fi
fi
3.定时任务
crontab表达式,每日00点到10点之间,每半小时执行一次
*/30 00-10 * * * /usr/local/oo.sh>>/usr/local/log/cron_oo.log