X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/d3cb9460f0a30f9602508bed7507c906b8a6d91d..9108a20c409161bc5a0ed06e2d34918334846acf:/docker/arvdock diff --git a/docker/arvdock b/docker/arvdock index 31e405bb41..a41056cd68 100755 --- a/docker/arvdock +++ b/docker/arvdock @@ -1,19 +1,26 @@ #!/bin/bash -ENABLE_SSH=false DOCKER=`which docker.io` 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) [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)" @@ -22,7 +29,7 @@ function usage { echo >&2 " -v, --vm Shell server" echo >&2 " -n, --nameserver Nameserver" echo >&2 " -k, --keep Keep servers" - echo >&2 " --ssh Enable SSH access to server containers" + echo >&2 " -p, --keepproxy Keepproxy server" echo >&2 " -h, --help Display this help and exit" echo >&2 echo >&2 " If no options are given, the action is applied to all servers." @@ -57,7 +64,7 @@ function start_container { fi if [[ "$3" != '' ]]; then local volume="$3" - args="$args -v $volume" + args="$args --volumes-from $volume" fi if [[ "$4" != '' ]]; then local link="$4" @@ -65,82 +72,38 @@ function start_container { fi local image=$5 - if $ENABLE_SSH - then - args="$args -e ENABLE_SSH=$ENABLE_SSH" - fi - `$DOCKER ps |grep -P "$name[^/]" -q` if [[ "$?" == "0" ]]; then echo "You have a running container with name $name -- skipping." return fi - # Remove any existing container by this name. - $DOCKER rm "$name" 2>/dev/null + echo "Starting container: $name" + `$DOCKER ps --all |grep -P "$name[^/]" -q` + if [[ "$?" == "0" ]]; then + echo " $DOCKER start $name" + container=`$DOCKER start $name` + else + echo " $DOCKER run $args $image" + container=`$DOCKER run $args $image` + fi - echo "Starting container:" - #echo " $DOCKER run --dns=127.0.0.1 $args $image" - echo " $DOCKER run $args $image" - container=`$DOCKER run $args $image` if [ "$?" != "0" -o "$container" = "" ]; then echo "Unable to start container" exit 1 - fi - if [ "$name" == "compute" -o "$ENABLE_SSH" != "false" ]; - then - ip=$(ip_address $container ) - echo - echo "You can ssh into the container with:" - echo - echo " ssh root@$ip" - echo else 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 - - } -declare -a keep_volumes - -# Initialize the global `keep_volumes' array. If any keep volumes -# already appear to exist (mounted volumes with a top-level "keep" -# directory), use them; create temporary volumes if necessary. -# +# Create a Docker data volume function make_keep_volumes () { - # Mount a keep volume if we don't already have one - for mountpoint in $(cut -d ' ' -f 2 /proc/mounts); do - if [[ -d "$mountpoint/keep" && "$mountpoint" != "/" ]]; then - keep_volumes+=($mountpoint) - fi - done - - # Create any keep volumes that do not yet exist. - while [ ${#keep_volumes[*]} -lt 2 ] - do - new_keep=$(mktemp -d) - echo >&2 "mounting 2G tmpfs keep volume in $new_keep" - sudo mount -t tmpfs -o size=2G tmpfs $new_keep - mkdir $new_keep/keep - keep_volumes+=($new_keep) - done + `$DOCKER ps --all |grep -P "keep_data[^/]" -q` + if [[ "$?" == "0" ]]; then + return + fi + docker create -v /keep-data --name keep_data arvados/keep } function do_start { @@ -152,10 +115,12 @@ function do_start { local start_vm=false local start_nameserver=false local start_keep=false + local start_keepproxy=false + local # NOTE: This requires GNU getopt (part of the util-linux package on Debian-based distros). - local TEMP=`getopt -o d::s::a::cw::nkvh \ - --long doc::,sso::,api::,compute,workbench::,nameserver,keep,vm,help,ssh \ + local TEMP=`getopt -o d::s::a::cw::nkpvh \ + --long doc::,sso::,api::,compute,workbench::,nameserver,keep,keepproxy,vm,help \ -n "$0" -- "$@"` if [ $? != 0 ] ; then echo "Use -h for help"; exit 1 ; fi @@ -206,9 +171,8 @@ function do_start { start_keep=true shift ;; - --ssh) - # ENABLE_SSH is a global variable - ENABLE_SSH=true + -p | --keepproxy) + start_keepproxy=true shift ;; --) @@ -230,7 +194,8 @@ function do_start { $start_workbench == false && $start_vm == false && $start_nameserver == false && - $start_keep == false ]] + $start_keep == false && + $start_keepproxy == false ]] then start_doc=9898 #the sso server is currently not used by default so don't start it unless explicitly requested @@ -241,20 +206,7 @@ function do_start { start_vm=true start_nameserver=true start_keep=true - fi - - if [[ $start_sso != false ]] - then - start_container "$start_sso:443" "sso_server" '' '' "arvados/sso" - fi - - if [[ $start_api != false ]] - then - if [[ $start_sso != false ]]; then - start_container "$start_api:443" "api_server" '' "sso_server:sso" "arvados/api" - else - start_container "$start_api:443" "api_server" '' '' "arvados/api" - fi + start_keepproxy=true fi if [[ $start_nameserver != false ]] @@ -265,16 +217,32 @@ function do_start { if [[ "$?" != "0" ]]; then echo "Starting crosbymichael/skydns container..." $DOCKER rm "skydns" 2>/dev/null + echo $DOCKER run -d -p 172.17.42.1:53:53/udp --name skydns crosbymichael/skydns -nameserver 8.8.8.8:53 -domain arvados $DOCKER run -d -p 172.17.42.1:53:53/udp --name skydns crosbymichael/skydns -nameserver 8.8.8.8:53 -domain arvados fi $DOCKER ps | grep skydock >/dev/null if [[ "$?" != "0" ]]; then echo "Starting crosbymichael/skydock container..." $DOCKER rm "skydock" 2>/dev/null + 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 fi + if [[ $start_sso != false ]] + then + start_container "$start_sso:443" "sso_server" '' '' "arvados/sso" + fi + + if [[ $start_api != false ]] + then + if [[ $start_sso != false ]]; then + start_container "$start_api:443" "api_server" '' "sso_server:sso" "arvados/api" + else + start_container "$start_api:443" "api_server" '' '' "arvados/api" + fi + fi + if [[ $start_compute != false ]] then for i in `seq 0 $(($start_compute - 1))`; do @@ -287,20 +255,23 @@ function do_start { # create `keep_volumes' array with a list of keep mount points # remove any stale metadata from those volumes before starting them make_keep_volumes - for v in ${keep_volumes[*]} - do - [ -f $v/keep/.metadata.yml ] && sudo rm $v/keep/.metadata.yml - done start_container "25107:25107" "keep_server_0" \ - "${keep_volumes[0]}:/keep-data" \ + "keep_data" \ "api_server:api" \ "arvados/keep" start_container "25108:25107" "keep_server_1" \ - "${keep_volumes[1]}:/keep-data" \ + "keep_data" \ "api_server:api" \ "arvados/keep" fi + if [[ $start_keepproxy != false ]] + then + start_container "9902:9100" "keepproxy_server" '' \ + "api_server:api" \ + "arvados/keepproxy" + fi + if [[ $start_doc != false ]] then start_container "$start_doc:80" "doc_server" '' '' "arvados/doc" @@ -330,6 +301,42 @@ EOF fi fi fi + + if [ "$(awk '($1 == "nameserver"){print $2; exit}' /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 { @@ -341,10 +348,11 @@ function do_stop { local stop_nameserver="" local stop_vm="" local stop_keep="" + local stop_keepproxy="" # NOTE: This requires GNU getopt (part of the util-linux package on Debian-based distros). - local TEMP=`getopt -o dsacwnkvh \ - --long doc,sso,api,compute,workbench,nameserver,keep,vm,help \ + local TEMP=`getopt -o dsacwnkpvh \ + --long doc,sso,api,compute,workbench,nameserver,keep,keepproxy,vm,help \ -n "$0" -- "$@"` if [ $? != 0 ] ; then echo "Use -h for help"; exit 1 ; fi @@ -371,6 +379,8 @@ function do_stop { stop_vm="shell" ; shift ;; -k | --keep ) stop_keep="keep_server_0 keep_server_1" ; shift ;; + -p | --keepproxy ) + stop_keep="keepproxy_server" ; shift ;; --) shift break @@ -390,7 +400,8 @@ function do_stop { $stop_workbench == "" && $stop_vm == "" && $stop_nameserver == "" && - $stop_keep == "" ]] + $stop_keep == "" && + $stop_keepproxy == "" ]] then stop_doc=doc_server stop_sso=sso_server @@ -400,9 +411,10 @@ function do_stop { stop_vm=shell stop_nameserver="skydock skydns" stop_keep="keep_server_0 keep_server_1" + stop_keepproxy="keepproxy_server" fi - $DOCKER stop $stop_doc $stop_sso $stop_api $stop_compute $stop_workbench $stop_nameserver $stop_keep $stop_vm \ + $DOCKER stop $stop_doc $stop_sso $stop_api $stop_compute $stop_workbench $stop_nameserver $stop_keep $stop_keepproxy $stop_vm \ 2>/dev/null } @@ -437,6 +449,34 @@ function do_test { done } +function do_reset { + for name in skydock skydns workbench_server shell doc_server keepproxy_server keep_server_0 keep_server_1 compute0 compute1 api_server keepproxy keep_data + do + `$DOCKER ps |grep -P "$name[^/]" -q` + if [[ "$?" == "0" ]]; then + echo " $DOCKER stop $name" + $DOCKER stop $name + fi + `$DOCKER ps --all |grep -P "$name[^/]" -q` + if [[ "$?" == "0" ]]; then + echo " $DOCKER rm $name" + $DOCKER rm $name + fi + 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 @@ -461,6 +501,10 @@ case $1 in shift do_test $@ ;; + reset) + shift + do_reset $@ + ;; *) usage exit 1