k8s-manifests/ops/110-native-mysql/install-replica.sh

34 lines
1009 B
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
if [[ $EUID -ne 0 || $# -ne 1 ]]; then
echo "usage: sudo $0 <mysql-config.cnf>" >&2
exit 2
fi
config_file=$(realpath "$1")
config_target=/etc/mysql/mysql.conf.d/zz-mes-prd.cnf
if [[ ! -s $config_file ]]; then
echo "config file is missing or empty: $config_file" >&2
exit 2
fi
if ss -ltnH 'sport = :3306' | grep -q .; then
echo "TCP port 3306 is already in use; refusing to continue" >&2
exit 1
fi
if dpkg-query -W mysql-server-8.0 >/dev/null 2>&1; then
echo "mysql-server-8.0 is already installed; refusing to reinitialize it" >&2
exit 1
fi
apt-get update
NEEDRESTART_MODE=l DEBIAN_FRONTEND=noninteractive apt-get install -y mysql-common
install -d -m 0755 /etc/mysql/mysql.conf.d
sed -e '/^read_only=/d' -e '/^super_read_only=/d' "$config_file" \
> "$config_target"
chmod 0644 "$config_target"
NEEDRESTART_MODE=l DEBIAN_FRONTEND=noninteractive apt-get install -y mysql-server
"$(dirname "$(realpath "$0")")/apply-replica-config.sh" "$config_file"