2020-04-03 14:37:40 +08:00
|
|
|
set -e
|
|
|
|
|
|
|
|
source x.sh
|
|
|
|
|
|
|
|
CURRENT_PATH=$(pwd)
|
|
|
|
PROJECT_PATH=$(dirname "${CURRENT_PATH}")
|
|
|
|
BUILD_PATH=${CURRENT_PATH}/build
|
|
|
|
APP_VERSION=$(git describe --tag)
|
2020-08-25 20:21:44 +08:00
|
|
|
N=4
|
2020-04-03 14:37:40 +08:00
|
|
|
|
|
|
|
# help prompt message
|
|
|
|
function printHelp() {
|
|
|
|
print_blue "Usage: "
|
2020-08-25 20:21:44 +08:00
|
|
|
echo " deploy.sh [-a <bitxhub_addr>] [-r <if_recompile>] [-u <username>] [-p <build_path>]"
|
2020-04-03 14:37:40 +08:00
|
|
|
echo " - 'a' - the ip address of bitxhub node"
|
|
|
|
echo " - 'r' - if need to recompile locally"
|
|
|
|
echo " - 'u' - the username of remote linux server"
|
|
|
|
echo " - 'p' - the deploy path relative to HOME directory in linux server"
|
|
|
|
echo " deploy.sh -h (print this message)"
|
|
|
|
}
|
|
|
|
|
2020-08-25 20:21:44 +08:00
|
|
|
function splitWindow() {
|
|
|
|
tmux splitw -v -p 50
|
|
|
|
tmux splitw -h -p 50
|
|
|
|
tmux selectp -t 0
|
|
|
|
tmux splitw -h -p 50
|
|
|
|
}
|
|
|
|
|
2020-04-03 14:37:40 +08:00
|
|
|
function deploy() {
|
2020-08-25 20:21:44 +08:00
|
|
|
rm -rf "${BUILD_PATH}"
|
|
|
|
mkdir "${BUILD_PATH}"
|
2020-04-03 14:37:40 +08:00
|
|
|
print_blue "1. Generate config"
|
2020-08-25 20:21:44 +08:00
|
|
|
for ((i = 1; i < $N + 1; i = i + 1)); do
|
|
|
|
root=${BUILD_PATH}/node${i}
|
|
|
|
mkdir -p "${root}"
|
|
|
|
|
|
|
|
cp -rf "${CURRENT_PATH}"/certs/node${i}/certs "${root}"
|
|
|
|
cp -rf "${PROJECT_PATH}"/config/* "${root}"
|
|
|
|
|
|
|
|
echo " #!/usr/bin/env bash" >"${root}"/start.sh
|
|
|
|
echo "./bitxhub --repo \$(pwd)" start >>"${root}"/start.sh
|
|
|
|
x_replace 1s/1/${i}/ ${root}/network.toml
|
|
|
|
done
|
2020-04-03 14:37:40 +08:00
|
|
|
|
|
|
|
print_blue "2. Compile bitxhub"
|
|
|
|
if [[ $IF_RECOMPILE == true ]]; then
|
|
|
|
bash cross_compile.sh linux-amd64 ${PROJECT_PATH}
|
|
|
|
else
|
|
|
|
echo "Do not need compile"
|
|
|
|
fi
|
|
|
|
|
2020-08-25 20:21:44 +08:00
|
|
|
ips=$(echo $SERVER_ADDRESSES | tr "," "\n")
|
2020-04-03 14:37:40 +08:00
|
|
|
## prepare deploy package
|
|
|
|
cd "${CURRENT_PATH}"
|
2020-08-25 20:21:44 +08:00
|
|
|
for ((i = 1; i < $N + 1; i = i + 1)); do
|
|
|
|
root=${BUILD_PATH}/node${i}
|
|
|
|
cp ../bin/bitxhub_linux-amd64 ${root}/bitxhub
|
|
|
|
mkdir -p ${root}/plugins
|
|
|
|
cp ../internal/plugins/build/*.so ${root}/plugins
|
|
|
|
|
|
|
|
j=1
|
|
|
|
for ip in $ips; do
|
|
|
|
x_replace s#ip4/127.0.0.1/tcp/400${j}#ip4/"$ip"/tcp/4001#g ${root}/network.toml
|
|
|
|
((j = j + 1))
|
|
|
|
done
|
|
|
|
done
|
2020-04-03 14:37:40 +08:00
|
|
|
|
|
|
|
print_blue "3. Deploy bitxhub"
|
2020-08-25 20:21:44 +08:00
|
|
|
|
|
|
|
i=1
|
2020-04-03 14:37:40 +08:00
|
|
|
cd "${CURRENT_PATH}"
|
2020-08-25 20:21:44 +08:00
|
|
|
for ip in $ips; do
|
2020-09-29 15:13:05 +08:00
|
|
|
scp -r build/node${i} ${USERNAME}@$ip:~/
|
2020-08-25 20:21:44 +08:00
|
|
|
((i = i + 1))
|
|
|
|
done
|
|
|
|
|
|
|
|
tmux new -d -s deploy || (tmux kill-session -t deploy && tmux new -d -s deploy)
|
|
|
|
|
|
|
|
for ((i = 0; i < $N / 4; i = i + 1)); do
|
|
|
|
splitWindow
|
|
|
|
tmux new-window
|
|
|
|
done
|
|
|
|
splitWindow
|
|
|
|
|
|
|
|
i=0
|
|
|
|
for ip in $ips; do
|
|
|
|
tmux selectw -t $(($i / 4))
|
|
|
|
tmux selectp -t $(($i % 4))
|
|
|
|
((i = i + 1))
|
2020-09-29 15:13:05 +08:00
|
|
|
tmux send-keys "ssh -t $USERNAME@$ip 'export LD_LIBRARY_PATH=\${LD_LIBRARY_PATH}:\${HOME} && cd ~/node${i} && bash start.sh'" C-m
|
2020-08-25 20:21:44 +08:00
|
|
|
done
|
|
|
|
tmux selectw -t 0
|
|
|
|
tmux attach-session -t deploy
|
2020-04-03 14:37:40 +08:00
|
|
|
}
|
|
|
|
|
2020-08-25 20:21:44 +08:00
|
|
|
while getopts "h?a:r:u:p:" opt; do
|
2020-04-03 14:37:40 +08:00
|
|
|
case "$opt" in
|
|
|
|
h | \?)
|
|
|
|
printHelp
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
a)
|
2020-08-25 20:21:44 +08:00
|
|
|
SERVER_ADDRESSES=$OPTARG
|
2020-04-03 14:37:40 +08:00
|
|
|
;;
|
|
|
|
r)
|
|
|
|
IF_RECOMPILE=$OPTARG
|
|
|
|
;;
|
|
|
|
u)
|
|
|
|
USERNAME=$OPTARG
|
|
|
|
;;
|
|
|
|
p)
|
|
|
|
SERVER_BUILD_PATH=/home/${USERNAME}/$OPTARG
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2020-08-25 20:21:44 +08:00
|
|
|
deploy
|