setupDnodes.sh 3.3 KB
Newer Older
P
plum-lihui 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#!/bin/bash
#
# setup test environment

set -e
#set -x

# setupDnodes.sh  
#             -e [ new | old]
#             -n [ dnode number]
#             -f [ first ep]
#             -p [ start port]
#             -r [ dnode root dir]

# set parameters by default value
P
plum-lihui 已提交
16 17
fqdn=`hostname`

P
plum-lihui 已提交
18 19
enviMode=new
dataRootDir="/data"
P
plum-lihui 已提交
20 21
firstEp="${fqdn}:6030"
startPort=6030
P
plum-lihui 已提交
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
dnodeNumber=1


while getopts "he:f:n:r:p:" arg
do
  case $arg in
    e)
      enviMode=$( echo $OPTARG )
      ;;
    n)
      dnodeNumber=$(echo $OPTARG)
      ;;
    f)
      firstEp=$(echo $OPTARG)
      ;;
    p)
      startPort=$(echo $OPTARG)
      ;;
    r)
      dataRootDir=$(echo $OPTARG)
      ;;
    h)
      echo "Usage: `basename $0` -e [new | old] "
      echo "                  -n [ dnode number] "
      echo "                  -f [ first ep] "
      echo "                  -p [ start port] "
      echo "                  -r [ dnode root dir] "
      exit 0
      ;;
    ?) #unknow option
      echo "unkonw argument"
      exit 1
      ;;
  esac
done

echo "enviMode=${enviMode} dnodeNumber=${dnodeNumber} dataRootDir=${dataRootDir} firstEp=${firstEp} startPort=${startPort}"

#curr_dir=$(pwd)


createNewCfgFile() {
    cfgFile=$1/taos.cfg
    dataDir=$2
    logDir=$3
    firstEp=$4    
    serverPort=$5
    
    echo "debugFlag     131"             > ${cfgFile}
    echo "firstEp       ${firstEp}"     >> ${cfgFile}
    echo "dataDir       ${dataDir}"     >> ${cfgFile}
    echo "logDir        ${logDir}"      >> ${cfgFile}
    echo "serverPort    ${serverPort}"  >> ${cfgFile}     
P
plum-lihui 已提交
75
    echo "numOfLogLines      100000000" >> ${cfgFile}  
P
plum-lihui 已提交
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
    echo "supportVnodes        1024"   >> ${cfgFile} 
    #echo "asyncLog             0"     >> ${cfgFile}
    echo "telemetryReporting   0"      >> ${cfgFile}  
}

createNewDnodesDataDir() {
    if [ -d ${dataRootDir} ]; then
        rm -rf ${dataRootDir}/dnode*
    else
        echo "${dataRootDir} not exist"
        exit 1
    fi
    
    dnodeNumber=$1
    firstEp=$2
    
    serverPort=${startPort}
    for ((i=0; i<${dnodeNumber}; i++)); do
        mkdir -p ${dataRootDir}/dnode_${i}/cfg
        mkdir -p ${dataRootDir}/dnode_${i}/log
        mkdir -p ${dataRootDir}/dnode_${i}/data 
        
        createNewCfgFile ${dataRootDir}/dnode_${i}/cfg ${dataRootDir}/dnode_${i}/data ${dataRootDir}/dnode_${i}/log ${firstEp} ${serverPort}
P
plum-lihui 已提交
99
        #echo "create dnode: ${serverPort}, ${dataRootDir}/dnode_${i}"
P
plum-lihui 已提交
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
        serverPort=$((10#${serverPort}+100))
    done
}

function kill_process() {
    pid=$(ps -ef | grep "$1" | grep -v "grep" | awk '{print $2}')
    if [ -n "$pid" ]; then
        kill -9 $pid   || :
    fi
}

startDnodes() {
    dnodeNumber=$1
    
    for ((i=0; i<${dnodeNumber}; i++)); do
        if [ -d ${dataRootDir}/dnode_${i} ]; then
            nohup taosd -c ${dataRootDir}/dnode_${i}/cfg >/dev/null 2>&1 & 
            echo "start taosd ${dataRootDir}/dnode_${i}"
        fi
    done
}

########################################################################################
###############################  main process ##########################################

## kill all taosd process
P
plum-lihui 已提交
126
#kill_process taosd
P
plum-lihui 已提交
127 128 129 130 131 132 133 134 135

## create director for all dnode
if [[ "$enviMode" == "new" ]]; then
  createNewDnodesDataDir ${dnodeNumber} ${firstEp}  
fi

## start all dnode by nohup
startDnodes ${dnodeNumber}

P
plum-lihui 已提交
136 137
echo "====run setupDnodes.sh end===="
echo " "
P
plum-lihui 已提交
138 139