Skip to content

Commit

Permalink
Always configure both proxysql schedulers
Browse files Browse the repository at this point in the history
  • Loading branch information
tplavcic committed Oct 17, 2022
1 parent c4b5aec commit 9bf2f91
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 48 deletions.
88 changes: 40 additions & 48 deletions proxysql/dockerdir/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,23 @@
set -o xtrace

PROXY_CFG=/etc/proxysql/proxysql.cnf
if [ "${SCHEDULER}" == "percona" ]; then
PROXY_SCHEDULER_CFG=/etc/config.toml
temp_proxy_scheduler_cfg=$(mktemp)
else
PROXY_SCHEDULER_CFG=/etc/proxysql-admin.cnf
fi
# Percona scheduler
PERCONA_SCHEDULER_CFG=/etc/config.toml
temp_proxy_scheduler_cfg=$(mktemp)
# proxysql-admin scheduler
PROXY_SCHEDULER_CFG=/etc/proxysql-admin.cnf

if [ -n ${PROXYSQL_SERVICE} ]; then
MYSQL_INTERFACES='0.0.0.0:3306;0.0.0.0:33062'
CLUSTER_PORT='33062'
if [ "${SCHEDULER}" == "percona" ]; then
sed "s/^writerIsAlsoReader.*=.*$/writerIsAlsoReader = 1/" ${PROXY_SCHEDULER_CFG} | \
sed "s/^hgW.*=.*$/hgW = 11/" | \
sed "s/^hgR.*=.*$/hgR = 10/" | \
sed "s/^clustered.*=.*false$/clustered = true/" > ${temp_proxy_scheduler_cfg}
cp ${temp_proxy_scheduler_cfg} ${PROXY_SCHEDULER_CFG}
else
sed "s/#export WRITERS_ARE_READERS=.*$/export WRITERS_ARE_READERS='yes'/g" ${PROXY_SCHEDULER_CFG} 1<> ${PROXY_SCHEDULER_CFG}
fi
# Percona scheduler
sed "s/^writerIsAlsoReader.*=.*$/writerIsAlsoReader = 1/" ${PROXY_SCHEDULER_CFG} | \
sed "s/^hgW.*=.*$/hgW = 11/" | \
sed "s/^hgR.*=.*$/hgR = 10/" | \
sed "s/^clustered.*=.*false$/clustered = true/" > ${temp_proxy_scheduler_cfg}
cp ${temp_proxy_scheduler_cfg} ${PROXY_SCHEDULER_CFG}
# proxysql-admin scheduler
sed "s/#export WRITERS_ARE_READERS=.*$/export WRITERS_ARE_READERS='yes'/g" ${PROXY_SCHEDULER_CFG} 1<> ${PROXY_SCHEDULER_CFG}
fi

sed "s/interfaces=\"0.0.0.0:3306\"/interfaces=\"${MYSQL_INTERFACES:-0.0.0.0:3306}\"/g" ${PROXY_CFG} 1<> ${PROXY_CFG}
Expand All @@ -38,24 +36,23 @@ sed "s/cluster_username=\"admin\"/cluster_username=\"${PROXY_ADMIN_USER:-admin}\
sed "s/cluster_password=\"admin\"/cluster_password=\"${PROXY_ADMIN_PASSWORD:-admin}\"/g" ${PROXY_CFG} 1<> ${PROXY_CFG}
sed "s/monitor_password=\"monitor\"/monitor_password=\"${MONITOR_PASSWORD:-monitor}\"/g" ${PROXY_CFG} 1<> ${PROXY_CFG}

