Commit 4f21f91a authored by Fabio Montefuscolo's avatar Fabio Montefuscolo
Browse files

add rancher discovery

parent 7cb62aee
Pipeline #2951 passed with stage
in 1 minute and 4 seconds
#!/bin/bash
get_cluster_addresses () {
curl -s --header 'Accept: application/json' \
http://rancher-metadata/2016-07-29/self/service/containers \
| jq -r '.[].primary_ip'
}
......@@ -22,6 +22,26 @@ info_error () {
echo "";
}
info_score () {
score=0
ip=$(hostname -i)
if echo 1 > /dev/tcp/127.0.0.1/3306;
then
score=$(( $score + 2 ))
fi
value=$(awk '/^seqno:/{ print $2 }' "${PXC_DATA}/grastate.dat" 2>&-)
value="${value:--1}"
score=$(( $score + $value ))
value="${ip##*.}"
value="${value:-0}"
score=$(( $value + $score * 1000 ))
echo $score
}
info_get () {
case "$@" in
"/ip")
......@@ -32,13 +52,8 @@ info_get () {
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
"/score")
info_answer "$(info_score)"
;;
*)
......
#!/bin/bash
set -v
MY_IP=$(hostname -i | awk '{ print $1 }')
if [ -z "${CLUSTER_NAME}" ];
......@@ -25,6 +24,10 @@ then
then
source /entrypoint/discovery_etcd.sh
register_me_on_queue;
elif curl -sI http://rancher-metadata > /dev/null;
then
source /entrypoint/discovery_rancher.sh
fi
CLUSTER_JOIN=$(get_cluster_addresses | sed -Eze 's/^\s*//;s/\s*$//;s/\s+/,/g')
......@@ -34,30 +37,46 @@ fi
IFS=","
online=""
current=""
leader=""
for ip in $CLUSTER_JOIN;
do
if ping -n -c1 -W1 $ip >&-;
if ping -c2 -i5 -W1 $ip;
then
if [ -z "$online" ];
if [ "$ip" != "$MY_IP" ];
then
if [ -z "$online" ];
then
online="$ip"
else
online="$online,$ip"
fi
fi
score=$(curl -v http://$ip:8888/score)
if [ -z "$current" ] || [[ "$score" -gt "$current" ]];
then
online="$ip"
else
online="$online,$ip"
current=$score
leader=$ip
fi
fi
done
IFS="
"
echo "#
# My IP: $MY_IP
# Detected IPs: $online
# Leader: $leader
#"
if [ "$(basename $1)" = "mysqld" ];
then
rm "${MYSQL_LOG_FILE}"
mkfifo -m 777 "${MYSQL_LOG_FILE}"
cat "${MYSQL_LOG_FILE}" &
set -- "$@" "--user=mysql"
set -- "$@" "--log-bin=$CLUSTER_NAME-bin"
set -- "$@" "--explicit_defaults_for_timestamp=on"
set -- "$@" "--wsrep_cluster_name=$CLUSTER_NAME"
set -- "$@" "--wsrep_sst_method=xtrabackup-v2"
set -- "$@" "--wsrep_cluster_address=gcomm://$online"
......
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