buildClusterEnv.sh 4.5 KB
Newer Older
P
Ping Xiao 已提交
1 2 3
#!/bin/bash
echo "Executing buildClusterEnv.sh"
CURR_DIR=`pwd`
4
IN_TDINTERNAL="community"
P
Ping Xiao 已提交
5

P
Ping Xiao 已提交
6
if [ $# != 6 ]; then 
P
Ping Xiao 已提交
7 8
  echo "argument list need input : "
  echo "  -n numOfNodes"
P
Ping Xiao 已提交
9 10
  echo "  -v version"
  echo "  -d docker dir" 
P
Ping Xiao 已提交
11 12 13 14 15
  exit 1
fi

NUM_OF_NODES=
VERSION=
P
Ping Xiao 已提交
16 17
DOCKER_DIR=
while getopts "n:v:d:" arg
P
Ping Xiao 已提交
18 19 20 21 22 23 24
do
  case $arg in
    n)
      NUM_OF_NODES=$OPTARG
      ;;
    v)
      VERSION=$OPTARG
P
Ping Xiao 已提交
25 26 27
      ;;
    d)
      DOCKER_DIR=$OPTARG
P
Ping Xiao 已提交
28 29 30 31 32 33 34
      ;;    
    ?)
      echo "unkonwn argument"
      ;;
  esac
done

35
function addTaoscfg {
36
  for((i=1;i<=$NUM_OF_NODES;i++))
37
  do 
P
Ping Xiao 已提交
38
    touch $DOCKER_DIR/node$i/cfg/taos.cfg
P
Ping Xiao 已提交
39 40 41
    echo 'firstEp          tdnode1:6030' > $DOCKER_DIR/node$i/cfg/taos.cfg
    echo 'fqdn             tdnode'$i >> $DOCKER_DIR/node$i/cfg/taos.cfg
    echo 'arbitrator       tdnode1:6042' >> $DOCKER_DIR/node$i/cfg/taos.cfg
42 43
  done
}
P
Ping Xiao 已提交
44 45

function createDIR {
46
  for((i=1;i<=$NUM_OF_NODES;i++))
P
Ping Xiao 已提交
47
  do    
P
Ping Xiao 已提交
48 49 50 51
    mkdir -p $DOCKER_DIR/node$i/data
    mkdir -p $DOCKER_DIR/node$i/log
    mkdir -p $DOCKER_DIR/node$i/cfg
    mkdir -p $DOCKER_DIR/node$i/core
P
Ping Xiao 已提交
52 53 54
  done
}

