Chinthakayala, Sheshashailavas (sc2914) | d156997 | 2017-08-28 05:25:46 -0900 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | releaseDir="$1" |
| 3 | if [ "$#" != "1" ] |
| 4 | then |
| 5 | echo "Usage: $0 releaseDirName" |
| 6 | exit |
| 7 | fi |
| 8 | echo "ReleaseDir:$releaseDir" |
| 9 | export PROJECT_HOME=`pwd` |
| 10 | tbold=$(tput setf 3) |
| 11 | bold=$(tput setf 2) |
| 12 | bold1=$(tput setf 2) |
| 13 | offbold=$(tput rmso;tput sgr0) |
| 14 | |
| 15 | function pad { |
| 16 | #echo "1 is $1 2 is $2" |
| 17 | if [ "$1" == "" ] |
| 18 | then |
| 19 | $1 = ""; |
| 20 | fi |
| 21 | let count=0 |
| 22 | curr_len=`expr length "$1"` |
| 23 | let space_length=$2-$curr_len |
| 24 | spaces="" |
| 25 | while [ $count -lt $space_length ] |
| 26 | do |
| 27 | spaces="$spaces " |
| 28 | let count=$count+1 |
| 29 | done |
| 30 | echo "$1$spaces" |
| 31 | } |
| 32 | |
| 33 | function isRunning { |
| 34 | echo $(curl -I "$1" 2>/dev/null|head -1|tail -1|awk '{print $2}') |
| 35 | } |
| 36 | |
| 37 | npm install |
| 38 | |
| 39 | if [ -e "releases/${releaseDir}/customSettings.js" ] |
| 40 | then |
| 41 | pid=$(cat releases/$releaseDir/logs/process_pid 2>/dev/null) |
| 42 | port=$(cat releases/$releaseDir/customSettings.js|grep uiPort|sed -e 's/[, ]//g'|cut -d: -f2 ) |
| 43 | count=$(ps -p$pid 2>/dev/null|grep -v PID|wc -l) |
| 44 | if [ "$count" != "0" ] |
| 45 | then |
| 46 | echo "For Release \"$releaseDir\" - http://localhost:$port" |
| 47 | echo "********ALREADY RUNNING PID:$pid *******" |
| 48 | else |
| 49 | pid_listening_on_port=$(netstat -upltn 2>/dev/null|grep -w $port|awk '{print $NF}'|cut -d'/' -f1) |
| 50 | if [ "$pid_listening_on_port" != "" ] |
| 51 | then |
| 52 | if [ "$pid_listening_on_port" != "$pid" ] |
| 53 | then |
| 54 | echo "port $port is already in use by other process" |
| 55 | ps -p $pid_listening_on_port |
| 56 | else |
| 57 | echo "Process is already running."; |
| 58 | fi |
| 59 | exit; |
| 60 | fi |
| 61 | node red.js --settings releases/${releaseDir}/customSettings.js |
| 62 | process_pid="$!" |
| 63 | echo $process_pid >releases/$releaseDir/logs/process_pid |
| 64 | port=$(cat releases/${releaseDir}/customSettings.js|grep uiPort|sed -e 's/[, ]//g'|cut -d: -f2) |
| 65 | echo "For Release \"$releaseDir\" ${urlIp}:$port --- STARTED PID:$process_pid" |
| 66 | if [ "${releaseDir}" != "" ] |
| 67 | then |
| 68 | sleep 3 |
| 69 | ./show_status.sh|grep -w ${releaseDir} |
| 70 | fi |
| 71 | fi |
| 72 | else |
| 73 | echo "Directory ${releaseDir} is not setup. Use the createReleaseDir.sh script to setup the directory." |
| 74 | fi |