init.sh 2.9 KB
Newer Older
T
tangfangzhi 已提交
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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
#!/bin/bash

function usage() {
    echo "$0"
    echo -e "\t -w work dir"
    echo -e "\t -o old version package"
    echo -e "\t -n new version package"
    echo -e "\t -c client package"
    echo -e "\t -h help"
}

while getopts "w:o:n:c:h" opt; do
    case $opt in
        w)
            WORK_DIR=$OPTARG
            ;;
        o)
            TAOS_PKG1=$OPTARG
            ;;
        n)
            TAOS_PKG2=$OPTARG
            ;;
        c)
            CLIENT_PKG=$OPTARG
            ;;
        h)
            usage
            exit 0
            ;;
        \?)
            echo "Invalid option: -$OPTARG"
            usage
            exit 0
            ;;
    esac
done

if [ -z "$WORK_DIR" ]; then
    usage
    exit 1
fi
if [ -z "$TAOS_PKG1" ]; then
    usage
    exit 1
fi
if [ -z "$TAOS_PKG2" ]; then
    usage
    exit 1
fi
if [ ! -z "$CLIENT_PKG" ]; then
    if [ ! -f "$CLIENT_PKG" ]; then
        echo "$CLIENT_PKG not found"
        exit 1
    fi
fi

script_dir=`dirname $0`
cd $script_dir

source settings.sh

code_dir=$WORK_DIR/TDinternal
container_workdir1=$WORK_DIR/compatibility/$container_name1
container_workdir2=$WORK_DIR/compatibility/$container_name2
container_workdir3=$WORK_DIR/compatibility/$container_name3
container_workdir4=$WORK_DIR/compatibility/$container_name4


mkdir -p $container_workdir1
mkdir -p $container_workdir2
mkdir -p $container_workdir3
mkdir -p $container_workdir4

docker rm -f $container_name1 >/dev/null 2>&1
docker rm -f $container_name2 >/dev/null 2>&1
docker rm -f $container_name3 >/dev/null 2>&1
docker rm -f $container_name4 >/dev/null 2>&1

net_name=mynet
docker network create --driver bridge --subnet 172.31.30.0/24 --gateway 172.31.30.1 $net_name

./init_container.sh -d $code_dir -w $container_workdir1 -p $TAOS_PKG1 -q $TAOS_PKG2 -n $net_name -c $container_name1 &
./init_container.sh -d $code_dir -w $container_workdir2 -p $TAOS_PKG1 -q $TAOS_PKG2 -n $net_name -c $container_name2 &
./init_container.sh -d $code_dir -w $container_workdir3 -p $TAOS_PKG1 -q $TAOS_PKG2 -n $net_name -c $container_name3 &
./init_container.sh -d $code_dir -w $container_workdir4 -p $TAOS_PKG1 -q $TAOS_PKG2 -n $net_name -c $container_name4 &

RET=0
pids=`jobs -p`
for pid in $pids; do
    wait $pid
    status=$?
    if [ $status -ne 0 ]; then
        echo "init container $pid status is $status!"
        RET=$status
    fi
done

if [ $RET -eq 0 ]; then
    if [ -z "$CLIENT_PKG" ]; then
        docker exec $container_name4 pip3 install /home/TDinternal/community/src/connector/python
        RET=$?
    else
        pkg_name=`basename $CLIENT_PKG`
        pkg_dir=`echo "$pkg_name"|sed "s/-Linux-x64.tar.gz//"`
        docker cp $CLIENT_PKG $container_name4:/home/
        docker exec $container_name4 sh -c "cd /home;tar xzf $pkg_name;pip3 install /home/$pkg_dir/connector/python"
        RET=$?
    fi
fi

if [ $RET -eq 0 ]; then
    echo "containers created"
else
    echo "containers create failed"
fi

exit $RET