Initial commit for OpenECOMP SDN-C OA&M
[sdnc/oam.git] / dgbuilder / show_status
1 tbold=$(tput setf 3)
2 bold=$(tput setf 2)
3 bold1=$(tput setf 2)
4 offbold=$(tput rmso;tput sgr0)
5
6 function pad {
7         #echo "1 is $1 2 is $2"
8         if [ "$1" == "" ]
9         then
10                 $1 = "";
11         fi
12         let count=0
13         curr_len=`expr length "$1"`
14         let space_length=$2-$curr_len
15         spaces=""
16         while [ $count -lt $space_length ]
17         do
18                 spaces="$spaces "
19                 let count=$count+1
20         done
21         echo "$1$spaces"
22 }
23         
24 function isRunning {
25         echo $(curl -I "$1" 2>/dev/null|head -1|tail -1|awk '{print $2}')
26 }
27 dirName=$(pwd)
28 options=($(ls -l $dirName/releases|grep ^d|awk '{print $NF}'|sort))
29         echo "$(pad RELEASE 15)$(pad URL 30)$(pad Status 10)"
30         echo "$(pad '----' 15)$(pad '---' 30)$(pad '------' 10)"
31         for opt in "${options[@]}" 
32         do 
33                 
34                 releaseDir="$opt"
35                 if [ -e "./releases/${opt}/customSettings.js" ]
36                 then
37                         pid=$(cat ./releases/$releaseDir/logs/process_pid 2>/dev/null)
38                         port=$(cat ./releases/$releaseDir/customSettings.js 2>/dev/null|grep uiPort|sed -e 's/[, ]//g'|cut -d: -f2)
39                         resp1=$(isRunning "http://localhost:$port")
40                         if [ "$resp1" == "401" ]
41                         then    
42                                 echo "$(pad $releaseDir 15)$(pad http://localhost:$port 30)${bold}$(pad running 10)${offbold}"
43                         else
44                                 processId=$(netstat -upltn 2>/dev/null|grep $port|awk '{print $NF}'|sed -e 's%/node-red%%g')
45                                 if [ "$processId" == "" ]
46                                 then
47                                         echo "$(pad $releaseDir 15)$(pad http://localhost:$port 30)${bold}$(pad stopped 10)${offbold}"
48                                 else
49                                         echo "$(pad $releaseDir 15)$(pad http://localhost:$port 30)${bold}$(pad running 10)${offbold}"
50                                 fi
51                         fi
52                 fi
53         done