Tighten up DNS check in arvdock.
[arvados.git] / docker / arvdock
index 2107ff341773c733b3782c24ce2206b3e3da9d91..a41056cd680c534585e5346c15a2264157ef1b55 100755 (executable)
@@ -6,13 +6,21 @@ if [[ "$DOCKER" == "" ]]; then
     DOCKER=`which docker`
 fi
 
+CURL=`which curl`
+
 COMPUTE_COUNTER=0
 
 function usage {
     echo >&2
-    echo >&2 "usage: $0 (start|stop|restart|test|reset) [options]"
+    echo >&2 "usage: $0 (start|stop|restart|reset|test) [options]"
+    echo >&2
+    echo >&2 "start    run new or restart stopped arvados containers"
+    echo >&2 "stop     stop arvados containers"
+    echo >&2 "restart  stop and then start arvados containers"
+    echo >&2 "reset    stop and delete containers WARNING: this will delete the data inside Arvados!"
+    echo >&2 "test     run tests"
     echo >&2
-    echo >&2 "$0 start/stop/restart options:"
+    echo >&2 "$0 options:"
     echo >&2 "  -d[port], --doc[=port]        Documentation server (default port 9898)"
     echo >&2 "  -w[port], --workbench[=port]  Workbench server (default port 9899)"
     echo >&2 "  -s[port], --sso[=port]        SSO server (default port 9901)"
@@ -87,23 +95,6 @@ function start_container {
       echo "Started container: $container"
     fi
 
-    if [[ "$name" == "doc_server" ]]; then
-      echo
-      echo "*****************************************************************"
-      echo "You can access the Arvados documentation at http://localhost:${port%:*}"
-      echo "*****************************************************************"
-      echo
-    fi
-
-    if [[ "$name" == "workbench_server" ]]; then
-      echo
-      echo "*****************************************************************"
-      echo "You can access the Arvados workbench at http://localhost:${port%:*}"
-      echo "*****************************************************************"
-      echo
-   fi
-
-
 }
 
 # Create a Docker data volume
@@ -236,14 +227,6 @@ function do_start {
         echo $DOCKER run -d -v /var/run/docker.sock:/docker.sock --name skydock crosbymichael/skydock -ttl 30 -environment dev -s /docker.sock -domain arvados -name skydns
         $DOCKER run -d -v /var/run/docker.sock:/docker.sock --name skydock crosbymichael/skydock -ttl 30 -environment dev -s /docker.sock -domain arvados -name skydns
       fi
-
-      echo
-      echo "*****************************************************************"
-      echo "To access Arvados using command line tools on the host we recommend you add"
-      echo "the arvados nameserver to the top of your DNS configuration in /etc/resolv.conf:"
-      echo "nameserver 172.17.42.1"
-      echo "*****************************************************************"
-      echo
     fi
 
     if [[ $start_sso != false ]]
@@ -318,6 +301,42 @@ EOF
           fi
         fi
     fi
+
+    if [ "$(awk '($1 == "nameserver"){print $2; exit}' </etc/resolv.conf)" != "172.17.42.1" ]; then
+        echo
+        echo "******************************************************************"
+        echo "To access Arvados you must add the Arvados nameserver to the top"
+        echo "of your DNS configuration in /etc/resolv.conf:"
+        echo "nameserver 172.17.42.1"
+        echo
+        echo "Then run '$0 start' again"
+        echo "******************************************************************"
+        echo
+    else
+        while ! $CURL -L -f http://workbench.dev.arvados >/dev/null 2>/dev/null ; do
+            echo "Waiting for Arvados to be ready."
+            sleep 1
+        done
+
+        `$DOCKER ps |grep -P "doc_server[^/]" -q`
+        if [[ "$?" == "0" ]]; then
+            echo
+            echo "******************************************************************"
+            echo "You can access the Arvados documentation at http://doc.dev.arvados"
+            echo "******************************************************************"
+            echo
+        fi
+
+        `$DOCKER ps |grep -P "workbench_server[^/]" -q`
+        if [[ "$?" == "0" ]]; then
+            echo
+            echo "********************************************************************"
+            echo "You can access the Arvados workbench at http://workbench.dev.arvados"
+            echo "********************************************************************"
+            echo
+        fi
+    fi
+
 }
 
 function do_stop {
@@ -446,6 +465,18 @@ function do_reset {
     done
 }
 
+if [ "$DOCKER" == '' ]
+then
+  echo "Docker not found. Please install it first."
+  exit 2
+fi
+
+if [ "$CURL" == '' ]
+then
+  echo "Curl not found. Please install it first."
+  exit 3
+fi
+
 if [ $# -lt 1 ]
 then
   usage
@@ -474,7 +505,6 @@ case $1 in
         shift
         do_reset $@
         ;;
-
     *)
         usage
         exit 1