if [ "${SCHEDULER}" == "percona" ]; then
sed "s/^user.*=.*\"$/user = '${PROXY_ADMIN_USER:-admin}'/" ${PROXY_SCHEDULER_CFG} | \
sed "s/^password.*=.*\"$/password = '${PROXY_ADMIN_PASSWORD_ESCAPED:-admin}'/" | \
sed "s/^clusterUserPassword.*=.*\"$/clusterUserPassword='${OPERATOR_PASSWORD_ESCAPED:-operator}'/" | \
sed "s/^clusterUser.*=.*\"$/clusterUser = 'operator'/" | \
sed "s/^clusterPort.*=.*\"$/clusterPort='${CLUSTER_PORT:-3306}'/" | \
sed "s/^monitorUserPassword.*=.*\"$/monitorUserPassword='${MONITOR_PASSWORD_ESCAPED:-monitor}'/" | \
sed "s/^monitorUser.*=.*\"$/monitorUser='monitor'/" > ${temp_proxy_scheduler_cfg}
cp ${temp_proxy_scheduler_cfg} ${PROXY_SCHEDULER_CFG}
else
sed "s/PROXYSQL_USERNAME='admin'/PROXYSQL_USERNAME='${PROXY_ADMIN_USER:-admin}'/g" ${PROXY_SCHEDULER_CFG} 1<> ${PROXY_SCHEDULER_CFG}
sed "s/PROXYSQL_PASSWORD='admin'/PROXYSQL_PASSWORD='${PROXY_ADMIN_PASSWORD_ESCAPED:-admin}'/g" ${PROXY_SCHEDULER_CFG} 1<> ${PROXY_SCHEDULER_CFG}
sed "s/CLUSTER_USERNAME='admin'/CLUSTER_USERNAME='operator'/g" ${PROXY_SCHEDULER_CFG} 1<> ${PROXY_SCHEDULER_CFG}
sed "s/CLUSTER_PASSWORD='admin'/CLUSTER_PASSWORD='${OPERATOR_PASSWORD_ESCAPED:-operator}'/g" ${PROXY_SCHEDULER_CFG} 1<> ${PROXY_SCHEDULER_CFG}
sed "s/CLUSTER_PORT='3306'/CLUSTER_PORT='${CLUSTER_PORT:-3306}'/g" ${PROXY_SCHEDULER_CFG} 1<> ${PROXY_SCHEDULER_CFG}
sed "s/MONITOR_USERNAME='monitor'/MONITOR_USERNAME='monitor'/g" ${PROXY_SCHEDULER_CFG} 1<> ${PROXY_SCHEDULER_CFG}
sed "s/MONITOR_PASSWORD='monitor'/MONITOR_PASSWORD='${MONITOR_PASSWORD_ESCAPED:-monitor}'/g" ${PROXY_SCHEDULER_CFG} 1<> ${PROXY_SCHEDULER_CFG}
fi
# Percona scheduler
sed "s/^user.*=.*\"$/user = '${PROXY_ADMIN_USER:-admin}'/" ${PERCONA_SCHEDULER_CFG} | \
sed "s/^password.*=.*\"$/password = '${PROXY_ADMIN_PASSWORD_ESCAPED:-admin}'/" | \
sed "s/^clusterUserPassword.*=.*\"$/clusterUserPassword='${OPERATOR_PASSWORD_ESCAPED:-operator}'/" | \
sed "s/^clusterUser.*=.*\"$/clusterUser = 'operator'/" | \
sed "s/^clusterPort.*=.*\"$/clusterPort='${CLUSTER_PORT:-3306}'/" | \
sed "s/^monitorUserPassword.*=.*\"$/monitorUserPassword='${MONITOR_PASSWORD_ESCAPED:-monitor}'/" | \
sed "s/^monitorUser.*=.*\"$/monitorUser='monitor'/" > ${temp_proxy_scheduler_cfg}
cp ${temp_proxy_scheduler_cfg} ${PERCONA_SCHEDULER_CFG}
# proxysql-admin scheduler
sed "s/PROXYSQL_USERNAME='admin'/PROXYSQL_USERNAME='${PROXY_ADMIN_USER:-admin}'/g" ${PROXY_SCHEDULER_CFG} 1<> ${PROXY_SCHEDULER_CFG}
sed "s/PROXYSQL_PASSWORD='admin'/PROXYSQL_PASSWORD='${PROXY_ADMIN_PASSWORD_ESCAPED:-admin}'/g" ${PROXY_SCHEDULER_CFG} 1<> ${PROXY_SCHEDULER_CFG}
sed "s/CLUSTER_USERNAME='admin'/CLUSTER_USERNAME='operator'/g" ${PROXY_SCHEDULER_CFG} 1<> ${PROXY_SCHEDULER_CFG}
sed "s/CLUSTER_PASSWORD='admin'/CLUSTER_PASSWORD='${OPERATOR_PASSWORD_ESCAPED:-operator}'/g" ${PROXY_SCHEDULER_CFG} 1<> ${PROXY_SCHEDULER_CFG}
sed "s/CLUSTER_PORT='3306'/CLUSTER_PORT='${CLUSTER_PORT:-3306}'/g" ${PROXY_SCHEDULER_CFG} 1<> ${PROXY_SCHEDULER_CFG}
sed "s/MONITOR_USERNAME='monitor'/MONITOR_USERNAME='monitor'/g" ${PROXY_SCHEDULER_CFG} 1<> ${PROXY_SCHEDULER_CFG}
sed "s/MONITOR_PASSWORD='monitor'/MONITOR_PASSWORD='${MONITOR_PASSWORD_ESCAPED:-monitor}'/g" ${PROXY_SCHEDULER_CFG} 1<> ${PROXY_SCHEDULER_CFG}

set -o xtrace

