|
| 1 | +# |
| 2 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 3 | +# or more contributor license agreements. See the NOTICE file |
| 4 | +# distributed with this work for additional information |
| 5 | +# regarding copyright ownership. The ASF licenses this file |
| 6 | +# to you under the Apache License, Version 2.0 (the |
| 7 | +# "License"); you may not use this file except in compliance |
| 8 | +# with the License. You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, |
| 13 | +# software distributed under the License is distributed on an |
| 14 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | +# KIND, either express or implied. See the License for the |
| 16 | +# specific language governing permissions and limitations |
| 17 | +# under the License. |
| 18 | +# |
| 19 | + |
| 20 | +set -e |
| 21 | + |
| 22 | +# load environment parameters |
| 23 | +. ./script/env.sh |
| 24 | + |
| 25 | +# load ip list |
| 26 | +. ./script/load_config.sh $1 |
| 27 | + |
| 28 | +script_path=${BAZEL_WORKSPACE_PATH}/scripts |
| 29 | + |
| 30 | +if [[ -z $server ]]; |
| 31 | +then |
| 32 | +server=//service/kv:kv_service |
| 33 | +fi |
| 34 | + |
| 35 | +# obtain the src path |
| 36 | +main_folder=resilientdb_app |
| 37 | +server_path=`echo "$server" | sed 's/:/\//g'` |
| 38 | +server_path=${server_path:1} |
| 39 | +server_name=`echo "$server" | awk -F':' '{print $NF}'` |
| 40 | +server_bin=${server_name} |
| 41 | +grafna_port=8090 |
| 42 | + |
| 43 | +bin_path=${BAZEL_WORKSPACE_PATH}/bazel-bin/${server_path} |
| 44 | +output_path=${script_path}/deploy/config_out |
| 45 | +output_key_path=${output_path}/cert |
| 46 | +output_cert_path=${output_key_path} |
| 47 | +export home_path=${script_path}/deploy |
| 48 | + |
| 49 | +admin_key_path=${script_path}/deploy/data/cert |
| 50 | + |
| 51 | +rm -rf ${output_path} |
| 52 | +mkdir -p ${output_path} |
| 53 | + |
| 54 | +deploy_iplist=${iplist[@]} |
| 55 | + |
| 56 | + |
| 57 | +echo "server src path:"${server_path} |
| 58 | +echo "server bazel bin path:"${bin_path} |
| 59 | +echo "server name:"${server_bin} |
| 60 | +echo "admin config path:"${admin_key_path} |
| 61 | +echo "output path:"${output_path} |
| 62 | +echo "deploy to :"${deploy_iplist[@]} |
| 63 | + |
| 64 | +# generate keys and certificates. |
| 65 | + |
| 66 | +cd ${script_path} |
| 67 | +echo "where am i:"$PWD |
| 68 | + |
| 69 | +deploy/script/generate_admin_key.sh ${BAZEL_WORKSPACE_PATH} ${admin_key_path} |
| 70 | +deploy/script/generate_key.sh ${BAZEL_WORKSPACE_PATH} ${output_key_path} ${#iplist[@]} |
| 71 | +deploy/script/generate_config.sh ${BAZEL_WORKSPACE_PATH} ${output_key_path} ${output_cert_path} ${output_path} ${admin_key_path} ${deploy_iplist[@]} |
| 72 | + |
| 73 | +# build kv server |
| 74 | +bazel build ${server} |
| 75 | + |
| 76 | +if [ $? != 0 ] |
| 77 | +then |
| 78 | + echo "Complile ${server} failed" |
| 79 | + exit 0 |
| 80 | +fi |
| 81 | + |
| 82 | +# commands functions |
| 83 | +function run_cmd(){ |
| 84 | + echo "run cmd:"$1 |
| 85 | + count=1 |
| 86 | + idx=1 |
| 87 | + for ip in ${deploy_iplist[@]}; |
| 88 | + do |
| 89 | + cd ${home_path}/${main_folder}/$idx; |
| 90 | + `$1` |
| 91 | + ((count++)) |
| 92 | + ((idx++)) |
| 93 | + done |
| 94 | + |
| 95 | + while [ $count -gt 0 ]; do |
| 96 | + wait $pids |
| 97 | + count=`expr $count - 1` |
| 98 | + done |
| 99 | +} |
| 100 | + |
| 101 | +function run_one_cmd(){ |
| 102 | + echo "run one:"$1 |
| 103 | + $1 |
| 104 | +} |
| 105 | + |
| 106 | +run_cmd "killall -9 ${server_bin}" |
| 107 | +if [ $performance ]; |
| 108 | +then |
| 109 | +run_cmd "rm -rf ${home_path}/${main_folder}" |
| 110 | +fi |
| 111 | + |
| 112 | +idx=1 |
| 113 | +for ip in ${deploy_iplist[@]}; |
| 114 | +do |
| 115 | + run_one_cmd "mkdir -p ${home_path}/${main_folder}/$idx" & |
| 116 | + ((count++)) |
| 117 | + ((idx++)) |
| 118 | +done |
| 119 | + |
| 120 | + |
| 121 | +# upload config files and binary |
| 122 | +echo "upload configs" |
| 123 | +idx=1 |
| 124 | +count=0 |
| 125 | +for ip in ${deploy_iplist[@]}; |
| 126 | +do |
| 127 | + echo "cp -r ${bin_path} ${output_path}/server.config ${output_path}/cert ${home_path}/${main_folder}/$idx" |
| 128 | + cp -r ${bin_path} ${output_path}/server.config ${output_path}/cert ${home_path}/${main_folder}/$idx & |
| 129 | + ((count++)) |
| 130 | + ((idx++)) |
| 131 | +done |
| 132 | + |
| 133 | +while [ $count -gt 0 ]; do |
| 134 | + wait $pids |
| 135 | + count=`expr $count - 1` |
| 136 | +done |
| 137 | + |
| 138 | +echo "start to run" $PWD |
| 139 | +# Start server |
| 140 | +idx=1 |
| 141 | +count=0 |
| 142 | +for ip in ${deploy_iplist[@]}; |
| 143 | +do |
| 144 | + private_key="cert/node_"${idx}".key.pri" |
| 145 | + cert="cert/cert_"${idx}".cert" |
| 146 | + cd ${home_path}/${main_folder}/$idx; nohup ./${server_bin} server.config ${private_key} ${cert} ${grafna_port} > ${server_bin}.log 2>&1 & |
| 147 | + ((count++)) |
| 148 | + ((idx++)) |
| 149 | + ((grafna_port++)) |
| 150 | +done |
| 151 | + |
| 152 | +# Check ready logs |
| 153 | +idx=1 |
| 154 | +for ip in ${deploy_iplist[@]}; |
| 155 | +do |
| 156 | + resp="" |
| 157 | + while [ "$resp" = "" ] |
| 158 | + do |
| 159 | + cd ${home_path}/${main_folder}/$idx; |
| 160 | + resp=`grep "receive public size:${#iplist[@]}" ${server_bin}.log` |
| 161 | + if [ "$resp" = "" ]; then |
| 162 | + sleep 1 |
| 163 | + fi |
| 164 | + done |
| 165 | + ((idx++)) |
| 166 | +done |
| 167 | + |
| 168 | +echo "Servers are running....." |
| 169 | + |
0 commit comments