Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for arbitrary URLs and some error checking #290

Merged
merged 2 commits into from
May 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 30 additions & 13 deletions scripts/manual_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
# - deploy_replication <num_nodes> <base_port>: deploy a replication setup
# - exec_mysql_sock <name> <query>: execute a query on a MySQL server

set -xe

setup() {
local cmd=()
if (( UID != 0 ))
Expand All @@ -25,6 +23,9 @@ setup() {
ca-certificates
libaio1
libnuma1
libncurses5
libncurses6
netcat
wget
sudo
xz-utils
Expand Down Expand Up @@ -55,18 +56,23 @@ activate() {
return 1
fi

minor_version="${version%.*}"

printf -v filename "mysql-%s-linux-glibc2.28-x86_64.tar.xz" "$version"
printf -v url "https://dev.mysql.com/get/Downloads/MySQL-%s/%s" "$minor_version" "$filename"
dirname="${filename%.tar.xz}"
if [[ $version = http* ]]; then
url=$version
filename="${url##*/}"
dirname="${filename%.tar.xz}"
else
minor_version="${version%.*}"
printf -v filename "mysql-%s-linux-glibc2.28-x86_64.tar.xz" "$version"
printf -v url "https://dev.mysql.com/get/Downloads/MySQL-%s/%s" "$minor_version" "$filename"
dirname="${filename%.tar.xz}"
fi

if [[ -d $dirname ]]; then
pushd "$dirname"
return
fi
if [[ ! -f $filename ]]; then
wget "$url"
wget "$url" || return
fi
tar -xf "$filename"
pushd "$dirname"
Expand Down Expand Up @@ -97,6 +103,8 @@ start_mysql() {
server_id=$3
fi

check_port "$port" || return

"${mysql_cmd[@]}" --datadir="$datadir" --port="$port" --server-id="$server_id" &

pid=$!
Expand Down Expand Up @@ -135,7 +143,7 @@ deploy_replication() {
fi

initialize_mysql primary
start_mysql primary "$base_port"
start_mysql primary "$base_port" || return

exec_mysql_sock primary "CREATE USER 'repl'@'%' IDENTIFIED BY 'replica'"
exec_mysql_sock primary "GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%'"
Expand All @@ -147,18 +155,27 @@ deploy_replication() {
do
name="replica$i"
port=$((base_port + i))
initialize_mysql "$name"
start_mysql "$name" "$port" "$(( 100 + i ))"
initialize_mysql "$name" || continue
start_mysql "$name" "$port" "$(( 100 + i ))" || continue
exec_mysql_sock "$name" "CHANGE REPLICATION SOURCE TO SOURCE_HOST='127.0.0.1', SOURCE_PORT=$base_port, GET_SOURCE_PUBLIC_KEY=1"
exec_mysql_sock "$name" "START REPLICA USER='repl' PASSWORD='replica'"
done
}

exec_mysql_sock() {
local datadir=data
if [[ $1 ]]; then
if [[ $2 ]]; then
datadir="data-$1"
shift
fi
./bin/mysql -u root -S "$datadir/mysql.sock" -e "$2"

./bin/mysql -u root -S "$datadir/mysql.sock" -e "$1"
}

check_port() {
local port=$1
if nc -w0 -z localhost "$port" </dev/null >/dev/null; then
printf %s\\n "Port $port is in use" >&2
return 1
fi
}
Loading