avoid race condition between dataimport and mysql
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/c2d55a18 Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/c2d55a18 Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/c2d55a18 Branch: refs/heads/master Commit: c2d55a18bf979af6e68aab96467557c12004057c Parents: d5552db Author: Dan Kirkwood <dang...@gmail.com> Authored: Tue Dec 13 17:36:41 2016 +0000 Committer: Dan Kirkwood <dang...@gmail.com> Committed: Sun Jan 8 21:05:01 2017 -0700 ---------------------------------------------------------------------- .../app/db/pg-migration/Dockerfile-mysql | 19 ++++++++++++++ .../app/db/pg-migration/docker-compose.yml | 8 +++--- traffic_ops/app/db/pg-migration/get-to-data.sh | 10 ++++++++ traffic_ops/app/db/pg-migration/mysql.env | 1 + traffic_ops/app/db/pg-migration/mysql_host.yml | 4 ++- traffic_ops/app/db/pg-migration/postgres.env | 2 +- traffic_ops/app/db/pg-migration/runmysql.sh | 27 ++++++++++++++++++++ 7 files changed, 64 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/c2d55a18/traffic_ops/app/db/pg-migration/Dockerfile-mysql ---------------------------------------------------------------------- diff --git a/traffic_ops/app/db/pg-migration/Dockerfile-mysql b/traffic_ops/app/db/pg-migration/Dockerfile-mysql new file mode 100644 index 0000000..a4bf51f --- /dev/null +++ b/traffic_ops/app/db/pg-migration/Dockerfile-mysql @@ -0,0 +1,19 @@ +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +FROM mysql:5.6 + +MAINTAINER Dan Kirkwood + +ADD runmysql.sh / +CMD /runmysql.sh http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/c2d55a18/traffic_ops/app/db/pg-migration/docker-compose.yml ---------------------------------------------------------------------- diff --git a/traffic_ops/app/db/pg-migration/docker-compose.yml b/traffic_ops/app/db/pg-migration/docker-compose.yml index b611f75..a9d9d85 100644 --- a/traffic_ops/app/db/pg-migration/docker-compose.yml +++ b/traffic_ops/app/db/pg-migration/docker-compose.yml @@ -23,9 +23,8 @@ services: service: dataimport file: dataimport.yml volumes: - - ./mysql/initdb.d:/docker-entrypoint-initdb.d - volumes: - sync:/sync + - ./mysql/initdb.d:/docker-entrypoint-initdb.d # mysql_host loads mysql data locally and provides direct access for pgloader mysql: @@ -51,11 +50,10 @@ services: depends_on: - mysql volumes: - - /opt/traffic_ops-db:/var/lib/postgresql/data + - sync:/sync + - ./db:/var/lib/postgresql/data ports: - 5432 - volumes: - - sync:/sync # pgloader converts the data from mysql to postgres pgloader: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/c2d55a18/traffic_ops/app/db/pg-migration/get-to-data.sh ---------------------------------------------------------------------- diff --git a/traffic_ops/app/db/pg-migration/get-to-data.sh b/traffic_ops/app/db/pg-migration/get-to-data.sh index c1be98a..fd9f739 100755 --- a/traffic_ops/app/db/pg-migration/get-to-data.sh +++ b/traffic_ops/app/db/pg-migration/get-to-data.sh @@ -26,3 +26,13 @@ CREDS curl -k -H "Accept: application/json" --cookie "$cookiejar" --cookie-jar "$cookiejar" -X POST --data @"$cred" "$TO_SERVER/api/1.2/user/login" curl $output -k -s --cookie "$cookiejar" -X GET "$TO_SERVER/dbdump" + +waiting=/sync/waiting-for-dataimport +while [[ ! -f $waiting ]]; do + # wait for signal that other container is waiting + echo "Data import finished.." + sleep 3 +done + +# signal to waiting container that we're finished +rm $waiting http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/c2d55a18/traffic_ops/app/db/pg-migration/mysql.env ---------------------------------------------------------------------- diff --git a/traffic_ops/app/db/pg-migration/mysql.env b/traffic_ops/app/db/pg-migration/mysql.env index b6cba06..de12f7d 100644 --- a/traffic_ops/app/db/pg-migration/mysql.env +++ b/traffic_ops/app/db/pg-migration/mysql.env @@ -1,4 +1,5 @@ MYSQL_DATABASE=traffic_ops_db +MYSQL_HOST=mysql MYSQL_RANDOM_ROOT_PASSWORD=yes MYSQL_PASSWORD=twelve MYSQL_USER=to_user http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/c2d55a18/traffic_ops/app/db/pg-migration/mysql_host.yml ---------------------------------------------------------------------- diff --git a/traffic_ops/app/db/pg-migration/mysql_host.yml b/traffic_ops/app/db/pg-migration/mysql_host.yml index e7be262..59d0b9b 100644 --- a/traffic_ops/app/db/pg-migration/mysql_host.yml +++ b/traffic_ops/app/db/pg-migration/mysql_host.yml @@ -15,6 +15,8 @@ version: '2' services: mysql_host: - image: mysql:5.6 + build: + context: . + dockerfile: Dockerfile-mysql env_file: - mysql.env http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/c2d55a18/traffic_ops/app/db/pg-migration/postgres.env ---------------------------------------------------------------------- diff --git a/traffic_ops/app/db/pg-migration/postgres.env b/traffic_ops/app/db/pg-migration/postgres.env index dbd85cd..3e3c636 100644 --- a/traffic_ops/app/db/pg-migration/postgres.env +++ b/traffic_ops/app/db/pg-migration/postgres.env @@ -1,4 +1,4 @@ -POSTGRES_HOST=postgres_host +POSTGRES_HOST=postgres POSTGRES_DB=traffic_ops POSTGRES_PASSWORD=twelve POSTGRES_USER=traffic_ops http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/c2d55a18/traffic_ops/app/db/pg-migration/runmysql.sh ---------------------------------------------------------------------- diff --git a/traffic_ops/app/db/pg-migration/runmysql.sh b/traffic_ops/app/db/pg-migration/runmysql.sh new file mode 100755 index 0000000..58185f7 --- /dev/null +++ b/traffic_ops/app/db/pg-migration/runmysql.sh @@ -0,0 +1,27 @@ +#!/bin/bash -x +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +waiting=/sync/waiting-for-dataimport +touch $waiting + +# Wait for pgloader to finish +while [[ -f $waiting ]]; do + ls -l $waiting + sleep 3 +done + +echo "Looks like dataimport is finished.. Starting mysql..." + +docker-entrypoint.sh mysqld