summaryrefslogtreecommitdiffstats
path: root/utils/infra_setup/vm_dev_setup/setup_env.sh
blob: 7a69e83c4506ffb04d6f9e54fd43614252623882 (plain)
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
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/bin/bash

set -x

wait_vm_ok() {
    ip=$1

    retry=0
    until timeout 10s ssh $ssh_args ec2-user@$ip "exit" >/dev/null 2>&1
    do
        echo "retry connect rubbos vm ip $ip $retry"
        sleep 1
        let retry+=1
        if [[ $retry -ge $2 ]];then
            echo "rubbos control start timeout !!!"
            #exit 1
        fi
    done
}

bottlenecks_prepare_env()
{
    echo "Bottlenecks prepare env"

    # configue rubbos control ssh key
    generate_ssh_key

    # wait all other VMs ok
    for i in $rubbos_benchmark $rubbos_client1 $rubbos_client2 \
             $rubbos_client3 $rubbos_client4 $rubbos_httpd $rubbos_mysql1 $rubbos_tomcat1
    do
        wait_vm_ok $i 360
    done

    # configue other VMs
    for i in $rubbos_benchmark $rubbos_client1 $rubbos_client2 \
             $rubbos_client3 $rubbos_client4 $rubbos_httpd $rubbos_mysql1 $rubbos_tomcat1
    do
          scp $ssh_args -r $SCRIPT_DIR ec2-user@$i:/tmp
          ssh $ssh_args ec2-user@$i "sudo bash $SCRIPT_DIR/vm_prepare_setup.sh" &
    done

    # ugly use ssh execute script to fix ec2-user previlege issue
    ssh $ssh_args ec2-user@$rubbos_control "sudo bash $SCRIPT_DIR/vm_prepare_setup.sh"

    # test root access
    for i in $rubbos_control $rubbos_benchmark $rubbos_client1 $rubbos_client2 \
             $rubbos_client3 $rubbos_client4 $rubbos_httpd $rubbos_mysql1 $rubbos_tomcat1
    do
          ssh $ssh_args root@$i "uname -a"
    done
}

bottlenecks_download_repo()
{
    echo "Bottlenecks: download bottlenecks repo"

    sudo git config --global http.sslVerify false
    if [ -d $BOTTLENECKS_REPO_DIR/.git ]; then
        cd $BOTTLENECKS_REPO_DIR
        sudo git pull origin master
        if [ x"$GERRIT_REFSPEC_DEBUG" != x ]; then
            sudo git fetch $BOTTLENECKS_REPO $GERRIT_REFSPEC_DEBUG && sudo git checkout FETCH_HEAD
        fi
        cd -
    else
        sudo rm -rf $BOTTLENECKS_REPO_DIR
        sudo git clone $BOTTLENECKS_REPO $BOTTLENECKS_REPO_DIR
        if [ x"$GERRIT_REFSPEC_DEBUG" != x ]; then
            cd $BOTTLENECKS_REPO_DIR
            echo "fetch $GERRIT_REFSPEC_DEBUG"
            sudo git fetch $BOTTLENECKS_REPO $GERRIT_REFSPEC_DEBUG && sudo git checkout FETCH_HEAD
            cd -
        fi

    fi
}

bottlenecks_config_hosts_ip()
{
    sudo sed -i -e "s/REPLACE_CONTROL_HOST/$rubbos_control/g" \
           -e "s/REPLACE_HTTPD_HOST/$rubbos_httpd/g" \
           -e "s/REPLACE_MYSQL1_HOST/$rubbos_mysql1/g" \
           -e "s/REPLACE_TOMCAT1_HOST/$rubbos_tomcat1/g" \
           -e "s/REPLACE_CLIENT1_HOST/$rubbos_client1/g" \
           -e "s/REPLACE_CLIENT2_HOST/$rubbos_client2/g" \
           -e "s/REPLACE_CLIENT3_HOST/$rubbos_client3/g" \
           -e "s/REPLACE_CLIENT4_HOST/$rubbos_client4/g" \
           -e "s/REPLACE_BENCHMARK_HOST/$rubbos_benchmark/g" \
           $BOTTLENECKS_REPO_DIR/rubbos/rubbos_scripts/1-1-1/set_bottlenecks_rubbos_env.sh
}

bottlenecks_download_packages()
{
    echo "Bottlenecks: download rubbos dependent packages from artifacts"

    curl --connect-timeout 10 -o /tmp/app_tools.tar.gz $RUBBOS_APP_TOOLS_URL 2>/dev/null
    sudo tar zxf /tmp/app_tools.tar.gz -C $RUBBOS_DIR
    rm -rf /tmp/app_tools.tar.gz
    curl --connect-timeout 10 -o /tmp/rubbosMulini6.tar.gz $RUBBOS_MULINI6_URL 2>/dev/null
    sudo tar zxf /tmp/rubbosMulini6.tar.gz -C $RUBBOS_MULINI6_DIR
    rm -rf /tmp/rubbosMulini6.tar.gz
}

bottlenecks_rubbos_install_exe()
{
    echo "Bottlenecks: install and run rubbos"

    cd $RUBBOS_RUN_DIR
    sudo ./run.sh
}

main()
{
    SCRIPT_DIR=`cd ${BASH_SOURCE[0]%/*};pwd`

    ssh_args="-o StrictHostKeyChecking=no -o BatchMode=yes"
    source $SCRIPT_DIR/package.conf
    source $SCRIPT_DIR/hosts.conf
    source $SCRIPT_DIR/common.sh

    bottlenecks_prepare_env
    set -x
    bottlenecks_download_repo
    bottlenecks_config_hosts_ip
    bottlenecks_download_packages
    bottlenecks_rubbos_install_exe
}

main
set +x