3 DOCKER=`which docker.io`
5 if [[ "$DOCKER" == "" ]]; then
13 ARVADOS_DOMAIN=dev.arvados
17 echo >&2 "usage: $0 (start|stop|restart|reset|test) [options]"
19 echo >&2 "start run new or restart stopped arvados containers"
20 echo >&2 "stop stop arvados containers"
21 echo >&2 "restart stop and then start arvados containers"
22 echo >&2 "reset stop and delete containers WARNING: this will delete the data inside Arvados!"
23 echo >&2 "test run tests"
25 echo >&2 "$0 options:"
26 echo >&2 " -b[bridge], --bridge[=bridge] Docker bridge (default bridge docker0)"
27 echo >&2 " -d[port], --doc[=port] Documentation server (default port 9898)"
28 echo >&2 " -w[port], --workbench[=port] Workbench server (default port 9899)"
29 echo >&2 " -s[port], --sso[=port] SSO server (default port 9901)"
30 echo >&2 " -a[port], --api[=port] API server (default port 9900)"
31 echo >&2 " -c, --compute Compute nodes (starts 2)"
32 echo >&2 " -v, --vm Shell server"
33 echo >&2 " -n, --nameserver Nameserver"
34 echo >&2 " -k, --keep Keep servers"
35 echo >&2 " -p, --keepproxy Keepproxy server"
36 echo >&2 " -h, --help Display this help and exit"
37 echo >&2 " --domain=dns.domain DNS domain used by containers (default dev.arvados)"
39 echo >&2 " If no options are given, the action is applied to all servers."
41 echo >&2 "$0 test [testname] [testname] ..."
42 echo >&2 " By default, all tests are run."
47 echo `$DOCKER inspect $container |grep IPAddress |cut -f4 -d\"`
50 function bridge_ip_address {
52 # FIXME: add a more robust check here.
53 # because ip command could be mising, multiple docker bridges could be there.. etc.
54 echo $(ip --oneline --family inet addr show dev "$bridge_name" | awk '{ print $4 }'| cut -d/ -f1 )
57 function start_container {
58 bridge_ip=$(bridge_ip_address "$bridge")
61 if [[ "$1" != '' ]]; then
65 if [[ "$2" != '' ]]; then
67 if [[ "$name" == "api_server" ]]; then
68 args="$args --dns=$bridge_ip --dns-search=compute.$ARVADOS_DOMAIN --hostname api -P --name $name"
69 elif [[ "$name" == "compute" ]]; then
70 name=$name$COMPUTE_COUNTER
71 # We need --privileged because we run docker-inside-docker on the compute nodes
72 args="$args --dns=$bridge_ip --dns-search=compute.$ARVADOS_DOMAIN --hostname compute$COMPUTE_COUNTER -P --privileged --name $name"
73 let COMPUTE_COUNTER=$(($COMPUTE_COUNTER + 1))
75 args="$args --dns=$bridge_ip --dns-search=$ARVADOS_DOMAIN --hostname ${name#_server} --name $name"
78 if [[ "$3" != '' ]]; then
80 args="$args --volumes-from $volume"
82 if [[ "$4" != '' ]]; then
84 args="$args --link $link"
88 `$DOCKER ps |grep -E "\b$name\b" -q`
89 if [[ "$?" == "0" ]]; then
90 echo "You have a running container with name $name -- skipping."
94 echo "Starting container: $name"
95 `$DOCKER ps --all |grep -E "\b$name\b" -q`
96 if [[ "$?" == "0" ]]; then
97 echo " $DOCKER start $name"
98 container=`$DOCKER start $name`
100 echo " $DOCKER run $args $image"
101 container=`$DOCKER run $args $image`
104 if [ "$?" != "0" -o "$container" = "" ]; then
105 echo "Unable to start container"
108 echo "Started container: $container"
113 # Create a Docker data volume
114 function make_keep_volumes () {
115 `$DOCKER ps --all |grep -E "\bkeep_data\b" -q`
116 if [[ "$?" == "0" ]]; then
119 docker create -v /keep-data --name keep_data arvados/keep
123 local start_doc=false
124 local start_sso=false
125 local start_api=false
126 local start_compute=false
127 local start_workbench=false
129 local start_nameserver=false
130 local start_keep=false
131 local start_keepproxy=false
132 local bridge="docker0"
135 # NOTE: This requires GNU getopt (part of the util-linux package on Debian-based distros).
136 local TEMP=`getopt -o d::s::b:a::cw::nkpvh \
137 --long doc::,sso::,api::,bridge:,compute,workbench::,nameserver,keep,keepproxy,vm,help,domain:: \
140 if [ $? != 0 ] ; then echo "Use -h for help"; exit 1 ; fi
142 # Note the quotes around `$TEMP': they are essential!
150 *) start_bridge=$2; shift 2 ;;
155 "") start_doc=9898; shift 2 ;;
156 *) start_doc=$2; shift 2 ;;
161 "") start_sso=9901; shift 2 ;;
162 *) start_sso=$2; shift 2 ;;
167 "") start_api=9900; shift 2 ;;
168 *) start_api=$2; shift 2 ;;
177 "") start_workbench=9899; shift 2 ;;
178 *) start_workbench=$2; shift 2 ;;
186 start_nameserver=true
199 *) ARVADOS_DOMAIN="$2"; shift 2 ;;
213 # If no options were selected, then start all servers.
214 if [[ $start_doc == false &&
215 $start_sso == false &&
216 $start_api == false &&
217 $start_compute == false &&
218 $start_workbench == false &&
219 $start_vm == false &&
220 $start_nameserver == false &&
221 $start_keep == false &&
222 $start_keepproxy == false ]]
230 start_nameserver=true
235 if [[ $start_nameserver != false ]]
237 $DOCKER ps | grep skydns >/dev/null
240 $DOCKER ps | grep skydock >/dev/null
243 if [[ "$need_skydns" != 0 || "$need_skydock" != 0 ]]
245 # skydns and skydock need to both be running before everything else.
246 # If they are not running we need to shut everything down and start
247 # over, otherwise DNS will be broken and the containers won't find each other.
253 # We rely on skydock and skydns for dns discovery between the slurm controller and compute nodes,
254 # so make sure they are running
255 $DOCKER ps | grep skydns >/dev/null
256 if [[ $need_skydns != "0" ]]; then
257 echo "Detecting bridge '$bridge' IP for crosbymichael/skydns"
258 bridge_ip=$(bridge_ip_address "$bridge")
260 echo "Starting crosbymichael/skydns container..."
261 $DOCKER rm "skydns" 2>/dev/null
262 echo $DOCKER run -d -p $bridge_ip:53:53/udp --name skydns crosbymichael/skydns -nameserver 8.8.8.8:53 -domain arvados
263 $DOCKER run -d -p $bridge_ip:53:53/udp --name skydns crosbymichael/skydns -nameserver 8.8.8.8:53 -domain arvados
265 $DOCKER ps | grep skydock >/dev/null
266 if [[ "$need_skydock" != "0" ]]; then
267 echo "Starting crosbymichael/skydock container..."
268 $DOCKER rm "skydock" 2>/dev/null
269 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
270 $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
274 if [[ $start_sso != false ]]
276 start_container "$start_sso:443" "sso_server" '' '' "arvados/sso"
279 if [[ $start_api != false ]]
281 if [[ $start_sso != false ]]; then
282 start_container "$start_api:443" "api_server" '' "sso_server:sso" "arvados/api"
284 start_container "$start_api:443" "api_server" '' '' "arvados/api"
288 if [[ $start_compute != false ]]
290 for i in `seq 0 $(($start_compute - 1))`; do
291 start_container "" "compute" '' "api_server:api" "arvados/compute"
295 if [[ $start_keep != false ]]
297 # create `keep_volumes' array with a list of keep mount points
298 # remove any stale metadata from those volumes before starting them
300 start_container "25107:25107" "keep_server_0" \
304 start_container "25108:25107" "keep_server_1" \
310 if [[ $start_keepproxy != false ]]
312 start_container "9902:9100" "keepproxy_server" '' \
317 if [[ $start_doc != false ]]
319 start_container "$start_doc:80" "doc_server" '' '' "arvados/doc"
322 if [[ $start_vm != false ]]
324 start_container "" "shell" '' "api_server:api" "arvados/shell"
327 if [[ $start_workbench != false ]]
329 start_container "" "workbench_server" '' "" "arvados/workbench"
332 if [[ $start_api != false ]]
334 if [[ -f "api/generated/superuser_token" ]]
336 if [ -d $HOME/.config/arvados ] || mkdir -p $HOME/.config/arvados
338 cat >$HOME/.config/arvados/settings.conf <<EOF
339 ARVADOS_API_HOST=$(ip_address "api_server")
340 ARVADOS_API_HOST_INSECURE=yes
341 ARVADOS_API_TOKEN=$(cat api/generated/superuser_token)
347 if [ "$(awk '($1 == "nameserver"){print $2; exit}' </etc/resolv.conf)" != "$bridge_ip" ]; then
349 echo "******************************************************************"
350 echo "To access Arvados you must add the Arvados nameserver to the top"
351 echo "of your DNS configuration in /etc/resolv.conf:"
352 echo "nameserver $bridge_ip"
354 echo "Then run '$0 start' again"
355 echo "******************************************************************"
358 while ! $CURL -k -L -f http://workbench.$ARVADOS_DOMAIN >/dev/null 2>/dev/null ; do
359 echo "Waiting for Arvados to be ready."
363 `$DOCKER ps |grep -E "\bdoc_server\b" -q`
364 if [[ "$?" == "0" ]]; then
366 echo "******************************************************************"
367 echo "You can access the Arvados documentation at http://doc.$ARVADOS_DOMAIN"
368 echo "******************************************************************"
372 `$DOCKER ps |grep -E "\bworkbench_server\b" -q`
373 if [[ "$?" == "0" ]]; then
375 echo "********************************************************************"
376 echo "You can access the Arvados workbench at http://workbench.$ARVADOS_DOMAIN"
377 echo "********************************************************************"
388 local stop_compute=""
389 local stop_workbench=""
390 local stop_nameserver=""
393 local stop_keepproxy=""
395 # NOTE: This requires GNU getopt (part of the util-linux package on Debian-based distros).
396 local TEMP=`getopt -o dsacwnkpvh \
397 --long doc,sso,api,compute,workbench,nameserver,keep,keepproxy,vm,help,domain:: \
400 if [ $? != 0 ] ; then echo "Use -h for help"; exit 1 ; fi
402 # Note the quotes around `$TEMP': they are essential!
409 stop_doc=doc_server ; shift ;;
411 stop_sso=sso_server ; shift ;;
413 stop_api=api_server ; shift ;;
415 stop_compute=`$DOCKER ps |grep -E "\bcompute[0-9]+\b" |grep -v api_server |cut -f1 -d ' '` ; shift ;;
417 stop_workbench=workbench_server ; shift ;;
419 stop_nameserver="skydock skydns" ; shift ;;
421 stop_vm="shell" ; shift ;;
423 stop_keep="keep_server_0 keep_server_1" ; shift ;;
425 stop_keep="keepproxy_server" ; shift ;;
428 *) ARVADOS_DOMAIN="$2"; shift 2 ;;
442 # If no options were selected, then stop all servers.
443 if [[ $stop_doc == "" &&
446 $stop_compute == "" &&
447 $stop_workbench == "" &&
449 $stop_nameserver == "" &&
451 $stop_keepproxy == "" ]]
456 stop_compute=`$DOCKER ps |grep -E "\bcompute[0-9]+\b" |grep -v api_server |cut -f1 -d ' '`
457 stop_workbench=workbench_server
459 stop_nameserver="skydock skydns"
460 stop_keep="keep_server_0 keep_server_1"
461 stop_keepproxy="keepproxy_server"
464 $DOCKER stop $stop_doc $stop_sso $stop_api $stop_compute $stop_workbench $stop_nameserver $stop_keep $stop_keepproxy $stop_vm \
472 alltests="python-sdk api"
477 for testname in $alltests
479 echo "testing $testname..."
482 do_start --api --keep --sso
483 export ARVADOS_API_HOST=$(ip_address "api_server")
484 export ARVADOS_API_HOST_INSECURE=yes
485 export ARVADOS_API_TOKEN=$(cat api/generated/superuser_token)
486 python -m unittest discover ../sdk/python
489 $DOCKER run -t -i arvados/api \
490 /usr/src/arvados/services/api/script/rake_test.sh
493 echo >&2 "unknown test $testname"
500 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 sso_server
502 `$DOCKER ps |grep -E "\b$name\b" -q`
503 if [[ "$?" == "0" ]]; then
504 echo " $DOCKER stop $name"
507 `$DOCKER ps --all |grep -E "\b$name\b" -q`
508 if [[ "$?" == "0" ]]; then
509 echo " $DOCKER rm $name"
515 if [ "$DOCKER" == '' ]
517 echo "Docker not found. Please install it first."
523 echo "Curl not found. Please install it first."