Expand All @@ -67,18 +64,14 @@ fi
SSL_DIR=${SSL_DIR:-/etc/proxysql/ssl}
if [ -f "${SSL_DIR}/ca.crt" ]; then
CA=${SSL_DIR}/ca.crt
if [ "${SCHEDULER}" == "percona" ]; then
sed "s:^sslCertificatePath.*= .*\"$:sslCertificatePath = \"${SSL_DIR}\":" ${PROXY_SCHEDULER_CFG} > ${temp_proxy_scheduler_cfg}
cp ${temp_proxy_scheduler_cfg} ${PROXY_SCHEDULER_CFG}
fi
sed "s:^sslCertificatePath.*= .*\"$:sslCertificatePath = \"${SSL_DIR}\":" ${PERCONA_SCHEDULER_CFG} > ${temp_proxy_scheduler_cfg}
cp ${temp_proxy_scheduler_cfg} ${PERCONA_SCHEDULER_CFG}
fi
SSL_INTERNAL_DIR=${SSL_INTERNAL_DIR:-/etc/proxysql/ssl-internal}
if [ -f "${SSL_INTERNAL_DIR}/ca.crt" ]; then
CA=${SSL_INTERNAL_DIR}/ca.crt
if [ "${SCHEDULER}" == "percona" ]; then
sed "s:^sslCertificatePath.*= .*\"$:sslCertificatePath = \"${SSL_INTERNAL_DIR}\":" ${PROXY_SCHEDULER_CFG} > ${temp_proxy_scheduler_cfg}
cp ${temp_proxy_scheduler_cfg} ${PROXY_SCHEDULER_CFG}
fi
sed "s:^sslCertificatePath.*= .*\"$:sslCertificatePath = \"${SSL_INTERNAL_DIR}\":" ${PERCONA_SCHEDULER_CFG} > ${temp_proxy_scheduler_cfg}
cp ${temp_proxy_scheduler_cfg} ${PERCONA_SCHEDULER_CFG}
fi

KEY=${SSL_DIR}/tls.key
Expand All @@ -94,13 +87,12 @@ if [ -f "$CA" ] && [ -f "$KEY" ] && [ -f "$CERT" ] && [ -n "$PXC_SERVICE" ]; the
sed "s^ssl_p2s_ca=\"\"^ssl_p2s_ca=\"$CA\"^" ${PROXY_CFG} 1<> ${PROXY_CFG}
sed "s^ssl_p2s_key=\"\"^ssl_p2s_key=\"$KEY\"^" ${PROXY_CFG} 1<> ${PROXY_CFG}
sed "s^ssl_p2s_cert=\"\"^ssl_p2s_cert=\"$CERT\"^" ${PROXY_CFG} 1<> ${PROXY_CFG}
if [ "${SCHEDULER}" == "percona" ]; then
sed "s:^sslCa.*=.*\"$:sslCa = \"${CA##*/}\":" ${PROXY_SCHEDULER_CFG} | \
sed "s:^sslKey.*=.*\"$:sslKey = \"${KEY##*/}\":" | \
sed "s:^sslClient.*=.*\"$:sslClient = \"${CERT##*/}\":" > ${temp_proxy_scheduler_cfg}
cp ${temp_proxy_scheduler_cfg} ${PROXY_SCHEDULER_CFG}
rm ${temp_proxy_scheduler_cfg}
fi
# Percona scheduler
sed "s:^sslCa.*=.*\"$:sslCa = \"${CA##*/}\":" ${PERCONA_SCHEDULER_CFG} | \
sed "s:^sslKey.*=.*\"$:sslKey = \"${KEY##*/}\":" | \
sed "s:^sslClient.*=.*\"$:sslClient = \"${CERT##*/}\":" > ${temp_proxy_scheduler_cfg}
cp ${temp_proxy_scheduler_cfg} ${PERCONA_SCHEDULER_CFG}
rm ${temp_proxy_scheduler_cfg}
fi

if [ -f "${SSL_DIR}/tls.key" ] && [ -f "${SSL_DIR}/tls.crt" ]; then
Expand Down
4 changes: 4 additions & 0 deletions proxysql/dockerdir/usr/bin/add_pxc_nodes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ function main() {
sed "s/^clusterHost.*=.*\"$/clusterHost=\"$first_host\"/" /etc/config.toml > ${temp} && cp ${temp} /etc/config.toml
rm ${temp}

proxysql-admin --config-file=/etc/proxysql-admin.cnf --disable || true

percona-scheduler-admin \
--config-file=/etc/config.toml \
--write-node="$pod_zero.$service:3306" \
Expand All @@ -89,6 +91,8 @@ function main() {
--config-file=/etc/config.toml \
--update-mysql-version
else
percona-scheduler-admin --config-file=/etc/config.toml --disable || true

proxysql-admin \
--config-file=/etc/proxysql-admin.cnf \
--cluster-hostname="$first_host" \
Expand Down

0 comments on commit 9bf2f91

Please sign in to comment.