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

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

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

34 35 36 37
function addTaoscfg {
  for i in {1..5}
  do 
    touch /data/node$i/cfg/taos.cfg
P
Ping Xiao 已提交
38 39 40
    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
41 42
  done
}
P
Ping Xiao 已提交
43 44

function createDIR {
45
  for i in {1..5}
P
Ping Xiao 已提交
46
  do    
P
Ping Xiao 已提交
47 48 49 50
    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 已提交
51 52 53
  done
}

P
Ping Xiao 已提交
54 55
function cleanEnv {
  echo "Clean up docker environment"    
56
  for i in {1..5}
P
Ping Xiao 已提交
57 58 59
  do    
    rm -rf $DOCKER_DIR/node$i/data/*    
    rm -rf $DOCKER_DIR/node$i/log/*
P
Ping Xiao 已提交
60 61 62 63 64 65 66 67 68 69
  done
}

function prepareBuild {

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

70
  if [ ! -e $DOCKER_DIR/TDengine-server-$VERSION-Linux-x64.tar.gz ] || [ ! -e $DOCKER_DIR/TDengine-arbitrator-$VERSION-Linux-x64.tar.gz ]; then
71
    cd $CURR_DIR/../../../../packaging
72
    echo "generating TDeninger packages"
73 74 75 76 77 78
    ./release.sh -v edge -n $VERSION >> /dev/null

    if [ ! -e $CURR_DIR/../../../../release/TDengine-server-$VERSION-Linux-x64.tar.gz ]; then
      echo "no TDengine install package found"
      exit 1
    fi
P
Ping Xiao 已提交
79

80 81 82 83 84 85 86 87 88
    if [ ! -e $CURR_DIR/../../../../release/TDengine-arbitrator-$VERSION-Linux-x64.tar.gz ]; then
      echo "no arbitrator install package found"
      exit 1
    fi

    cd $CURR_DIR/../../../../release
    mv TDengine-server-$VERSION-Linux-x64.tar.gz $DOCKER_DIR
    mv TDengine-arbitrator-$VERSION-Linux-x64.tar.gz $DOCKER_DIR
  fi
P
Ping Xiao 已提交
89 90 91 92
  
  rm -rf $DOCKER_DIR/*.yml
  cd $CURR_DIR

93
  cp *.yml  $DOCKER_DIR
P
Ping Xiao 已提交
94 95 96 97
  cp Dockerfile $DOCKER_DIR
}

function clusterUp {
98
  echo "docker compose start"
P
Ping Xiao 已提交
99
  
100
  cd $DOCKER_DIR  
101 102

  if [ $NUM_OF_NODES -eq 2 ]; then
103
    echo "create 2 dnodes"
P
Ping Xiao 已提交
104
    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 docker-compose up -d
105 106
  fi

P
Ping Xiao 已提交
107
  if [ $NUM_OF_NODES -eq 3 ]; then
P
Ping Xiao 已提交
108
    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  docker-compose -f docker-compose.yml -f node3.yml up -d
P
Ping Xiao 已提交
109 110 111
  fi

  if [ $NUM_OF_NODES -eq 4 ]; then
P
Ping Xiao 已提交
112
    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  docker-compose -f docker-compose.yml -f node3.yml -f node4.yml up -d
P
Ping Xiao 已提交
113 114 115
  fi

  if [ $NUM_OF_NODES -eq 5 ]; then
P
Ping Xiao 已提交
116
    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  docker-compose -f docker-compose.yml -f node3.yml -f node4.yml -f node5.yml up -d
P
Ping Xiao 已提交
117
  fi
118 119

  echo "docker compose finish"
P
Ping Xiao 已提交
120 121
}

122 123 124
createDIR
cleanEnv
addTaoscfg
125 126
prepareBuild
clusterUp