Wait for weaveDNS HTTP to be running before sending it names
This adds a no-op endpoint to the HTTP API at `/status`. The script simply tries this until it succeeds or gets bored.
This commit is contained in:
1 parent
6a076d05b0
commit
b3d19d6e9d
2 files changed
+21
No files matched your search
@@ -4,6 +4,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -26,6 +27,15 @@ func httpErrorAndLog(level *log.Logger, w http.ResponseWriter, msg string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ListenHttp(domain string, db Zone, port int) {
|
func ListenHttp(domain string, db Zone, port int) {
|
||||||
|
|
||||||
|
http.HandleFunc("/status", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if r.Method != "GET" {
|
||||||
|
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
||||||
|
} else {
|
||||||
|
io.WriteString(w, "ok")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
http.HandleFunc("/name/", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/name/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
reqError := func(msg string, logmsg string, logargs ...interface{}) {
|
reqError := func(msg string, logmsg string, logargs ...interface{}) {
|
||||||
|
|||||||
@@ -317,6 +317,17 @@ tell_dns() {
|
|||||||
# Tell the newly-started weaveDNS about existing weave IPs
|
# Tell the newly-started weaveDNS about existing weave IPs
|
||||||
populate_dns() {
|
populate_dns() {
|
||||||
DNS_IP=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' $DNS_CONTAINER_NAME)
|
DNS_IP=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' $DNS_CONTAINER_NAME)
|
||||||
|
WAIT_TIME=1
|
||||||
|
while ! http_call_ip $DNS_IP $DNS_HTTP_PORT GET /status >/dev/null && [ $WAIT_TIME -lt 4 ]; do
|
||||||
|
echo "Waiting for weaveDNS container to start" >&2
|
||||||
|
sleep $WAIT_TIME
|
||||||
|
WAIT_TIME=$((WAIT_TIME+1))
|
||||||
|
done
|
||||||
|
if [ $WAIT_TIME = 4 ]; then
|
||||||
|
echo "Timed out waiting for weaveDNS container to start." >&2
|
||||||
|
echo "If running, it will not be pre-populated." >&2
|
||||||
|
fi
|
||||||
|
|
||||||
for CONTAINER in $(docker ps -q); do
|
for CONTAINER in $(docker ps -q); do
|
||||||
MORE_ARGS=$(docker inspect --format '--data-urlencode local_ip={{ .NetworkSettings.IPAddress }} --data-urlencode fqdn={{ .Config.Hostname }}.{{ .Config.Domainname }}.' $CONTAINER 2>/dev/null) && true
|
MORE_ARGS=$(docker inspect --format '--data-urlencode local_ip={{ .NetworkSettings.IPAddress }} --data-urlencode fqdn={{ .Config.Hostname }}.{{ .Config.Domainname }}.' $CONTAINER 2>/dev/null) && true
|
||||||
if CONTAINER_ADDRS=$(with_container_netns $CONTAINER container_weave_addrs 2>&1) ; then
|
if CONTAINER_ADDRS=$(with_container_netns $CONTAINER container_weave_addrs 2>&1) ; then
|
||||||
|
|||||||
Reference in new issue
Block a user