3 DOCKER=`which docker.io`
5 if [[ "$DOCKER" == "" ]]; then
13 echo >&2 "usage: $0 (start|stop|restart|reset|test) [options]"
15 echo >&2 "start run new or restart stopped arvados containers"
16 echo >&2 "stop stop arvados containers"
17 echo >&2 "restart stop and then start arvados containers"
18 echo >&2 "reset stop and delete containers WARNING: this will delete the data inside Arvados!"
19 echo >&2 "test run tests"
21 echo >&2 "$0 options:"
22 echo >&2 " -d[port], --doc[=port] Documentation server (default port 9898)"
23 echo >&2 " -w[port], --workbench[=port] Workbench server (default port 9899)"
24 echo >&2 " -s[port], --sso[=port] SSO server (default port 9901)"
25 echo >&2 " -a[port], --api[=port] API server (default port 9900)"
26 echo >&2 " -c, --compute Compute nodes (starts 2)"
27 echo >&2 " -v, --vm Shell server"
28 echo >&2 " -n, --nameserver Nameserver"
29 echo >&2 " -k, --keep Keep servers"
30 echo >&2 " -p, --keepproxy Keepproxy server"
31 echo >&2 " -h, --help Display this help and exit"
33 echo >&2 " If no options are given, the action is applied to all servers."
35 echo >&2 "$0 test [testname] [testname] ..."
36 echo >&2 " By default, all tests are run."
41 echo `$DOCKER inspect $container |grep IPAddress |cut -f4 -d\"`
44 function start_container {
46 if [[ "$1" != '' ]]; then
50 if [[ "$2" != '' ]]; then
52 if [[ "$name" == "api_server" ]]; then
53 args="$args --dns=172.17.42.1 --dns-search=compute.dev.arvados --hostname api -P --name $name"
54 elif [[ "$name" == "compute" ]]; then
55 name=$name$COMPUTE_COUNTER
56 # We need --privileged because we run docker-inside-docker on the compute nodes
57 args="$args --dns=172.17.42.1 --dns-search=compute.dev.arvados --hostname compute$COMPUTE_COUNTER -P --privileged --name $name"
58 let COMPUTE_COUNTER=$(($COMPUTE_COUNTER + 1))
60 args="$args --dns=172.17.42.1 --dns-search=dev.arvados --hostname ${name#_server} --name $name"
63 if [[ "$3" != '' ]]; then
65 args="$args --volumes-from $volume"
67 if [[ "$4" != '' ]]; then
69 args="$args --link $link"
73 `$DOCKER ps |grep -P "$name[^/]" -q`
74 if [[ "$?" == "0" ]]; then
75 echo "You have a running container with name $name -- skipping."
79 echo "Starting container: $name"
80 `$DOCKER ps --all |grep -P "$name[^/]" -q`
81 if [[ "$?" == "0" ]]; then
82 echo " $DOCKER start $name"
83 container=`$DOCKER start $name`
85 echo " $DOCKER run $args $image"
86 container=`$DOCKER run $args $image`
89 if [ "$?" != "0" -o "$container" = "" ]; then
90 echo "Unable to start container"
93 echo "Started container: $container"
96 if [[ "$name" == "doc_server" ]]; then
98 echo "******************************************************************"
99 echo "You can access the Arvados documentation at http://doc.dev.arvados"
100 echo "******************************************************************"
104 if [[ "$name" == "workbench_server" ]]; then
106 echo "********************************************************************"
107 echo "You can access the Arvados workbench at http://workbench.dev.arvados"
108 echo "********************************************************************"
115 # Create a Docker data volume
116 function make_keep_volumes () {
117 `$DOCKER ps --all |grep -P "keep_data[^/]" -q`
118 if [[ "$?" == "0" ]]; then
121 docker create -v /keep-data --name keep_data arvados/keep
125 local start_doc=false
126 local start_sso=false
127 local start_api=false
128 local start_compute=false
129 local start_workbench=false
131 local start_nameserver=false
132 local start_keep=false
133 local start_keepproxy=false
136 # NOTE: This requires GNU getopt (part of the util-linux package on Debian-based distros).
137 local TEMP=`getopt -o d::s::a::cw::nkpvh \
138 --long doc::,sso::,api::,compute,workbench::,nameserver,keep,keepproxy,vm,help \
141 if [ $? != 0 ] ; then echo "Use -h for help"; exit 1 ; fi
143 # Note the quotes around `$TEMP': they are essential!
151 "") start_doc=9898; shift 2 ;;
152 *) start_doc=$2; shift 2 ;;
157 "") start_sso=9901; shift 2 ;;
158 *) start_sso=$2; shift 2 ;;
163 "") start_api=9900; shift 2 ;;
164 *) start_api=$2; shift 2 ;;
173 "") start_workbench=9899; shift 2 ;;
174 *) start_workbench=$2; shift 2 ;;
182 start_nameserver=true
204 # If no options were selected, then start all servers.
205 if [[ $start_doc == false &&
206 $start_sso == false &&
207 $start_api == false &&
208 $start_compute == false &&
209 $start_workbench == false &&
210 $start_vm == false &&
211 $start_nameserver == false &&
212 $start_keep == false &&
213 $start_keepproxy == false ]]
216 #the sso server is currently not used by default so don't start it unless explicitly requested
222 start_nameserver=true
227 if [[ $start_nameserver != false ]]
229 # We rely on skydock and skydns for dns discovery between the slurm controller and compute nodes,
230 # so make sure they are running
231 $DOCKER ps | grep skydns >/dev/null
232 if [[ "$?" != "0" ]]; then
233 echo "Starting crosbymichael/skydns container..."
234 $DOCKER rm "skydns" 2>/dev/null
235 echo $DOCKER run -d -p 172.17.42.1:53:53/udp --name skydns crosbymichael/skydns -nameserver 8.8.8.8:53 -domain arvados
236 $DOCKER run -d -p 172.17.42.1:53:53/udp --name skydns crosbymichael/skydns -nameserver 8.8.8.8:53 -domain arvados
238 $DOCKER ps | grep skydock >/dev/null
239 if [[ "$?" != "0" ]]; then
240 echo "Starting crosbymichael/skydock container..."
241 $DOCKER rm "skydock" 2>/dev/null
242 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
243 $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 if [[ $start_sso != false ]]
249 start_container "$start_sso:443" "sso_server" '' '' "arvados/sso"
252 if [[ $start_api != false ]]
254 if [[ $start_sso != false ]]; then
255 start_container "$start_api:443" "api_server" '' "sso_server:sso" "arvados/api"
257 start_container "$start_api:443" "api_server" '' '' "arvados/api"
261 if [[ $start_compute != false ]]
263 for i in `seq 0 $(($start_compute - 1))`; do
264 start_container "" "compute" '' "api_server:api" "arvados/compute"
268 if [[ $start_keep != false ]]
270 # create `keep_volumes' array with a list of keep mount points
271 # remove any stale metadata from those volumes before starting them
273 start_container "25107:25107" "keep_server_0" \
277 start_container "25108:25107" "keep_server_1" \
283 if [[ $start_keepproxy != false ]]
285 start_container "9902:9100" "keepproxy_server" '' \
290 if [[ $start_doc != false ]]
292 start_container "$start_doc:80" "doc_server" '' '' "arvados/doc"
295 if [[ $start_vm != false ]]
297 start_container "" "shell" '' "api_server:api" "arvados/shell"
300 if [[ $start_workbench != false ]]
302 start_container "$start_workbench:80" "workbench_server" '' "api_server:api" "arvados/workbench"
305 if [[ $start_api != false ]]
307 if [[ -f "api/generated/superuser_token" ]]
309 if [ -d $HOME/.config/arvados ] || mkdir -p $HOME/.config/arvados
311 cat >$HOME/.config/arvados/settings.conf <<EOF
312 ARVADOS_API_HOST=$(ip_address "api_server")
313 ARVADOS_API_HOST_INSECURE=yes
314 ARVADOS_API_TOKEN=$(cat api/generated/superuser_token)
320 `cat /etc/resolv.conf |grep -P "nameserver 172\.17\.42\.1" -q`
321 if [[ "$?" == "1" ]]; then
323 echo "******************************************************************"
324 echo "To access Arvados you must add the Arvados nameserver to the top"
325 echo "of your DNS configuration in /etc/resolv.conf:"
326 echo "nameserver 172.17.42.1"
327 echo "******************************************************************"
336 local stop_compute=""
337 local stop_workbench=""
338 local stop_nameserver=""
341 local stop_keepproxy=""
343 # NOTE: This requires GNU getopt (part of the util-linux package on Debian-based distros).
344 local TEMP=`getopt -o dsacwnkpvh \
345 --long doc,sso,api,compute,workbench,nameserver,keep,keepproxy,vm,help \
348 if [ $? != 0 ] ; then echo "Use -h for help"; exit 1 ; fi
350 # Note the quotes around `$TEMP': they are essential!
357 stop_doc=doc_server ; shift ;;
359 stop_sso=sso_server ; shift ;;
361 stop_api=api_server ; shift ;;
363 stop_compute=`$DOCKER ps |grep -P "compute\d+" |grep -v api_server |cut -f1 -d ' '` ; shift ;;
365 stop_workbench=workbench_server ; shift ;;
367 stop_nameserver="skydock skydns" ; shift ;;
369 stop_vm="shell" ; shift ;;
371 stop_keep="keep_server_0 keep_server_1" ; shift ;;
373 stop_keep="keepproxy_server" ; shift ;;
385 # If no options were selected, then stop all servers.
386 if [[ $stop_doc == "" &&
389 $stop_compute == "" &&
390 $stop_workbench == "" &&
392 $stop_nameserver == "" &&
394 $stop_keepproxy == "" ]]
399 stop_compute=`$DOCKER ps |grep -P "compute\d+" |grep -v api_server |cut -f1 -d ' '`
400 stop_workbench=workbench_server
402 stop_nameserver="skydock skydns"
403 stop_keep="keep_server_0 keep_server_1"
404 stop_keepproxy="keepproxy_server"
407 $DOCKER stop $stop_doc $stop_sso $stop_api $stop_compute $stop_workbench $stop_nameserver $stop_keep $stop_keepproxy $stop_vm \
415 alltests="python-sdk api"
420 for testname in $alltests
422 echo "testing $testname..."
425 do_start --api --keep --sso
426 export ARVADOS_API_HOST=$(ip_address "api_server")
427 export ARVADOS_API_HOST_INSECURE=yes
428 export ARVADOS_API_TOKEN=$(cat api/generated/superuser_token)
429 python -m unittest discover ../sdk/python
432 $DOCKER run -t -i arvados/api \
433 /usr/src/arvados/services/api/script/rake_test.sh
436 echo >&2 "unknown test $testname"
443 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
445 `$DOCKER ps |grep -P "$name[^/]" -q`
446 if [[ "$?" == "0" ]]; then
447 echo " $DOCKER stop $name"
450 `$DOCKER ps --all |grep -P "$name[^/]" -q`
451 if [[ "$?" == "0" ]]; then
452 echo " $DOCKER rm $name"