4 DOCKER=`which docker.io`
6 if [[ "$DOCKER" == "" ]]; then
14 echo >&2 "usage: $0 (start|stop|restart|test) [options]"
16 echo >&2 "$0 start/stop/restart options:"
17 echo >&2 " -d[port], --doc[=port] Documentation server (default port 9898)"
18 echo >&2 " -w[port], --workbench[=port] Workbench server (default port 9899)"
19 echo >&2 " -s[port], --sso[=port] SSO server (default port 9901)"
20 echo >&2 " -a[port], --api[=port] API server (default port 9900)"
21 echo >&2 " -c[count], --compute[=count] Compute nodes (default starts 2)"
22 echo >&2 " -v, --vm Shell server"
23 echo >&2 " -n, --nameserver Nameserver"
24 echo >&2 " -k, --keep Keep servers"
25 echo >&2 " --ssh Enable SSH access to server containers"
26 echo >&2 " -h, --help Display this help and exit"
28 echo >&2 " If no options are given, the action is applied to all servers."
30 echo >&2 "$0 test [testname] [testname] ..."
31 echo >&2 " By default, all tests are run."
36 echo `$DOCKER inspect $container |grep IPAddress |cut -f4 -d\"`
39 function start_container {
41 if [[ "$1" != '' ]]; then
45 if [[ "$2" != '' ]]; then
47 if [[ "$name" == "api_server" ]]; then
48 args="$args --dns=172.17.42.1 --dns-search=compute.dev.arvados --hostname api -P --name $name"
49 elif [[ "$name" == "compute" ]]; then
50 name=$name$COMPUTE_COUNTER
51 # We need --privileged because we run docker-inside-docker on the compute nodes
52 args="$args --dns=172.17.42.1 --dns-search=compute.dev.arvados --hostname compute$COMPUTE_COUNTER -P --privileged --name $name"
53 let COMPUTE_COUNTER=$(($COMPUTE_COUNTER + 1))
55 args="$args --dns=172.17.42.1 --dns-search=dev.arvados --hostname ${name#_server} --name $name"
58 if [[ "$3" != '' ]]; then
60 args="$args -v $volume"
62 if [[ "$4" != '' ]]; then
64 args="$args --link $link"
70 args="$args -e ENABLE_SSH=$ENABLE_SSH"
73 `$DOCKER ps |grep -P "$name[^/]" -q`
74 if [[ "$?" == "0" ]]; then
75 echo "You have a running container with name $name -- skipping."
79 # Remove any existing container by this name.
80 $DOCKER rm "$name" 2>/dev/null
82 echo "Starting container:"
83 #echo " $DOCKER run --dns=127.0.0.1 $args $image"
84 echo " $DOCKER run $args $image"
85 container=`$DOCKER run $args $image`
86 if [[ "$?" != "0" ]]; then
87 echo "Unable to start container"
90 if [[ "$name" == "compute" || $ENABLE_SSH ]];
92 ip=$(ip_address $container )
94 echo "You can ssh into the container with:"
100 if [[ "$name" == "doc_server" ]]; then
102 echo "*****************************************************************"
103 echo "You can access the Arvados documentation at http://localhost:${port%:*}"
104 echo "*****************************************************************"
108 if [[ "$name" == "workbench_server" ]]; then
110 echo "*****************************************************************"
111 echo "You can access the Arvados workbench at http://localhost:${port%:*}"
112 echo "*****************************************************************"
119 declare -a keep_volumes
121 # Initialize the global `keep_volumes' array. If any keep volumes
122 # already appear to exist (mounted volumes with a top-level "keep"
123 # directory), use them; create temporary volumes if necessary.
125 function make_keep_volumes () {
126 # Mount a keep volume if we don't already have one
127 for mountpoint in $(cut -d ' ' -f 2 /proc/mounts); do
128 if [[ -d "$mountpoint/keep" && "$mountpoint" != "/" ]]; then
129 keep_volumes+=($mountpoint)
133 # Create any keep volumes that do not yet exist.
134 while [ ${#keep_volumes[*]} -lt 2 ]
136 new_keep=$(mktemp -d)
137 echo >&2 "mounting 512M tmpfs keep volume in $new_keep"
138 sudo mount -t tmpfs -o size=512M tmpfs $new_keep
140 keep_volumes+=($new_keep)
145 local start_doc=false
146 local start_sso=false
147 local start_api=false
148 local start_compute=false
149 local start_workbench=false
151 local start_nameserver=false
152 local start_keep=false
154 # NOTE: This requires GNU getopt (part of the util-linux package on Debian-based distros).
155 local TEMP=`getopt -o d::s::a::c::w::nkvh \
156 --long doc::,sso::,api::,compute::,workbench::,nameserver,keep,vm,help,ssh \
159 if [ $? != 0 ] ; then echo "Use -h for help"; exit 1 ; fi
161 # Note the quotes around `$TEMP': they are essential!
169 "") start_doc=9898; shift 2 ;;
170 *) start_doc=$2; shift 2 ;;
175 "") start_sso=9901; shift 2 ;;
176 *) start_sso=$2; shift 2 ;;
181 "") start_api=9900; shift 2 ;;
182 *) start_api=$2; shift 2 ;;
187 "") start_compute=2; shift 2 ;;
188 *) start_compute=$2; shift 2 ;;
193 "") start_workbench=9899; shift 2 ;;
194 *) start_workbench=$2; shift 2 ;;
202 start_nameserver=true
210 # ENABLE_SSH is a global variable
225 # If no options were selected, then start all servers.
226 if [[ $start_doc == false &&
227 $start_sso == false &&
228 $start_api == false &&
229 $start_compute == false &&
230 $start_workbench == false &&
231 $start_vm == false &&
232 $start_nameserver == false &&
233 $start_keep == false ]]
241 start_nameserver=true
245 if [[ $start_sso != false ]]
247 start_container "$start_sso:443" "sso_server" '' '' "arvados/sso"
250 if [[ $start_api != false ]]
252 start_container "$start_api:443" "api_server" '' "sso_server:sso" "arvados/api"
255 if [[ $start_nameserver != false ]]
257 # We rely on skydock and skydns for dns discovery between the slurm controller and compute nodes,
258 # so make sure they are running
259 $DOCKER images | grep skydns >/dev/null
260 if [[ "$?" != "0" ]]; then
261 echo "Downloading crosbymichael/skydns..."
262 $DOCKER pull crosbymichael/skydns
264 $DOCKER ps | grep skydns >/dev/null
265 if [[ "$?" != "0" ]]; then
266 echo "Starting crosbymichael/skydns container..."
267 $DOCKER rm "skydns" 2>/dev/null
268 $DOCKER run -d -p 172.17.42.1:53:53/udp --name skydns crosbymichael/skydns -nameserver 8.8.8.8:53 -domain arvados
270 $DOCKER images | grep skydock >/dev/null
271 if [[ "$?" != "0" ]]; then
272 echo "Downloading crosbymichael/skydock..."
273 $DOCKER pull crosbymichael/skydock
275 $DOCKER ps | grep skydock >/dev/null
276 if [[ "$?" != "0" ]]; then
277 echo "Starting crosbymichael/skydock container..."
278 $DOCKER rm "skydock" 2>/dev/null
279 $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
283 if [[ $start_compute != false ]]
285 for i in `seq 0 $(($start_compute - 1))`; do
286 start_container "" "compute" '' "api_server:api" "arvados/compute"
290 if [[ $start_keep != false ]]
292 # create `keep_volumes' array with a list of keep mount points
293 # remove any stale metadata from those volumes before starting them
295 for v in ${keep_volumes[*]}
297 [ -f $v/keep/.metadata.yml ] && sudo rm $v/keep/.metadata.yml
299 start_container "25107:25107" "keep_server_0" \
300 "${keep_volumes[0]}:/dev/keep-0" \
303 start_container "25108:25107" "keep_server_1" \
304 "${keep_volumes[1]}:/dev/keep-0" \
309 if [[ $start_doc != false ]]
311 start_container "$start_doc:80" "doc_server" '' '' "arvados/doc"
314 if [[ $start_vm != false ]]
316 start_container "" "shell" '' "api_server:api" "arvados/shell"
319 if [[ $start_workbench != false ]]
321 start_container "$start_workbench:80" "workbench_server" '' "api_server:api" "arvados/workbench"
324 if [ -d $HOME/.config/arvados ] || mkdir -p $HOME/.config/arvados
326 cat >$HOME/.config/arvados/settings.conf <<EOF
327 ARVADOS_API_HOST=$(ip_address "api_server")
328 ARVADOS_API_HOST_INSECURE=yes
329 ARVADOS_API_TOKEN=$(cat api/generated/superuser_token)
339 local stop_compute=""
340 local stop_workbench=""
341 local stop_nameserver=""
345 # NOTE: This requires GNU getopt (part of the util-linux package on Debian-based distros).
346 local TEMP=`getopt -o dsacwnkvh \
347 --long doc,sso,api,compute,workbench,nameserver,keep,vm,help \
350 if [ $? != 0 ] ; then echo "Use -h for help"; exit 1 ; fi
352 # Note the quotes around `$TEMP': they are essential!
359 stop_doc=doc_server ; shift ;;
361 stop_sso=sso_server ; shift ;;
363 stop_api=api_server ; shift ;;
365 stop_compute=`$DOCKER ps |grep -P "compute\d+" |grep -v api_server |cut -f1 -d ' '` ; shift ;;
367 stop_workbench=workbench_server ; shift ;;
369 stop_nameserver="skydock skydns" ; shift ;;
371 stop_vm="shell" ; shift ;;
373 stop_keep="keep_server_0 keep_server_1" ; shift ;;
385 # If no options were selected, then stop all servers.
386 if [[ $stop_doc == "" &&
389 $stop_compute == "" &&
390 $stop_workbench == "" &&
392 $stop_nameserver == "" &&
398 stop_compute=`$DOCKER ps |grep -P "compute\d+" |grep -v api_server |cut -f1 -d ' '`
399 stop_workbench=workbench_server
401 stop_nameserver="skydock skydns"
402 stop_keep="keep_server_0 keep_server_1"
405 $DOCKER stop $stop_doc $stop_sso $stop_api $stop_compute $stop_workbench $stop_nameserver $stop_keep $stop_vm \
413 alltests="python-sdk api"
418 for testname in $alltests
420 echo "testing $testname..."
423 do_start --api --keep --sso
424 export ARVADOS_API_HOST=$(ip_address "api_server")
425 export ARVADOS_API_HOST_INSECURE=yes
426 export ARVADOS_API_TOKEN=$(cat api/generated/superuser_token)
427 python -m unittest discover ../sdk/python
430 $DOCKER run -t -i arvados/api \
431 /usr/src/arvados/services/api/script/rake_test.sh
434 echo >&2 "unknown test $testname"