P
Ping Xiao 已提交
55 56
function cleanEnv {
  echo "Clean up docker environment"    
57
  for((i=1;i<=$NUM_OF_NODES;i++))
P
Ping Xiao 已提交
58 59 60
  do    
    rm -rf $DOCKER_DIR/node$i/data/*    
    rm -rf $DOCKER_DIR/node$i/log/*
P
Ping Xiao 已提交
61 62 63 64 65 66 67 68 69 70
  done
}

function prepareBuild {

  if [ -d $CURR_DIR/../../../../release ]; then
    echo release exists
    rm -rf $CURR_DIR/../../../../release/*
  fi

71
  if [ ! -e $DOCKER_DIR/TDengine-server-$VERSION-Linux-x64.tar.gz ] || [ ! -e $DOCKER_DIR/TDengine-arbitrator-$VERSION-Linux-x64.tar.gz ]; then
72 73 74
    cd $CURR_DIR/../../../../packaging    
    echo $CURR_DIR
    echo $IN_TDINTERNAL
75
    echo "generating TDeninger packages"
76 77 78 79 80 81
    if [[ "$CURR_DIR" == *"$IN_TDINTERNAL"* ]]; then
      pwd
      ./release.sh -v cluster -n $VERSION >> /dev/null 2>&1
    else
      pwd
      ./release.sh -v edge -n $VERSION >> /dev/null 2>&1
82
    fi
P
Ping Xiao 已提交
83

84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
    if [[ "$CURR_DIR" == *"$IN_TDINTERNAL"* ]]; then
      if [ ! -e $CURR_DIR/../../../../release/TDengine-enterprise-server-$VERSION-Linux-x64.tar.gz ]; then
        echo "no TDengine install package found"
        exit 1
      fi

      if [ ! -e $CURR_DIR/../../../../release/TDengine-enterprise-arbitrator-$VERSION-Linux-x64.tar.gz ]; then
        echo "no arbitrator install package found"
        exit 1
      fi
    else
      if [ ! -e $CURR_DIR/../../../../release/TDengine-server-$VERSION-Linux-x64.tar.gz ]; then
        echo "no TDengine install package found"
        exit 1
      fi

      if [ ! -e $CURR_DIR/../../../../release/TDengine-arbitrator-$VERSION-Linux-x64.tar.gz ]; then
        echo "no arbitrator install package found"
        exit 1
      fi
104 105 106
    fi

    cd $CURR_DIR/../../../../release
107 108 109 110 111 112 113
    if [[ "$CURR_DIR" == *"$IN_TDINTERNAL"* ]]; then
      mv TDengine-enterprise-server-$VERSION-Linux-x64.tar.gz $DOCKER_DIR
      mv TDengine-enterprise-arbitrator-$VERSION-Linux-x64.tar.gz $DOCKER_DIR
    else
      mv TDengine-server-$VERSION-Linux-x64.tar.gz $DOCKER_DIR
      mv TDengine-arbitrator-$VERSION-Linux-x64.tar.gz $DOCKER_DIR
    fi
114
  fi
P
Ping Xiao 已提交
115 116 117 118
  
  rm -rf $DOCKER_DIR/*.yml
  cd $CURR_DIR

119
  cp *.yml  $DOCKER_DIR
P
Ping Xiao 已提交
120 121 122 123
  cp Dockerfile $DOCKER_DIR
}

function clusterUp {
124
  echo "docker compose start"
P
Ping Xiao 已提交
125
  
126
  cd $DOCKER_DIR  
127

128
  if [[ "$CURR_DIR" == *"$IN_TDINTERNAL"* ]]; then
P
Ping Xiao 已提交
129
    docker_run="PACKAGE=TDengine-enterprise-server-$VERSION-Linux-x64.tar.gz TARBITRATORPKG=TDengine-enterprise-arbitrator-$VERSION-Linux-x64.tar.gz DIR=TDengine-enterprise-server-$VERSION DIR2=TDengine-enterprise-arbitrator-$VERSION VERSION=$VERSION DATADIR=$DOCKER_DIR docker-compose -f docker-compose.yml "
130 131 132 133
  else
    docker_run="PACKAGE=TDengine-server-$VERSION-Linux-x64.tar.gz TARBITRATORPKG=TDengine-arbitrator-$VERSION-Linux-x64.tar.gz DIR=TDengine-server-$VERSION DIR2=TDengine-arbitrator-$VERSION VERSION=$VERSION DATADIR=$DOCKER_DIR docker-compose -f docker-compose.yml "
  fi

134 135 136 137 138 139 140 141 142 143
  if [ $NUM_OF_NODES -ge 2 ];then
    echo "create $NUM_OF_NODES dnodes"
    for((i=3;i<=$NUM_OF_NODES;i++))
    do
      if [ ! -f node$i.yml ];then
        echo "node$i.yml not exist"
        cp node3.yml node$i.yml
        sed -i "s/td2.0-node3/td2.0-node$i/g" node$i.yml
        sed -i "s/'tdnode3'/'tdnode$i'/g" node$i.yml
        sed -i "s#/node3/#/node$i/#g" node$i.yml
L
fix  
liuyq-617 已提交
144
        sed -i "s#hostname: tdnode3#hostname: tdnode$i#g" node$i.yml
145 146 147 148 149
        sed -i "s#ipv4_address: 172.27.0.9#ipv4_address: 172.27.0.`expr $i + 6`#g" node$i.yml
      fi
      docker_run=$docker_run" -f node$i.yml "
    done
    docker_run=$docker_run" up -d"
P
Ping Xiao 已提交
150
  fi
151
  echo $docker_run |sh 
L
change  
liuyq-617 已提交
152
  
153
  echo "docker compose finish"
P
Ping Xiao 已提交
154 155
}

156 157 158
createDIR
cleanEnv
addTaoscfg
159 160
prepareBuild
clusterUp