exec.sh 3.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 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
#!/bin/bash

# if [ $# != 4 || $# != 5 ]; then
  # echo "argument list need input : "
  # echo "  -n nodeName"
  # echo "  -s start/stop"
  # echo "  -c clear"
  # exit 1
# fi

set +e
#set -x

UNAME_BIN=`which uname`
OS_TYPE=`$UNAME_BIN`

NODE_NAME=
EXEC_OPTON=
CLEAR_OPTION="false"
while getopts "n:s:u:x:cv" arg
do
  case $arg in
    n)
      NODE_NAME=$OPTARG
      ;;
    s)
      EXEC_OPTON=$OPTARG
      ;;
    c)
      CLEAR_OPTION="clear"
      ;;
    v)
      VALGRIND_OPTION="true"
      ;;
    u)
      USERS=$OPTARG
      ;;
    x)
      SIGNAL=$OPTARG
      ;;
    ?)
      echo "unkown argument"
      ;;
  esac
done

SCRIPT_DIR=`dirname $0`
cd $SCRIPT_DIR/../
SCRIPT_DIR=`pwd`

IN_TDINTERNAL="community"
if [[ "$SCRIPT_DIR" == *"$IN_TDINTERNAL"* ]]; then
  cd ../../..
else
  cd ../../
fi

TAOS_DIR=`pwd`
wafwerar's avatar
wafwerar 已提交
59
TAOSD_DIR=`find . -name "taosd"|grep bin|head -n1`
60 61 62 63 64 65 66 67

if [[ "$OS_TYPE" != "Darwin" ]]; then
  cut_opt="--field="
else
  cut_opt="-f "
fi

if [[ "$TAOSD_DIR" == *"$IN_TDINTERNAL"* ]]; then
wafwerar's avatar
wafwerar 已提交
68
  BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2,3`
69
else
wafwerar's avatar
wafwerar 已提交
70
  BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2`
71 72 73 74 75 76
fi

BUILD_DIR=$TAOS_DIR/$BIN_DIR

SIM_DIR=$TAOS_DIR/sim
NODE_DIR=$SIM_DIR/$NODE_NAME
wafwerar's avatar
wafwerar 已提交
77
EXE_DIR=$BUILD_DIR/build/bin
78 79 80 81 82
CFG_DIR=$NODE_DIR/cfg
LOG_DIR=$NODE_DIR/log
DATA_DIR=$NODE_DIR/data
MGMT_DIR=$NODE_DIR/data/mgmt
TSDB_DIR=$NODE_DIR/data/tsdb
S
Shengliang Guan 已提交
83
ASAN_DIR=$SIM_DIR/asan
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
TAOS_CFG=$NODE_DIR/cfg/taos.cfg

echo ------------ $EXEC_OPTON $NODE_NAME

TAOS_FLAG=$SIM_DIR/tsim/flag
if [ -f "$TAOS_FLAG" ]; then 
  EXE_DIR=/usr/local/bin/taos
fi

if [ "$CLEAR_OPTION" = "clear" ]; then 
  echo rm -rf $MGMT_DIR $TSDB_DIR  
  rm -rf $TSDB_DIR
  rm -rf $MGMT_DIR
fi

if [ "$EXEC_OPTON" = "start" ]; then 
100
  #echo "ExcuteCmd:" $EXE_DIR/taosd -c $CFG_DIR  
101 102
  if [ "$VALGRIND_OPTION" = "true" ]; then 
    TT=`date +%s`
103
    #mkdir ${LOG_DIR}/${TT}
X
Xiaoyu Wang 已提交
104 105
    echo "nohup valgrind --log-file=${LOG_DIR}/valgrind-taosd-${NODE_NAME}-${TT}.log --tool=memcheck --leak-check=full --show-reachable=no  --track-origins=yes --show-leak-kinds=all --num-callers=20 -v -v  --workaround-gcc296-bugs=yes   $EXE_DIR/taosd -c $CFG_DIR > /dev/null 2>&1 &"
    nohup valgrind --log-file=${LOG_DIR}/valgrind-taosd-${NODE_NAME}-${TT}.log --tool=memcheck --leak-check=full --show-reachable=no  --track-origins=yes --show-leak-kinds=all --num-callers=20 -v -v  --workaround-gcc296-bugs=yes   $EXE_DIR/taosd -c $CFG_DIR > /dev/null 2>&1 &   
106
  else
107
    echo "nohup $EXE_DIR/taosd -c $CFG_DIR > /dev/null 2>&1 &"
S
Shengliang Guan 已提交
108
    nohup $EXE_DIR/taosd -c $CFG_DIR > /dev/null 2> $ASAN_DIR/$NODE_NAME.asan & 
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
  fi
  
else
  #relative path
  RCFG_DIR=sim/$NODE_NAME/cfg
  PID=`ps -ef|grep taosd | grep $RCFG_DIR | grep -v grep | awk '{print $2}'`
  while [ -n "$PID" ]
  do
    if [ "$SIGNAL" = "SIGKILL" ]; then
      echo try to kill by signal SIGKILL
      kill -9 $PID
    else
      echo try to kill by signal SIGINT
      kill -SIGINT $PID
    fi
    sleep 1
    PID=`ps -ef|grep taosd | grep $RCFG_DIR | grep -v grep | awk '{print $2}'`
  done 
fi