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 " -d[port], --doc[=port] Documentation server (default port 9898)"
25 echo >&2 " -w[port], --workbench[=port] Workbench server (default port 9899)"
26 echo >&2 " -s[port], --sso[=port] SSO server (default port 9901)"
27 echo >&2 " -a[port], --api[=port] API server (default port 9900)"
28 echo >&2 " -c, --compute Compute nodes (starts 2)"
29 echo >&2 " -v, --vm Shell server"
30 echo >&2 " -n, --nameserver Nameserver"
31 echo >&2 " -k, --keep Keep servers"
32 echo >&2 " -p, --keepproxy Keepproxy server"
33 echo >&2 " -h, --help Display this help and exit"
35 echo >&2 " If no options are given, the action is applied to all servers."
37 echo >&2 "$0 test [testname] [testname] ..."
38 echo >&2 " By default, all tests are run."
43 echo `$DOCKER inspect $container |grep IPAddress |cut -f4 -d\"`
46 function start_container {
48 if [[ "$1" != '' ]]; then
52 if [[ "$2" != '' ]]; then
54 if [[ "$name" == "api_server" ]]; then
55 args="$args --dns=172.17.42.1 --dns-search=compute.dev.arvados --hostname api -P --name $name"
56 elif [[ "$name" == "compute" ]]; then
57 name=$name$COMPUTE_COUNTER
58 # We need --privileged because we run docker-inside-docker on the compute nodes
59 args="$args --dns=172.17.42.1 --dns-search=compute.dev.arvados --hostname compute$COMPUTE_COUNTER -P --privileged --name $name"
60 let COMPUTE_COUNTER=$(($COMPUTE_COUNTER + 1))
62 args="$args --dns=172.17.42.1 --dns-search=dev.arvados --hostname ${name#_server} --name $name"
65 if [[ "$3" != '' ]]; then
67 args="$args --volumes-from $volume"
69 if [[ "$4" != '' ]]; then
71 args="$args --link $link"
75 `$DOCKER ps |grep -P "$name[^/]" -q`
76 if [[ "$?" == "0" ]]; then
77 echo "You have a running container with name $name -- skipping."
81 echo "Starting container: $name"
82 `$DOCKER ps --all |grep -P "$name[^/]" -q`
83 if [[ "$?" == "0" ]]; then
84 echo " $DOCKER start $name"
85 container=`$DOCKER start $name`
87 echo " $DOCKER run $args $image"
88 container=`$DOCKER run $args $image`
91 if [ "$?" != "0" -o "$container" = "" ]; then
92 echo "Unable to start container"
95 echo "Started container: $container"
100 # Create a Docker data volume
101 function make_keep_volumes () {
102 `$DOCKER ps --all |grep -P "keep_data[^/]" -q`
103 if [[ "$?" == "0" ]]; then
106 docker create -v /keep-data --name keep_data arvados/keep
110 local start_doc=false
111 local start_sso=false
112 local start_api=false
113 local start_compute=false
114 local start_workbench=false
116 local start_nameserver=false
117 local start_keep=false
118 local start_keepproxy=false
121 # NOTE: This requires GNU getopt (part of the util-linux package on Debian-based distros).
122 local TEMP=`getopt -o d::s::a::cw::nkpvh \
123 --long doc::,sso::,api::,compute,workbench::,nameserver,keep,keepproxy,vm,help \
126 if [ $? != 0 ] ; then echo "Use -h for help"; exit 1 ; fi
128 # Note the quotes around `$TEMP': they are essential!
136 "") start_doc=9898; shift 2 ;;
137 *) start_doc=$2; shift 2 ;;
142 "") start_sso=9901; shift 2 ;;
143 *) start_sso=$2; shift 2 ;;
148 "") start_api=9900; shift 2 ;;
149 *) start_api=$2; shift 2 ;;
158 "") start_workbench=9899; shift 2 ;;
159 *) start_workbench=$2; shift 2 ;;
167 start_nameserver=true
189 # If no options were selected, then start all servers.
190 if [[ $start_doc == false &&
191 $start_sso == false &&
192 $start_api == false &&
193 $start_compute == false &&
194 $start_workbench == false &&
195 $start_vm == false &&
196 $start_nameserver == false &&
197 $start_keep == false &&
198 $start_keepproxy == false ]]
201 #the sso server is currently not used by default so don't start it unless explicitly requested
207 start_nameserver=true
212 if [[ $start_nameserver != false ]]
214 # We rely on skydock and skydns for dns discovery between the slurm controller and compute nodes,
215 # so make sure they are running
216 $DOCKER ps | grep skydns >/dev/null
217 if [[ "$?" != "0" ]]; then
218 echo "Starting crosbymichael/skydns container..."
219 $DOCKER rm "skydns" 2>/dev/null
220 echo $DOCKER run -d -p 172.17.42.1:53:53/udp --name skydns crosbymichael/skydns -nameserver 8.8.8.8:53 -domain arvados
221 $DOCKER run -d -p 172.17.42.1:53:53/udp --name skydns crosbymichael/skydns -nameserver 8.8.8.8:53 -domain arvados
223 $DOCKER ps | grep skydock >/dev/null
224 if [[ "$?" != "0" ]]; then
225 echo "Starting crosbymichael/skydock container..."
226 $DOCKER rm "skydock" 2>/dev/null
227 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
228 $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
232 if [[ $start_sso != false ]]
234 start_container "$start_sso:443" "sso_server" '' '' "arvados/sso"
237 if [[ $start_api != false ]]
239 if [[ $start_sso != false ]]; then
240 start_container "$start_api:443" "api_server" '' "sso_server:sso" "arvados/api"
242 start_container "$start_api:443" "api_server" '' '' "arvados/api"
246 if [[ $start_compute != false ]]
248 for i in `seq 0 $(($start_compute - 1))`; do
249 start_container "" "compute" '' "api_server:api" "arvados/compute"
253 if [[ $start_keep != false ]]
255 # create `keep_volumes' array with a list of keep mount points
256 # remove any stale metadata from those volumes before starting them
258 start_container "25107:25107" "keep_server_0" \
262 start_container "25108:25107" "keep_server_1" \
268 if [[ $start_keepproxy != false ]]
270 start_container "9902:9100" "keepproxy_server" '' \
275 if [[ $start_doc != false ]]
277 start_container "$start_doc:80" "doc_server" '' '' "arvados/doc"
280 if [[ $start_vm != false ]]
282 start_container "" "shell" '' "api_server:api" "arvados/shell"
285 if [[ $start_workbench != false ]]
287 start_container "$start_workbench:80" "workbench_server" '' "api_server:api" "arvados/workbench"
290 if [[ $start_api != false ]]
292 if [[ -f "api/generated/superuser_token" ]]
294 if [ -d $HOME/.config/arvados ] || mkdir -p $HOME/.config/arvados
296 cat >$HOME/.config/arvados/settings.conf <<EOF
297 ARVADOS_API_HOST=$(ip_address "api_server")
298 ARVADOS_API_HOST_INSECURE=yes
299 ARVADOS_API_TOKEN=$(cat api/generated/superuser_token)
305 if [ "$(awk '($1 == "nameserver"){print $2; exit}' </etc/resolv.conf)" != "172.17.42.1" ]; then
307 echo "******************************************************************"
308 echo "To access Arvados you must add the Arvados nameserver to the top"
309 echo "of your DNS configuration in /etc/resolv.conf:"
310 echo "nameserver 172.17.42.1"
312 echo "Then run '$0 start' again"
313 echo "******************************************************************"
316 while ! $CURL -L -f http://workbench.dev.arvados >/dev/null 2>/dev/null ; do
317 echo "Waiting for Arvados to be ready."
321 `$DOCKER ps |grep -P "doc_server[^/]" -q`
322 if [[ "$?" == "0" ]]; then
324 echo "******************************************************************"
325 echo "You can access the Arvados documentation at http://doc.dev.arvados"
326 echo "******************************************************************"
330 `$DOCKER ps |grep -P "workbench_server[^/]" -q`
331 if [[ "$?" == "0" ]]; then
333 echo "********************************************************************"
334 echo "You can access the Arvados workbench at http://workbench.dev.arvados"
335 echo "********************************************************************"
346 local stop_compute=""
347 local stop_workbench=""
348 local stop_nameserver=""
351 local stop_keepproxy=""
353 # NOTE: This requires GNU getopt (part of the util-linux package on Debian-based distros).
354 local TEMP=`getopt -o dsacwnkpvh \
355 --long doc,sso,api,compute,workbench,nameserver,keep,keepproxy,vm,help \
358 if [ $? != 0 ] ; then echo "Use -h for help"; exit 1 ; fi
360 # Note the quotes around `$TEMP': they are essential!
367 stop_doc=doc_server ; shift ;;
369 stop_sso=sso_server ; shift ;;
371 stop_api=api_server ; shift ;;
373 stop_compute=`$DOCKER ps |grep -P "compute\d+" |grep -v api_server |cut -f1 -d ' '` ; shift ;;
375 stop_workbench=workbench_server ; shift ;;
377 stop_nameserver="skydock skydns" ; shift ;;
379 stop_vm="shell" ; shift ;;
381 stop_keep="keep_server_0 keep_server_1" ; shift ;;
383 stop_keep="keepproxy_server" ; shift ;;
395 # If no options were selected, then stop all servers.
396 if [[ $stop_doc == "" &&
399 $stop_compute == "" &&
400 $stop_workbench == "" &&
402 $stop_nameserver == "" &&
404 $stop_keepproxy == "" ]]
409 stop_compute=`$DOCKER ps |grep -P "compute\d+" |grep -v api_server |cut -f1 -d ' '`
410 stop_workbench=workbench_server
412 stop_nameserver="skydock skydns"
413 stop_keep="keep_server_0 keep_server_1"
414 stop_keepproxy="keepproxy_server"
417 $DOCKER stop $stop_doc $stop_sso $stop_api $stop_compute $stop_workbench $stop_nameserver $stop_keep $stop_keepproxy $stop_vm \
425 alltests="python-sdk api"
430 for testname in $alltests
432 echo "testing $testname..."
435 do_start --api --keep --sso
436 export ARVADOS_API_HOST=$(ip_address "api_server")
437 export ARVADOS_API_HOST_INSECURE=yes
438 export ARVADOS_API_TOKEN=$(cat api/generated/superuser_token)
439 python -m unittest discover ../sdk/python
442 $DOCKER run -t -i arvados/api \
443 /usr/src/arvados/services/api/script/rake_test.sh
446 echo >&2 "unknown test $testname"
453 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
455 `$DOCKER ps |grep -P "$name[^/]" -q`
456 if [[ "$?" == "0" ]]; then
457 echo " $DOCKER stop $name"
460 `$DOCKER ps --all |grep -P "$name[^/]" -q`
461 if [[ "$?" == "0" ]]; then
462 echo " $DOCKER rm $name"
468 if [ "$DOCKER" == '' ]
470 echo "Docker not found. Please install it first."
476 echo "Curl not found. Please install it first."