3 DOCKER=`which docker.io`
5 if [[ "$DOCKER" == "" ]]; then
13 echo >&2 "usage: $0 (start|stop|restart|test) [options]"
15 echo >&2 "$0 start/stop/restart options:"
16 echo >&2 " -d[port], --doc[=port] Documentation server (default port 9898)"
17 echo >&2 " -w[port], --workbench[=port] Workbench server (default port 9899)"
18 echo >&2 " -s[port], --sso[=port] SSO server (default port 9901)"
19 echo >&2 " -a[port], --api[=port] API server (default port 9900)"
20 echo >&2 " -c, --compute Compute nodes (starts 2)"
21 echo >&2 " -v, --vm Shell server"
22 echo >&2 " -n, --nameserver Nameserver"
23 echo >&2 " -k, --keep Keep servers"
24 echo >&2 " -p, --keepproxy Keepproxy server"
25 echo >&2 " -h, --help Display this help and exit"
27 echo >&2 " If no options are given, the action is applied to all servers."
29 echo >&2 "$0 test [testname] [testname] ..."
30 echo >&2 " By default, all tests are run."
35 echo `$DOCKER inspect $container |grep IPAddress |cut -f4 -d\"`
38 function start_container {
40 if [[ "$1" != '' ]]; then
44 if [[ "$2" != '' ]]; then
46 if [[ "$name" == "api_server" ]]; then
47 args="$args --dns=172.17.42.1 --dns-search=compute.dev.arvados --hostname api -P --name $name"
48 elif [[ "$name" == "compute" ]]; then
49 name=$name$COMPUTE_COUNTER
50 # We need --privileged because we run docker-inside-docker on the compute nodes
51 args="$args --dns=172.17.42.1 --dns-search=compute.dev.arvados --hostname compute$COMPUTE_COUNTER -P --privileged --name $name"
52 let COMPUTE_COUNTER=$(($COMPUTE_COUNTER + 1))
54 args="$args --dns=172.17.42.1 --dns-search=dev.arvados --hostname ${name#_server} --name $name"
57 if [[ "$3" != '' ]]; then
59 args="$args -v $volume"
61 if [[ "$4" != '' ]]; then
63 args="$args --link $link"
67 `$DOCKER ps |grep -P "$name[^/]" -q`
68 if [[ "$?" == "0" ]]; then
69 echo "You have a running container with name $name -- skipping."
73 # Remove any existing container by this name.
74 $DOCKER rm "$name" 2>/dev/null
76 echo "Starting container:"
77 echo " $DOCKER run $args $image"
78 container=`$DOCKER run $args $image`
79 if [ "$?" != "0" -o "$container" = "" ]; then
80 echo "Unable to start container"
83 echo "Started container: $container"
86 if [[ "$name" == "doc_server" ]]; then
88 echo "*****************************************************************"
89 echo "You can access the Arvados documentation at http://localhost:${port%:*}"
90 echo "*****************************************************************"
94 if [[ "$name" == "workbench_server" ]]; then
96 echo "*****************************************************************"
97 echo "You can access the Arvados workbench at http://localhost:${port%:*}"
98 echo "*****************************************************************"
105 declare -a keep_volumes
107 # Initialize the global `keep_volumes' array. If any keep volumes
108 # already appear to exist (mounted volumes with a top-level "keep"
109 # directory), use them; create temporary volumes if necessary.
111 function make_keep_volumes () {
112 # Mount a keep volume if we don't already have one
113 for mountpoint in $(cut -d ' ' -f 2 /proc/mounts); do
114 if [[ -d "$mountpoint/keep" && "$mountpoint" != "/" ]]; then
115 keep_volumes+=($mountpoint)
119 # Create any keep volumes that do not yet exist.
120 while [ ${#keep_volumes[*]} -lt 2 ]
122 new_keep=$(mktemp -d)
123 echo >&2 "mounting 2G tmpfs keep volume in $new_keep"
124 sudo mount -t tmpfs -o size=2G tmpfs $new_keep
126 keep_volumes+=($new_keep)
131 local start_doc=false
132 local start_sso=false
133 local start_api=false
134 local start_compute=false
135 local start_workbench=false
137 local start_nameserver=false
138 local start_keep=false
139 local start_keepproxy=false
141 # NOTE: This requires GNU getopt (part of the util-linux package on Debian-based distros).
142 local TEMP=`getopt -o d::s::a::cw::nkpvh \
143 --long doc::,sso::,api::,compute,workbench::,nameserver,keep,keepproxy,vm,help \
146 if [ $? != 0 ] ; then echo "Use -h for help"; exit 1 ; fi
148 # Note the quotes around `$TEMP': they are essential!
156 "") start_doc=9898; shift 2 ;;
157 *) start_doc=$2; shift 2 ;;
162 "") start_sso=9901; shift 2 ;;
163 *) start_sso=$2; shift 2 ;;
168 "") start_api=9900; shift 2 ;;
169 *) start_api=$2; shift 2 ;;
178 "") start_workbench=9899; shift 2 ;;
179 *) start_workbench=$2; shift 2 ;;
187 start_nameserver=true
209 # If no options were selected, then start all servers.
210 if [[ $start_doc == false &&
211 $start_sso == false &&
212 $start_api == false &&
213 $start_compute == false &&
214 $start_workbench == false &&
215 $start_vm == false &&
216 $start_nameserver == false &&
217 $start_keep == false &&
218 $start_keepproxy == false ]]
221 #the sso server is currently not used by default so don't start it unless explicitly requested
227 start_nameserver=true
232 if [[ $start_nameserver != false ]]
234 # We rely on skydock and skydns for dns discovery between the slurm controller and compute nodes,
235 # so make sure they are running
236 $DOCKER ps | grep skydns >/dev/null
237 if [[ "$?" != "0" ]]; then
238 echo "Starting crosbymichael/skydns container..."
239 $DOCKER rm "skydns" 2>/dev/null
240 $DOCKER run -d -p 172.17.42.1: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 $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
250 if [[ $start_sso != false ]]
252 start_container "$start_sso:443" "sso_server" '' '' "arvados/sso"
255 if [[ $start_api != false ]]
257 if [[ $start_sso != false ]]; then
258 start_container "$start_api:443" "api_server" '' "sso_server:sso" "arvados/api"
260 start_container "$start_api:443" "api_server" '' '' "arvados/api"
264 if [[ $start_compute != false ]]
266 for i in `seq 0 $(($start_compute - 1))`; do
267 start_container "" "compute" '' "api_server:api" "arvados/compute"
271 if [[ $start_keep != false ]]
273 # create `keep_volumes' array with a list of keep mount points
274 # remove any stale metadata from those volumes before starting them
276 for v in ${keep_volumes[*]}
278 [ -f $v/keep/.metadata.yml ] && sudo rm $v/keep/.metadata.yml
280 start_container "25107:25107" "keep_server_0" \
281 "${keep_volumes[0]}:/keep-data" \
284 start_container "25108:25107" "keep_server_1" \
285 "${keep_volumes[1]}:/keep-data" \
290 if [[ $start_keepproxy != false ]]
292 start_container "9902:9100" "keepproxy_server" '' \
297 if [[ $start_doc != false ]]
299 start_container "$start_doc:80" "doc_server" '' '' "arvados/doc"
302 if [[ $start_vm != false ]]
304 start_container "" "shell" '' "api_server:api" "arvados/shell"
307 if [[ $start_workbench != false ]]
309 start_container "$start_workbench:80" "workbench_server" '' "api_server:api" "arvados/workbench"
312 if [[ $start_api != false ]]
314 if [[ -f "api/generated/superuser_token" ]]
316 if [ -d $HOME/.config/arvados ] || mkdir -p $HOME/.config/arvados
318 cat >$HOME/.config/arvados/settings.conf <<EOF
319 ARVADOS_API_HOST=$(ip_address "api_server")
320 ARVADOS_API_HOST_INSECURE=yes
321 ARVADOS_API_TOKEN=$(cat api/generated/superuser_token)
332 local stop_compute=""
333 local stop_workbench=""
334 local stop_nameserver=""
337 local stop_keepproxy=""
339 # NOTE: This requires GNU getopt (part of the util-linux package on Debian-based distros).
340 local TEMP=`getopt -o dsacwnkpvh \
341 --long doc,sso,api,compute,workbench,nameserver,keep,keepproxy,vm,help \
344 if [ $? != 0 ] ; then echo "Use -h for help"; exit 1 ; fi
346 # Note the quotes around `$TEMP': they are essential!
353 stop_doc=doc_server ; shift ;;
355 stop_sso=sso_server ; shift ;;
357 stop_api=api_server ; shift ;;
359 stop_compute=`$DOCKER ps |grep -P "compute\d+" |grep -v api_server |cut -f1 -d ' '` ; shift ;;
361 stop_workbench=workbench_server ; shift ;;
363 stop_nameserver="skydock skydns" ; shift ;;
365 stop_vm="shell" ; shift ;;
367 stop_keep="keep_server_0 keep_server_1" ; shift ;;
369 stop_keep="keepproxy_server" ; shift ;;
381 # If no options were selected, then stop all servers.
382 if [[ $stop_doc == "" &&
385 $stop_compute == "" &&
386 $stop_workbench == "" &&
388 $stop_nameserver == "" &&
390 $stop_keepproxy == "" ]]
395 stop_compute=`$DOCKER ps |grep -P "compute\d+" |grep -v api_server |cut -f1 -d ' '`
396 stop_workbench=workbench_server
398 stop_nameserver="skydock skydns"
399 stop_keep="keep_server_0 keep_server_1"
400 stop_keepproxy="keepproxy_server"
403 $DOCKER stop $stop_doc $stop_sso $stop_api $stop_compute $stop_workbench $stop_nameserver $stop_keep $stop_keepproxy $stop_vm \
411 alltests="python-sdk api"
416 for testname in $alltests
418 echo "testing $testname..."
421 do_start --api --keep --sso
422 export ARVADOS_API_HOST=$(ip_address "api_server")
423 export ARVADOS_API_HOST_INSECURE=yes
424 export ARVADOS_API_TOKEN=$(cat api/generated/superuser_token)
425 python -m unittest discover ../sdk/python
428 $DOCKER run -t -i arvados/api \
429 /usr/src/arvados/services/api/script/rake_test.sh
432 echo >&2 "unknown test $testname"