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 bridges could be there.. etc.
51 echo $(ip --oneline --family inet addr show dev "$bridge_name" | awk '{ print $4 }'| cut -d/ -f1 )
54 function start_container {
55 bridge_ip=$(bridge_ip_address "$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 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::b: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=$2; shift 2 ;;
152 "") start_doc=9898; shift 2 ;;
153 *) start_doc=$2; shift 2 ;;
158 "") start_sso=9901; shift 2 ;;
159 *) start_sso=$2; shift 2 ;;
164 "") start_api=9900; shift 2 ;;
165 *) start_api=$2; shift 2 ;;
174 "") start_workbench=9899; shift 2 ;;
175 *) start_workbench=$2; shift 2 ;;
183 start_nameserver=true
205 # If no options were selected, then start all servers.
206 if [[ $start_doc == false &&
207 $start_sso == false &&
208 $start_api == false &&
209 $start_compute == false &&
210 $start_workbench == false &&
211 $start_vm == false &&
212 $start_nameserver == false &&
213 $start_keep == false &&
214 $start_keepproxy == false ]]
217 #the sso server is currently not used by default so don't start it unless explicitly requested
223 start_nameserver=true
228 if [[ $start_nameserver != false ]]
230 # We rely on skydock and skydns for dns discovery between the slurm controller and compute nodes,
231 # so make sure they are running
232 $DOCKER ps | grep skydns >/dev/null
233 if [[ "$?" != "0" ]]; then
234 echo "Detecting bridge '$bridge' IP for crosbymichael/skydns"
235 bridge_ip=$(bridge_ip_address "$bridge")
237 echo "Starting crosbymichael/skydns container..."
238 $DOCKER rm "skydns" 2>/dev/null
239 echo $DOCKER run -d -p $bridge_ip:53:53/udp --name skydns crosbymichael/skydns -nameserver 8.8.8.8:53 -domain arvados
240 $DOCKER run -d -p $bridge_ip:53:53/udp --name skydns crosbymichael/skydns -nameserver 8.8.8.8:53 -domain arvados
242 $DOCKER ps | grep skydock >/dev/null
243 if [[ "$?" != "0" ]]; then
244 echo "Starting crosbymichael/skydock container..."
245 $DOCKER rm "skydock" 2>/dev/null
246 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
247 $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
251 if [[ $start_sso != false ]]
253 start_container "$start_sso:443" "sso_server" '' '' "arvados/sso"
256 if [[ $start_api != false ]]
258 if [[ $start_sso != false ]]; then
259 start_container "$start_api:443" "api_server" '' "sso_server:sso" "arvados/api"
261 start_container "$start_api:443" "api_server" '' '' "arvados/api"
265 if [[ $start_compute != false ]]
267 for i in `seq 0 $(($start_compute - 1))`; do
268 start_container "" "compute" '' "api_server:api" "arvados/compute"
272 if [[ $start_keep != false ]]
274 # create `keep_volumes' array with a list of keep mount points
275 # remove any stale metadata from those volumes before starting them
277 start_container "25107:25107" "keep_server_0" \
281 start_container "25108:25107" "keep_server_1" \
287 if [[ $start_keepproxy != false ]]
289 start_container "9902:9100" "keepproxy_server" '' \
294 if [[ $start_doc != false ]]
296 start_container "$start_doc:80" "doc_server" '' '' "arvados/doc"
299 if [[ $start_vm != false ]]
301 start_container "" "shell" '' "api_server:api" "arvados/shell"
304 if [[ $start_workbench != false ]]
306 start_container "$start_workbench:80" "workbench_server" '' "api_server:api" "arvados/workbench"
309 if [[ $start_api != false ]]
311 if [[ -f "api/generated/superuser_token" ]]
313 if [ -d $HOME/.config/arvados ] || mkdir -p $HOME/.config/arvados
315 cat >$HOME/.config/arvados/settings.conf <<EOF
316 ARVADOS_API_HOST=$(ip_address "api_server")
317 ARVADOS_API_HOST_INSECURE=yes
318 ARVADOS_API_TOKEN=$(cat api/generated/superuser_token)
324 if [ "$(awk '($1 == "nameserver"){print $2; exit}' </etc/resolv.conf)" != "$bridge_ip" ]; then
326 echo "******************************************************************"
327 echo "To access Arvados you must add the Arvados nameserver to the top"
328 echo "of your DNS configuration in /etc/resolv.conf:"
329 echo "nameserver $bridge_ip"
331 echo "Then run '$0 start' again"
332 echo "******************************************************************"
335 while ! $CURL -L -f http://workbench.dev.arvados >/dev/null 2>/dev/null ; do
336 echo "Waiting for Arvados to be ready."
340 `$DOCKER ps |grep -E "\bdoc_server\b" -q`
341 if [[ "$?" == "0" ]]; then
343 echo "******************************************************************"
344 echo "You can access the Arvados documentation at http://doc.dev.arvados"
345 echo "******************************************************************"
349 `$DOCKER ps |grep -E "\bworkbench_server\b" -q`
350 if [[ "$?" == "0" ]]; then
352 echo "********************************************************************"
353 echo "You can access the Arvados workbench at http://workbench.dev.arvados"
354 echo "********************************************************************"
365 local stop_compute=""
366 local stop_workbench=""
367 local stop_nameserver=""
370 local stop_keepproxy=""
372 # NOTE: This requires GNU getopt (part of the util-linux package on Debian-based distros).
373 local TEMP=`getopt -o dsacwnkpvh \
374 --long doc,sso,api,compute,workbench,nameserver,keep,keepproxy,vm,help \
377 if [ $? != 0 ] ; then echo "Use -h for help"; exit 1 ; fi
379 # Note the quotes around `$TEMP': they are essential!
386 stop_doc=doc_server ; shift ;;
388 stop_sso=sso_server ; shift ;;
390 stop_api=api_server ; shift ;;
392 stop_compute=`$DOCKER ps |grep -E "\bcompute[0-9]+\b" |grep -v api_server |cut -f1 -d ' '` ; shift ;;
394 stop_workbench=workbench_server ; shift ;;
396 stop_nameserver="skydock skydns" ; shift ;;
398 stop_vm="shell" ; shift ;;
400 stop_keep="keep_server_0 keep_server_1" ; shift ;;
402 stop_keep="keepproxy_server" ; shift ;;
414 # If no options were selected, then stop all servers.
415 if [[ $stop_doc == "" &&
418 $stop_compute == "" &&
419 $stop_workbench == "" &&
421 $stop_nameserver == "" &&
423 $stop_keepproxy == "" ]]
428 stop_compute=`$DOCKER ps |grep -E "\bcompute[0-9]+\b" |grep -v api_server |cut -f1 -d ' '`
429 stop_workbench=workbench_server
431 stop_nameserver="skydock skydns"
432 stop_keep="keep_server_0 keep_server_1"
433 stop_keepproxy="keepproxy_server"
436 $DOCKER stop $stop_doc $stop_sso $stop_api $stop_compute $stop_workbench $stop_nameserver $stop_keep $stop_keepproxy $stop_vm \
444 alltests="python-sdk api"
449 for testname in $alltests
451 echo "testing $testname..."
454 do_start --api --keep --sso
455 export ARVADOS_API_HOST=$(ip_address "api_server")
456 export ARVADOS_API_HOST_INSECURE=yes
457 export ARVADOS_API_TOKEN=$(cat api/generated/superuser_token)
458 python -m unittest discover ../sdk/python
461 $DOCKER run -t -i arvados/api \
462 /usr/src/arvados/services/api/script/rake_test.sh
465 echo >&2 "unknown test $testname"
472 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
474 `$DOCKER ps |grep -E "\b$name\b" -q`
475 if [[ "$?" == "0" ]]; then
476 echo " $DOCKER stop $name"
479 `$DOCKER ps --all |grep -E "\b$name\b" -q`
480 if [[ "$?" == "0" ]]; then
481 echo " $DOCKER rm $name"
487 if [ "$DOCKER" == '' ]
489 echo "Docker not found. Please install it first."
495 echo "Curl not found. Please install it first."