Merge "Change PTL informatin in INFO"
[bottlenecks.git] / utils / infra_setup / vm_dev_setup / setup_env.sh
1 #!/bin/bash
2 ##############################################################################
3 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
4 #
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10
11 set -x
12
13 wait_vm_ok() {
14     ip=$1
15
16     retry=0
17     until timeout 10s ssh $ssh_args ubuntu@$ip "exit" >/dev/null 2>&1
18     do
19         echo "retry connect rubbos vm ip $ip $retry"
20         sleep 1
21         let retry+=1
22         if [[ $retry -ge $2 ]];then
23             echo "rubbos control start timeout !!!"
24             #exit 1
25         fi
26     done
27 }
28
29 bottlenecks_prepare_env()
30 {
31     echo "Bottlenecks prepare env"
32
33     # configue rubbos control ssh key
34     generate_ssh_key
35
36     # wait all other VMs ok
37     for i in $rubbos_benchmark $rubbos_client1 $rubbos_client2 \
38              $rubbos_client3 $rubbos_client4 $rubbos_httpd $rubbos_mysql1 $rubbos_tomcat1
39     do
40         wait_vm_ok $i 360
41     done
42
43     # configue other VMs
44     for i in $rubbos_benchmark $rubbos_client1 $rubbos_client2 \
45              $rubbos_client3 $rubbos_client4 $rubbos_httpd $rubbos_mysql1 $rubbos_tomcat1
46     do
47           scp $ssh_args -r $SCRIPT_DIR ubuntu@$i:/tmp
48           ssh $ssh_args ubuntu@$i "sudo bash $SCRIPT_DIR/vm_prepare_setup.sh" &
49     done
50
51     # ugly use ssh execute script to fix ubuntu previlege issue
52     ssh $ssh_args ubuntu@$rubbos_control "sudo bash $SCRIPT_DIR/vm_prepare_setup.sh"
53
54     # test root access
55     for i in $rubbos_control $rubbos_benchmark $rubbos_client1 $rubbos_client2 \
56              $rubbos_client3 $rubbos_client4 $rubbos_httpd $rubbos_mysql1 $rubbos_tomcat1
57     do
58           ssh $ssh_args root@$i "uname -a"
59     done
60 }
61
62 git_checkout()
63 {
64     if sudo git cat-file -e $1^{commit} 2>/dev/null; then
65         # branch, tag or sha1 object
66         sudo git checkout $1
67     else
68         # refspec / changeset
69         sudo git fetch --tags --progress $2 $1
70         sudo git checkout FETCH_HEAD
71     fi
72 }
73
74 bottlenecks_download_repo()
75 {
76     echo "Bottlenecks: download bottlenecks repo"
77
78     sudo git config --global http.sslVerify false
79     if [ ! -d $BOTTLENECKS_REPO_DIR ]; then
80         sudo git clone $BOTTLENECKS_REPO $BOTTLENECKS_REPO_DIR
81     fi
82     cd $BOTTLENECKS_REPO_DIR
83     sudo git checkout master && sudo git pull
84     git_checkout $BOTTLENECKS_BRANCH $BOTTLENECKS_REPO
85     cd -
86 }
87
88 bottlenecks_config_hosts_ip()
89 {
90     sudo sed -i -e "s/REPLACE_CONTROL_HOST/$rubbos_control/g" \
91            -e "s/REPLACE_HTTPD_HOST/$rubbos_httpd/g" \
92            -e "s/REPLACE_MYSQL1_HOST/$rubbos_mysql1/g" \
93            -e "s/REPLACE_TOMCAT1_HOST/$rubbos_tomcat1/g" \
94            -e "s/REPLACE_CLIENT1_HOST/$rubbos_client1/g" \
95            -e "s/REPLACE_CLIENT2_HOST/$rubbos_client2/g" \
96            -e "s/REPLACE_CLIENT3_HOST/$rubbos_client3/g" \
97            -e "s/REPLACE_CLIENT4_HOST/$rubbos_client4/g" \
98            -e "s/REPLACE_BENCHMARK_HOST/$rubbos_benchmark/g" \
99            $BOTTLENECKS_REPO_DIR/rubbos/rubbos_scripts/1-1-1/set_bottlenecks_rubbos_env.sh
100 }
101
102 bottlenecks_download_packages()
103 {
104     echo "Bottlenecks: download rubbos dependent packages from artifacts"
105
106     curl --connect-timeout 10 -o /tmp/app_tools.tar.gz $RUBBOS_APP_TOOLS_URL 2>/dev/null
107     sudo tar zxf /tmp/app_tools.tar.gz -C $RUBBOS_DIR
108     rm -rf /tmp/app_tools.tar.gz
109     curl --connect-timeout 10 -o /tmp/rubbosMulini6.tar.gz $RUBBOS_MULINI6_URL 2>/dev/null
110     sudo tar zxf /tmp/rubbosMulini6.tar.gz -C $RUBBOS_MULINI6_DIR
111     rm -rf /tmp/rubbosMulini6.tar.gz
112 }
113
114 bottlenecks_rubbos_install_exe()
115 {
116     echo "Bottlenecks: install and run rubbos"
117
118     cd $RUBBOS_RUN_DIR
119     sudo ./run.sh
120 }
121
122 main()
123 {
124     SCRIPT_DIR=`cd ${BASH_SOURCE[0]%/*};pwd`
125
126     ssh_args="-o StrictHostKeyChecking=no -o BatchMode=yes"
127     source $SCRIPT_DIR/hosts.conf
128     source $SCRIPT_DIR/package.conf
129     source $SCRIPT_DIR/common.sh
130
131     bottlenecks_prepare_env
132     set -x
133     bottlenecks_download_repo
134     bottlenecks_config_hosts_ip
135     bottlenecks_download_packages
136     bottlenecks_rubbos_install_exe
137 }
138
139 main
140 set +x