Removed any code useless;New feature:Show Details of Application

This commit is contained in:
2020-04-10 13:26:57 +08:00
parent 5503dd82fd
commit 4f0b3f21ee
+62 -35
View File
@@ -78,20 +78,21 @@ main_menu()
{
while true
do
title=" Please Enter Your Application:[1-$app_num]"
clear
echo -e
echo -e "${blue}NCBA MSL Management Menu (RWA)${plain}"
echo -e "----------------------------------------------"
echo -e $title
echo -e "----------------------------------------------"
echo -e "--------------------------------------------------"
echo -e "Please Enter Your Choice"
echo -e ""
echo -e "[${yellow}1-$app_num${plain}]:Chose Application ${yellow}q${plain}:Exit Menu ${yellow}a${plain}:Details"
echo -e "--------------------------------------------------"
echo -e ""
## render app menu
for ((i=1;i<=${#app_list[@]};i++ )); do
hint="${app_list[$i-1]}"
state=`get_app_state ${hint}`
printf "${green}%-4s${plain} %-30s [$([ "$state" == "running" ] && echo ${green} || echo ${red})%-7s${plain}]\n" ${i}")" ${hint} ${state}
printf "${yellow}%-3s${plain} %-30s [$([ "$state" == "running" ] && echo ${green} || echo ${red})%-7s${plain}]\n" ${i}")" ${hint} ${state}
done
## Ask user which choice and press key
@@ -99,29 +100,37 @@ main_menu()
case "${selected}" in
[1-9]*)
if [ "${selected}" -gt $app_num ]; then
title="[${red}Error${plain}] Please only enter a number [1-$app_num]"
#title="[${red}Error${plain}] Please only enter a number [1-$app_num]"
continue
fi
echo
echo -e
echo "You choose = ${app_list[${selected}-1]}"
cur_app=${app_list[${selected}-1]}
echo
echo -e
function_menu
;;
q)
exit 0
;;
a)
## Show details all of application
clear
printf "%-25s %-15s %-5s %-10s\n" "Application" "Version" "Size" "LastUpdated"
echo -e "-------------------------------------------------------------------"
for ((j=1;j<=${#app_list[@]};j++ )); do
hint="${app_list[$j-1]}"
echo -e "${green}${j}${plain}) ${hint} status"
hint=${app_list[$j-1]}
pid=$(get_app_pid ${hint})
state=$(get_app_state ${hint})
version=$(get_app_version ${hint})
last_updated=$(get_app_last_updated ${hint})
size=$(get_app_size ${hint})
printf "${blue}%-25s${plan} ${red}%-15s${plan} ${gray}%-5s${plan} ${gray}%-10s${plan} \n" $hint $version $size $last_updated
done
echo -e && read -s -n1 -p "Press any key go back"
;;
*)
title="[${red}Error${plain}] Please only enter a number [1-$app_num]"
## Do nothing when other key pressed
;;
esac
done
@@ -216,24 +225,25 @@ function_menu()
do
pid=`get_app_pid ${cur_app}`
state=`get_app_state ${cur_app}`
if [ "running" == "$state" ]; then
title="$cur_app is [${green}running($pid)${plain}] "
else
title="$cur_app is [${red}dead${plain}]"
fi
version=`get_app_version ${cur_app}`
last_updated=`get_app_last_updated ${cur_app}`
size=`get_app_size ${cur_app}`
clear
echo -e "----------------------------------------------"
echo -e $title
echo -e "----------------------------------------------"
echo -e ""
echo -e "${green}1${plain}) Login"
echo -e "${green}2${plain}) Startup/Restart"
echo -e "${green}3${plain}) Shutdown"
echo -e "${green}4${plain}) Trace Logging"
printf "Application: ${blue}%s${plain} [$([ "$state" == "running" ] && echo ${green} || echo ${red})%s${plain}]\n" ${cur_app} $state
echo -e "--------------------------------------------------"
printf "Version : ${gray}%s${plain}\n" $version
printf "Size : ${gray}%s${plain}\n" $size
printf "LastUpdated: ${gray}%-19s${plain}\n" $last_updated
echo -e "--------------------------------------------------"
echo -e ""
echo -e "${yellow}1)${plain} Login"
echo -e "${yellow}2)${plain} Startup/Restart"
echo -e "${yellow}3)${plain} Shutdown"
echo -e "${yellow}4)${plain} Logging Trace"
echo -e ""
echo -e "${green}b${plain}) Go back"
echo -e "${yellow}b)${plain} Go back"
echo -e ""
echo -e && read -p "Please enter a number :" selected
@@ -246,7 +256,7 @@ function_menu()
break
;;
2)
## Startup Application
## Startup application
module_name=${module_map["${cur_app}"]}
profile_app=""
@@ -270,7 +280,7 @@ function_menu()
break
;;
3)
## Shutdown application
## Shutdown application
clear
echo -e ""
echo -e "${blue}>> Now beginning kill the application with PID:${pid}...${plain}"
@@ -295,7 +305,7 @@ function_menu()
break
;;
4)
## Trace logging
## Logging trace
echo -e "${blue}>> Trace logging...${plain}"
echo -e ""
#tail -f ${base_home}/${cur_app}/log/${cur_app}.out
@@ -307,27 +317,44 @@ function_menu()
break
;;
*)
## Echo error message when other key pressed
title="[${red}Error${plain}] Please only enter a number [1-4]"
## Do nothing when other key pressed
;;
esac
done
}
get_app_last_updated()
{
app=$1
last_updated=`stat --format="%y" ${war_dir}/${app}.war | sed 's/\..*//g'| sed 's/ /_/g'`
echo -e $last_updated
}
get_app_size()
{
app=$1
size=`stat --format="%s" ${war_dir}/${app}.war`
size=`expr $size / 1024 / 1024`"M"
echo -e $size
}
get_app_state()
{
app=$1
pid=`ps -ef | grep "/${app}.war" | grep -v grep|awk '{print $2}'`
echo $([ ! -z "${pid}" ] && echo "running" || echo "dead")
return 0
echo -e $([ ! -z "${pid}" ] && echo "running" || echo "dead")
}
get_app_pid()
{
app=$1
echo $(ps -ef | grep "/${app}.war" | grep -v grep|awk '{print $2}')
return 0
echo -e $(ps -ef | grep "/${app}.war" | grep -v grep|awk '{print $2}')
}
get_app_version()
{
app=$1
echo -e $(unzip -p ${war_dir}/${app}.war META-INF/MANIFEST.MF | grep Implementation-Version: | awk -F ':' '{print $2}' | sed 's/ //g' |sed 's/\r//g' | sed 's/\n//g')
}
main_menu