3 DOCKER=`which docker.io`
5 if [[ "$DOCKER" == "" ]]; then
15 echo >&2 "usage: $0 (start|stop|restart|reset|test) [options]"
17 echo >&2 "start run new or restart stopped arvados containers"
18 echo >&2 "stop stop arvados containers"
19 echo >&2 "restart stop and then start arvados containers"
20 echo >&2 "reset stop and delete containers WARNING: this will delete the data inside Arvados!"
21 echo >&2 "test run tests"
23 echo >&2 "$0 options:"
24 echo >&2 " -b[bridge], --bridge[=bridge] Docker bridge (default bridge docker0)"
25 echo >&2 " -d[port], --doc[=port] Documentation server (default port 9898)"
26 echo >&2 " -w[port], --workbench[=port] Workbench server (default port 9899)"
27 echo >&2 " -s[port], --sso[=port] SSO server (default port 9901)"
28 echo >&2 " -a[port], --api[=port] API server (default port 9900)"
29 echo >&2 " -c, --compute Compute nodes (starts 2)"
30 echo >&2 " -v, --vm Shell server"
31 echo >&2 " -n, --nameserver Nameserver"
32 echo >&2 " -k, --keep Keep servers"
33 echo >&2 " -p, --keepproxy Keepproxy server"
34 echo >&2 " -h, --help Display this help and exit"
36 echo >&2 " If no options are given, the action is applied to all servers."
38 echo >&2 "$0 test [testname] [testname] ..."
39 echo >&2 " By default, all tests are run."
44 echo `$DOCKER inspect $container |grep IPAddress |cut -f4 -d\"`
47 function bridge_ip_address {
49 # FIXME: add a more robust check here.
50 # because ip command could be mising, multiple docker birdges could be there.. etc.
51 echo $(ip -oneline addr show | grep $bridge_name | grep -E '\binet\b' | awk '{ print $4 }'| cut -d/ -f1 )
54 function start_container {
55 bridge_ip=$(bridge_ip_address "$start_bridge")
58 if [[ "$1" != '' ]]; then
62 if [[ "$2" != '' ]]; then
64 if [[ "$name" == "api_server" ]]; then
65 args="$args --dns=$bridge_ip --dns-search=compute.dev.arvados --hostname api -P --name $name"
66 elif [[ "$name" == "compute" ]]; then
67 name=$name$COMPUTE_COUNTER
68 # We need --privileged because we run docker-inside-docker on the compute nodes
69 args="$args --dns=$bridge_ip --dns-search=compute.dev.arvados --hostname compute$COMPUTE_COUNTER -P --privileged --name $name"
70 let COMPUTE_COUNTER=$(($COMPUTE_COUNTER + 1))
72 args="$args --dns=$bridge_ip --dns-search=dev.arvados --hostname ${name#_server} --name $name"
75 if [[ "$3" != '' ]]; then
77 args="$args --volumes-from $volume"
79 if [[ "$4" != '' ]]; then
81 args="$args --link $link"
85 `$DOCKER ps |grep -E "\b$name\b" -q`
86 if [[ "$?" == "0" ]]; then
87 echo "You have a running container with name $name -- skipping."
91 echo "Starting container: $name"
92 `$DOCKER ps --all |grep -E "\b$name\b" -q`
93 if [[ "$?" == "0" ]]; then
94 echo " $DOCKER start $name"
95 container=`$DOCKER start $name`
97 echo " $DOCKER run $args $image"
98 container=`$DOCKER run $args $image`
101 if [ "$?" != "0" -o "$container" = "" ]; then
102 echo "Unable to start container"
105 echo "Started container: $container"
110 # Create a Docker data volume
111 function make_keep_volumes () {
112 `$DOCKER ps --all |grep -E "\bkeep_data\b" -q`
113 if [[ "$?" == "0" ]]; then
116 docker create -v /keep-data --name keep_data arvados/keep
120 local start_doc=false
121 local start_sso=false
122 local start_api=false
123 local start_compute=false
124 local start_workbench=false
126 local start_nameserver=false
127 local start_keep=false
128 local start_keepproxy=false
129 local start_bridge="docker0"
132 # NOTE: This requires GNU getopt (part of the util-linux package on Debian-based distros).
133 local TEMP=`getopt -o d::s::a::cw::nkpvh \
134 --long doc::,sso::,api::,bridge::,compute,workbench::,nameserver,keep,keepproxy,vm,help \
137 if [ $? != 0 ] ; then echo "Use -h for help"; exit 1 ; fi
139 # Note the quotes around `$TEMP': they are essential!
147 "") start_bridge="docker0"; shift 2 ;;
148 *) start_bridge=$2; shift 2 ;;
153 "") start_doc=9898; shift 2 ;;
154 *) start_doc=$2; shift 2 ;;
159 "") start_sso=9901; shift 2 ;;
160 *) start_sso=$2; shift 2 ;;
165 "") start_api=9900; shift 2 ;;
166 *) start_api=$2; shift 2 ;;
175 "") start_workbench=9899; shift 2 ;;
176 *) start_workbench=$2; shift 2 ;;
184 start_nameserver=true
206 # If no options were selected, then start all servers.
207 if [[ $start_doc == false &&
208 $start_sso == false &&
209 $start_api == false &&
210 $start_compute == false &&
211 $start_workbench == false &&
212 $start_vm == false &&
213 $start_nameserver == false &&
214 $start_keep == false &&
215 $start_keepproxy == false ]]
217 start_bridge="docker0"
219 #the sso server is currently not used by default so don't start it unless explicitly requested
225 start_nameserver=true
230 if [[ $start_nameserver != false ]]
232 # We rely on skydock and skydns for dns discovery between the slurm controller and compute nodes,
233 # so make sure they are running
234 $DOCKER ps | grep skydns >/dev/null
235 if [[ "$?" != "0" ]]; then
236 echo "Detecting bridge '$start_bridge' IP for crosbymichael/skydns"
237 bridge_ip=$(bridge_ip_address "$start_bridge")
239 echo "Starting crosbymichael/skydns container..."
240 $DOCKER rm "skydns" 2>/dev/null
241 echo $DOCKER run -d -p $bridge_ip:53:53/udp --name skydns crosbymichael/skydns -nameserver 8.8.8.8:53 -domain arvados
242 $DOCKER run -d -p $bridge_ip:53:53/udp --name skydns crosbymichael/skydns -nameserver 8.8.8.8:53 -domain arvados
244 $DOCKER ps | grep skydock >/dev/null
245 if [[ "$?" != "0" ]]; then
246 echo "Starting crosbymichael/skydock container..."
247 $DOCKER rm "skydock" 2>/dev/null
248 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
249 $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
253 if [[ $start_sso != false ]]
255 start_container "$start_sso:443" "sso_server" '' '' "arvados/sso"
258 if [[ $start_api != false ]]
260 if [[ $start_sso != false ]]; then
261 start_container "$start_api:443" "api_server" '' "sso_server:sso" "arvados/api"
263 start_container "$start_api:443" "api_server" '' '' "arvados/api"
267 if [[ $start_compute != false ]]
269 for i in `seq 0 $(($start_compute - 1))`; do
270 start_container "" "compute" '' "api_server:api" "arvados/compute"
274 if [[ $start_keep != false ]]
276 # create `keep_volumes' array with a list of keep mount points
277 # remove any stale metadata from those volumes before starting them
279 start_container "25107:25107" "keep_server_0" \
283 start_container "25108:25107" "keep_server_1" \
289 if [[ $start_keepproxy != false ]]
291 start_container "9902:9100" "keepproxy_server" '' \
296 if [[ $start_doc != false ]]
298 start_container "$start_doc:80" "doc_server" '' '' "arvados/doc"
301 if [[ $start_vm != false ]]
303 start_container "" "shell" '' "api_server:api" "arvados/shell"
306 if [[ $start_workbench != false ]]
308 start_container "$start_workbench:80" "workbench_server" '' "api_server:api" "arvados/workbench"
311 if [[ $start_api != false ]]
313 if [[ -f "api/generated/superuser_token" ]]
315 if [ -d $HOME/.config/arvados ] || mkdir -p $HOME/.config/arvados
317 cat >$HOME/.config/arvados/settings.conf <<EOF
318 ARVADOS_API_HOST=$(ip_address "api_server")
319 ARVADOS_API_HOST_INSECURE=yes
320 ARVADOS_API_TOKEN=$(cat api/generated/superuser_token)
326 if [ "$(awk '($1 == "nameserver"){print $2; exit}' </etc/resolv.conf)" != "$bridge_ip" ]; then
328 echo "******************************************************************"
329 echo "To access Arvados you must add the Arvados nameserver to the top"
330 echo "of your DNS configuration in /etc/resolv.conf:"
331 echo "nameserver $bridge_ip"
333 echo "Then run '$0 start' again"
334 echo "******************************************************************"
337 while ! $CURL -L -f http://workbench.dev.arvados >/dev/null 2>/dev/null ; do
338 echo "Waiting for Arvados to be ready."
342 `$DOCKER ps |grep -E "\bdoc_server\b" -q`
343 if [[ "$?" == "0" ]]; then
345 echo "******************************************************************"
346 echo "You can access the Arvados documentation at http://doc.dev.arvados"
347 echo "******************************************************************"
351 `$DOCKER ps |grep -E "\bworkbench_server\b" -q`
352 if [[ "$?" == "0" ]]; then
354 echo "********************************************************************"
355 echo "You can access the Arvados workbench at http://workbench.dev.arvados"
356 echo "********************************************************************"
367 local stop_compute=""
368 local stop_workbench=""
369 local stop_nameserver=""
372 local stop_keepproxy=""
374 # NOTE: This requires GNU getopt (part of the util-linux package on Debian-based distros).
375 local TEMP=`getopt -o dsacwnkpvh \
376 --long doc,sso,api,compute,workbench,nameserver,keep,keepproxy,vm,help \
379 if [ $? != 0 ] ; then echo "Use -h for help"; exit 1 ; fi
381 # Note the quotes around `$TEMP': they are essential!
388 stop_doc=doc_server ; shift ;;
390 stop_sso=sso_server ; shift ;;
392 stop_api=api_server ; shift ;;
394 stop_compute=`$DOCKER ps |grep -E "\bcompute[0-9]+\b" |grep -v api_server |cut -f1 -d ' '` ; shift ;;
396 stop_workbench=workbench_server ; shift ;;
398 stop_nameserver="skydock skydns" ; shift ;;
400 stop_vm="shell" ; shift ;;
402 stop_keep="keep_server_0 keep_server_1" ; shift ;;
404 stop_keep="keepproxy_server" ; shift ;;
416 # If no options were selected, then stop all servers.
417 if [[ $stop_doc == "" &&
420 $stop_compute == "" &&
421 $stop_workbench == "" &&
423 $stop_nameserver == "" &&
425 $stop_keepproxy == "" ]]
430 stop_compute=`$DOCKER ps |grep -E "\bcompute[0-9]+\b" |grep -v api_server |cut -f1 -d ' '`
431 stop_workbench=workbench_server
433 stop_nameserver="skydock skydns"
434 stop_keep="keep_server_0 keep_server_1"
435 stop_keepproxy="keepproxy_server"
438 $DOCKER stop $stop_doc $stop_sso $stop_api $stop_compute $stop_workbench $stop_nameserver $stop_keep $stop_keepproxy $stop_vm \
446 alltests="python-sdk api"
451 for testname in $alltests
453 echo "testing $testname..."
456 do_start --api --keep --sso
457 export ARVADOS_API_HOST=$(ip_address "api_server")
458 export ARVADOS_API_HOST_INSECURE=yes
459 export ARVADOS_API_TOKEN=$(cat api/generated/superuser_token)
460 python -m unittest discover ../sdk/python
463 $DOCKER run -t -i arvados/api \
464 /usr/src/arvados/services/api/script/rake_test.sh
467 echo >&2 "unknown test $testname"
474 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
476 `$DOCKER ps |grep -E "\b$name\b" -q`
477 if [[ "$?" == "0" ]]; then
478 echo " $DOCKER stop $name"
481 `$DOCKER ps --all |grep -E "\b$name\b" -q`
482 if [[ "$?" == "0" ]]; then
483 echo " $DOCKER rm $name"
489 if [ "$DOCKER" == '' ]
491 echo "Docker not found. Please install it first."
497 echo "Curl not found. Please install it first."