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