Commit 478c8e7a authored by Fabio Montefuscolo's avatar Fabio Montefuscolo
Browse files

MySQLd passou a rodar

parent aa7394e4
Pipeline #2949 passed with stage
in 5 minutes and 23 seconds
......@@ -16,7 +16,7 @@ ENV MYSQL_LOG_FILE=/var/log/mysqld.log
RUN groupadd -r mysql && useradd -r -m -d "${PXC_HOME}" -g mysql mysql \
&& apt-get update \
&& apt-get install -y curl jq \
&& apt-get install -y curl jq netcat \
&& curl -sLo pxc.deb https://repo.percona.com/apt/percona-release_0.1-5.jessie_all.deb \
&& dpkg -i pxc.deb \
&& apt-get update \
......@@ -55,6 +55,6 @@ VOLUME ["${PXC_DATA}","${PXC_RUN}"]
EXPOSE 3306 4567 4568
COPY entrypoint /entrypoint
ENTRYPOINT ["/entrypoint/main.sh"]
ENTRYPOINT ["/bin/bash", "/entrypoint/main.sh"]
CMD ["mysqld", "--user=mysql", "--wsrep_sst_method=xtrabackup-v2"]
CMD ["/usr/sbin/mysqld", "--user=mysql"]
#!/bin/bash
BASE_URL="http://$ETCD_HOST/v2/keys/pxc-cluster"
MY_IP=$(hostname -i | awk '{ print $1 }')
TTL=60
register_me_on_queue () {
curl -sS "${BASE_URL}/queue/$CLUSTER_NAME" -XPOST -d value=$MY_IP -d ttl=$TTL \
| jq '.' \
| tee /dev/stderr
| jq '.'
}
register_me_on_quorum () {
......@@ -18,17 +17,20 @@ register_me_on_quorum () {
get_queue_addresses () {
curl -sS "${BASE_URL}/queue/$CLUSTER_NAME" \
| jq ".node.nodes[] | select(.value != \"$MY_IP\") .value" \
| tee /dev/stderr
| jq -r ".node.nodes[].value"
}
get_quorum_addresses () {
curl "${BASE_URL}/$CLUSTER_NAME/?quorum=true"
curl -sS "${BASE_URL}/$CLUSTER_NAME/?quorum=true" \
| jq -r '.node.nodes[]?.key' \
| grep -o '[0-9\.]*$'
}
get_cluster_addresses () {
get_queue_addresses;
get_quorum_addresses;
{
get_queue_addresses;
get_quorum_addresses;
} \
| sort -u \
| tee /dev/stderr
}
#!/bin/bash
PROGRAM=$(readlink -f $0)
INFO_PIPE="/tmp/info_pipe"
info_answer () {
shopt -s extglob
message="${@##*( )}"
message="${message%%*( )}"
length="${#message}"
echo "HTTP/1.1 200 OK";
echo "Content-Type: text/plain; charset=utf-8";
echo "Content-Length: $length";
echo "";
echo -e "$message";
}
info_error () {
echo "HTTP/1.1 $@";
echo "Content-Type: text/plain; charset=utf-8";
echo "Content-Length: 0";
echo "";
}
info_get () {
case "$@" in
"/ip")
info_answer "$(hostname -i)"
;;
"/name")
info_answer "$(hostname)"
;;
"/grastate/seqno")
res=$(awk '/^seqno:/{ print $2 }' "${PXC_DATA}/grastate.dat" 2>&-)
if [ -n "$res" ]; then
info_answer "$res"
else
info_error 404 "$@ found"
fi
;;
*)
info_error 404 "Not found"
;;
esac
}
info_parse () {
regex="^GET (/[^ ]*)"
while read line;
do
if [[ "$line" =~ $regex ]];
then
info_get "${BASH_REMATCH[1]}" > "$INFO_PIPE"
else
info_error 405 "Method Not Allowed" > "$INFO_PIPE"
fi
return
done
}
rm -f "$INFO_PIPE"
mkfifo "$INFO_PIPE"
while true;
do
cat "$INFO_PIPE" \
| nc -l -p 8888 > >(info_parse)
done
#!/bin/bash
set -v
MY_IP=$(hostname -i | awk '{ print $1 }')
if [ -z "${CLUSTER_NAME}" ];
......@@ -8,12 +8,14 @@ then
exit 1
fi
source /entrypoint/info_server.sh &
source /entrypoint/bootstrap.sh;
if [ -z "$(ls -A $PXC_DATA)" ];
then
mkdir -m 755 -p "${PXC_DATA}"
chown -R mysql: "${PXC_DATA}"
source /entrypoint/bootstrap.sh;
bootstrap_database
fi
......@@ -29,17 +31,69 @@ then
export CLUSTER_JOIN
fi
latest="-1"
leader=""
online=""
IFS=","
for ip in $CLUSTER_JOIN;
do
if ping -n -c1 -W1 $ip >&-;
then
leader="${leader:-$ip}"
res=$(curl -sS "http://$ip:8888/grastate/seqno")
res="${res:-$latest}"
if [[ "${res}" -gt "$latest" ]];
then
latest="$res"
leader="$ip"
fi
if [ -z "$online" ];
then
online="$ip"
else
online="$online,$ip"
fi
fi
done
IFS="
"
if [ "$(basename $1)" = "mysqld" ];
then
MYSQLD_ARGS=("--wsrep_cluster_name='$CLUSTER_NAME'")
if [ "$leader" = "$MY_IP" ];
then
if [ "$latest" == "-1" ];
then
sed -i -e '/^safe_to_bootstrap/s/0/1/' "${PXC_DATA}/grastate.dat"
fi
MYSQLD_ARGS+=("--wsrep-new-cluster")
MYSQLD_ARGS+=("--wsrep_cluster_address=gcomm://$MY_IP?pc.wait_prim=no")
else
while ! `echo 1 > /dev/tcp/$leader/3306`;
do
echo "Waiting leader $leader";
sleep 5
done
MYSQLD_ARGS+=("--wsrep_cluster_address='gcomm://$online'")
fi
rm "${MYSQL_LOG_FILE}"
mkfifo -m 777 "${MYSQL_LOG_FILE}"
cat "${MYSQL_LOG_FILE}" &
exec "$@" \
--wsrep_cluster_name=$CLUSTER_NAME \
--wsrep_cluster_address="gcomm://$CLUSTER_JOIN" \
--wsrep_sst_auth="xtrabackup:$XTRABACKUP_PASSWORD" \
--wsrep_node_address="$MY_IP"
MYSQLD_ARGS+=("--wsrep_sst_method=xtrabackup-v2")
MYSQLD_ARGS+=("--wsrep_sst_auth='xtrabackup:$XTRABACKUP_PASSWORD'")
MYSQLD_ARGS+=("--wsrep_node_address='$MY_IP'")
echo "$@ $MYSQLD_ARGS" >&2
$@ $MYSQLD_ARGS
else
exec "$@"
fi
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment