Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
open-source
docker-pxc
Commits
478c8e7a
Commit
478c8e7a
authored
Feb 06, 2018
by
Fabio Montefuscolo
Browse files
MySQLd passou a rodar
parent
aa7394e4
Pipeline
#2949
passed with stage
in 5 minutes and 23 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
145 additions
and
17 deletions
+145
-17
.gitignore
.gitignore
+1
-0
Dockerfile
Dockerfile
+3
-3
entrypoint/discovery_etcd.sh
entrypoint/discovery_etcd.sh
+9
-7
entrypoint/info_server.sh
entrypoint/info_server.sh
+71
-0
entrypoint/main.sh
entrypoint/main.sh
+61
-7
No files found.
.gitignore
0 → 100644
View file @
478c8e7a
*.swp
Dockerfile
View file @
478c8e7a
...
...
@@ -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"]
entrypoint/discovery_etcd.sh
View file @
478c8e7a
#!/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
}
entrypoint/info_server.sh
0 → 100755
View file @
478c8e7a
#!/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
entrypoint/main.sh
View file @
478c8e7a
#!/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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment