You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by ro...@apache.org on 2019/02/19 23:05:43 UTC

[trafficcontrol] branch master updated: CIAB: Fixed the method of obtaining IP

This is an automated email from the ASF dual-hosted git repository.

rob pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git


The following commit(s) were added to refs/heads/master by this push:
     new 475c5e1  CIAB: Fixed the method of obtaining IP
475c5e1 is described below

commit 475c5e134941449644e2e1aec6d4879a060af99e
Author: Shihta Kuan <sh...@qct.io>
AuthorDate: Wed Jan 30 14:21:12 2019 +0800

    CIAB: Fixed the method of obtaining IP
    
    The sequence of setting DNS record is shown as follows:
    
    1. Set /etc/resolv.conf (infrastructure/cdn-in-a-box/dns/set-dns.sh)
    2. Obtaining IP by "dig +short ${my_host}" (infrastructure/cdn-in-a-box/dns/insert-self-into-dns.sh)
    3. Set DNS record (infrastructure/cdn-in-a-box/dns/insert-self-into-dns.sh)
    
    It can not obtain IP after the /etc/resolv.conf changed.
    This commit provide one way to fix it by changing the method of obtaining IP.
    It uses parsing the ifconfig result instead of dig.
    
    This commit also deletes insert-db-into-dns.sh.
    DB should use insert-self-into-dns.sh instead of insert-db-into-dns.sh as well.
---
 .../cdn-in-a-box/dns/insert-db-into-dns.sh         | 63 ----------------------
 .../cdn-in-a-box/dns/insert-self-into-dns.sh       |  7 ++-
 infrastructure/cdn-in-a-box/docker-compose.yml     |  7 +--
 .../cdn-in-a-box/traffic_ops/Dockerfile-db         |  5 +-
 .../traffic_ops/{Dockerfile-db => run-db.sh}       | 11 ++--
 infrastructure/cdn-in-a-box/traffic_ops/run.sh     |  1 -
 6 files changed, 17 insertions(+), 77 deletions(-)

diff --git a/infrastructure/cdn-in-a-box/dns/insert-db-into-dns.sh b/infrastructure/cdn-in-a-box/dns/insert-db-into-dns.sh
deleted file mode 100755
index 3591579..0000000
--- a/infrastructure/cdn-in-a-box/dns/insert-db-into-dns.sh
+++ /dev/null
@@ -1,63 +0,0 @@
-#!/usr/bin/env bash
-
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this file
-# to you 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.
-#
-
-set -eu
-
-domain="ciab.test"
-shared_dns_dir="/shared/dns"
-dns_key_file_name="K${domain}.private"
-
-# TODO remove duplication with insert-self-into-dns.sh
-my_host="db"
-my_ip="$(dig +short ${my_host})" # TODO determine if this should be 'hostname -I'
-my_ip6="$(dig +short ${my_host} AAAA)"
-
-full_sub_domain="infra.${domain}"
-my_fqdn="${my_host}.${full_sub_domain}"
-
-ttl="86400"
-
-nsupdate_remove_cmd="update delete ${my_fqdn} A"
-nsupdate_remove_cmd6="update delete ${my_fqdn} AAAA"
-
-nsupdate_cmd="update add ${my_fqdn} ${ttl} A ${my_ip}"
-
-nsupdate_cmd6=
-if [ -n "$my_ip6" ] ; then
-	nsupdate_cmd6="update add ${my_fqdn} ${ttl} AAAA ${my_ip6}"
-fi
-
-dns_key_path="$(ls ${shared_dns_dir}/*.private || true)"
-while [ -z "${dns_key_path}" ]; do
-	printf "insert-self-into-dns waiting for dns server to place key\n"
-	sleep 1
-	dns_key_path="$(ls ${shared_dns_dir}/*private || true)"
-done
-
-printf "insert-self-into-dns domain $domain dns_key_path $dns_key_path my_host $my_host my_ip $my_ip my_fqdn $my_fqdn cmd '$nsupdate_cmd'\n"
-
-nsupdate -v -k "${dns_key_path}" << EOF
-${nsupdate_remove_cmd}
-${nsupdate_remove_cmd6}
-${nsupdate_cmd}
-${nsupdate_cmd6}
-show
-send
-EOF
diff --git a/infrastructure/cdn-in-a-box/dns/insert-self-into-dns.sh b/infrastructure/cdn-in-a-box/dns/insert-self-into-dns.sh
index 0c7d58a..60d155a 100755
--- a/infrastructure/cdn-in-a-box/dns/insert-self-into-dns.sh
+++ b/infrastructure/cdn-in-a-box/dns/insert-self-into-dns.sh
@@ -25,8 +25,11 @@ shared_dns_dir="/shared/dns"
 dns_key_file_name="K${domain}.private"
 
 my_host="$(hostname -s)"
-my_ip="$(dig +short ${my_host})" # TODO determine if this should be 'hostname -I'
-my_ip6="$(dig +short ${my_host} AAAA)"
+my_interface="$(ifconfig | egrep "^\w.+ " | grep -v lo | awk '{print $1}')"
+my_interface=${my_interface%":"}
+my_ip="$(ifconfig $my_interface | grep 'inet ' | awk '{print $2}')" # TODO determine if this should be 'hostname -I'
+my_ip=${my_ip#"addr:"}
+my_ip6="$(ifconfig $my_interface | egrep 'inet6 .+<global>' | awk '{print $2}')"
 
 full_sub_domain="infra.${domain}"
 my_fqdn="${my_host}.${full_sub_domain}"
diff --git a/infrastructure/cdn-in-a-box/docker-compose.yml b/infrastructure/cdn-in-a-box/docker-compose.yml
index 932c5a7..bff0d1f 100644
--- a/infrastructure/cdn-in-a-box/docker-compose.yml
+++ b/infrastructure/cdn-in-a-box/docker-compose.yml
@@ -38,8 +38,8 @@ services:
   # All other components access the database thru the Traffic Ops API
   db:
     build:
-      context: traffic_ops
-      dockerfile: Dockerfile-db
+      context: .
+      dockerfile: traffic_ops/Dockerfile-db
     hostname: db
     domainname: infra.ciab.test
     depends_on:
@@ -47,6 +47,8 @@ services:
     volumes:
       - /var/lib/postgresql/data
       - shared:/shared
+      - ./dns/set-dns.sh:/usr/local/sbin/set-dns.sh
+      - ./dns/insert-self-into-dns.sh:/usr/local/sbin/insert-self-into-dns.sh
     env_file:
       - variables.env
     # TODO: change to expose: "5432" to limit to containers
@@ -93,7 +95,6 @@ services:
       - ./traffic_ops/ca:/ca
       - ./dns/set-dns.sh:/usr/local/sbin/set-dns.sh
       - ./dns/insert-self-into-dns.sh:/usr/local/sbin/insert-self-into-dns.sh
-      - ./dns/insert-db-into-dns.sh:/usr/local/sbin/insert-db-into-dns.sh
       - ./traffic_ops/set-to-ips-from-dns.sh:/usr/local/sbin/set-to-ips-from-dns.sh
       - shared:/shared
 
diff --git a/infrastructure/cdn-in-a-box/traffic_ops/Dockerfile-db b/infrastructure/cdn-in-a-box/traffic_ops/Dockerfile-db
index d98a5d3..f05c12d 100644
--- a/infrastructure/cdn-in-a-box/traffic_ops/Dockerfile-db
+++ b/infrastructure/cdn-in-a-box/traffic_ops/Dockerfile-db
@@ -22,4 +22,7 @@
 FROM postgres:9.6.6
 
 ENV POSTGRES_PASSWORD=$POSTGRES_PASSWORD
-COPY initdb.d /docker-entrypoint-initdb.d
+RUN apt-get update && apt-get install -y dnsutils net-tools
+COPY traffic_ops/initdb.d /docker-entrypoint-initdb.d
+COPY traffic_ops/run-db.sh /
+ENTRYPOINT /run-db.sh
diff --git a/infrastructure/cdn-in-a-box/traffic_ops/Dockerfile-db b/infrastructure/cdn-in-a-box/traffic_ops/run-db.sh
old mode 100644
new mode 100755
similarity index 75%
copy from infrastructure/cdn-in-a-box/traffic_ops/Dockerfile-db
copy to infrastructure/cdn-in-a-box/traffic_ops/run-db.sh
index d98a5d3..c1693ee
--- a/infrastructure/cdn-in-a-box/traffic_ops/Dockerfile-db
+++ b/infrastructure/cdn-in-a-box/traffic_ops/run-db.sh
@@ -1,3 +1,4 @@
+#!/usr/bin/env bash
 # Licensed to the Apache Software Foundation (ASF) under one
 # or more contributor license agreements.  See the NOTICE file
 # distributed with this work for additional information
@@ -15,11 +16,7 @@
 # specific language governing permissions and limitations
 # under the License.
 
-############################################################
-# Dockerfile for trafficops db
-############################################################
+set-dns.sh
+insert-self-into-dns.sh
 
-FROM postgres:9.6.6
-
-ENV POSTGRES_PASSWORD=$POSTGRES_PASSWORD
-COPY initdb.d /docker-entrypoint-initdb.d
+exec /docker-entrypoint.sh postgres
diff --git a/infrastructure/cdn-in-a-box/traffic_ops/run.sh b/infrastructure/cdn-in-a-box/traffic_ops/run.sh
index afd18f8..bea6c0d 100755
--- a/infrastructure/cdn-in-a-box/traffic_ops/run.sh
+++ b/infrastructure/cdn-in-a-box/traffic_ops/run.sh
@@ -41,7 +41,6 @@ done
 
 set-dns.sh
 insert-self-into-dns.sh
-insert-db-into-dns.sh
 
 set-to-ips-from-dns.sh