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 " -n, --nameserver Nameserver"
23 echo >&2 " -k, --keep Keep servers"
24 echo >&2 " --ssh Enable SSH access to server containers"
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 --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 --hostname compute$COMPUTE_COUNTER -P --privileged --name $name"
52 let COMPUTE_COUNTER=$(($COMPUTE_COUNTER + 1))
54 args="$args --name $name"
57 if [[ "$3" != '' ]]; then
59 args="$args -v $volume"
61 if [[ "$4" != '' ]]; then
63 args="$args --link $link"
69 args="$args -e ENABLE_SSH=$ENABLE_SSH"
72 `$DOCKER ps |grep -P "$name[^/]" -q`
73 if [[ "$?" == "0" ]]; then
74 echo "You have a running container with name $name -- skipping."
78 # Remove any existing container by this name.
79 $DOCKER rm "$name" 2>/dev/null
81 echo "Starting container:"
82 #echo " $DOCKER run --dns=127.0.0.1 $args $image"
83 echo " $DOCKER run $args $image"
84 container=`$DOCKER run --dns=172.17.42.1 --dns-search=compute.dev.arvados $args $image`
85 if [[ "$?" != "0" ]]; then
86 echo "Unable to start container"
91 ip=$(ip_address $container )
93 echo "You can ssh into the container with:"
99 if [[ "$name" == "doc_server" ]]; then
101 echo "*****************************************************************"
102 echo "You can access the Arvados documentation at http://localhost:${port%:*}"
103 echo "*****************************************************************"
107 if [[ "$name" == "workbench_server" ]]; then
109 echo "*****************************************************************"
110 echo "You can access the Arvados workbench at http://localhost:${port%:*}"
111 echo "*****************************************************************"
118 declare -a keep_volumes
120 # Initialize the global `keep_volumes' array. If any keep volumes
121 # already appear to exist (mounted volumes with a top-level "keep"
122 # directory), use them; create temporary volumes if necessary.
124 function make_keep_volumes () {
125 # Mount a keep volume if we don't already have one
126 for mountpoint in $(cut -d ' ' -f 2 /proc/mounts); do
127 if [[ -d "$mountpoint/keep" && "$mountpoint" != "/" ]]; then
128 keep_volumes+=($mountpoint)
132 # Create any keep volumes that do not yet exist.
133 while [ ${#keep_volumes[*]} -lt 2 ]
135 new_keep=$(mktemp -d)
136 echo >&2 "mounting 512M tmpfs keep volume in $new_keep"
137 sudo mount -t tmpfs -o size=512M tmpfs $new_keep
139 keep_volumes+=($new_keep)
144 local start_doc=false
145 local start_sso=false
146 local start_api=false
147 local start_compute=false
148 local start_workbench=false
149 local start_nameserver=false
150 local start_keep=false
152 # NOTE: This requires GNU getopt (part of the util-linux package on Debian-based distros).
153 local TEMP=`getopt -o d::s::a::c::w::nkh \
154 --long doc::,sso::,api::,compute::,workbench::,nameserver,keep,help,ssh \
157 if [ $? != 0 ] ; then echo "Use -h for help"; exit 1 ; fi
159 # Note the quotes around `$TEMP': they are essential!
167 "") start_doc=9898; shift 2 ;;
168 *) start_doc=$2; shift 2 ;;
173 "") start_sso=9901; shift 2 ;;
174 *) start_sso=$2; shift 2 ;;
179 "") start_api=9900; shift 2 ;;
180 *) start_api=$2; shift 2 ;;
185 "") start_compute=2; shift 2 ;;
186 *) start_compute=$2; shift 2 ;;
191 "") start_workbench=9899; shift 2 ;;
192 *) start_workbench=$2; shift 2 ;;
196 start_nameserver=true
204 # ENABLE_SSH is a global variable
219 # If no options were selected, then start all servers.
220 if [[ $start_doc == false &&
221 $start_sso == false &&
222 $start_api == false &&
223 $start_compute == false &&
224 $start_workbench == false &&
225 $start_nameserver == false &&
226 $start_keep == false ]]
233 start_nameserver=true
237 if [[ $start_sso != false ]]
239 start_container "$start_sso:443" "sso_server" '' '' "arvados/sso"
242 if [[ $start_api != false ]]
244 start_container "$start_api:443" "api_server" '' "sso_server:sso" "arvados/api"
247 if [[ $start_nameserver != false ]]
249 # We rely on skydock and skydns for dns discovery between the slurm controller and compute nodes,
250 # so make sure they are running
251 $DOCKER images | grep skydns >/dev/null
252 if [[ "$?" != "0" ]]; then
253 echo "Downloading crosbymichael/skydns..."
254 $DOCKER pull crosbymichael/skydns
256 $DOCKER ps | grep skydns >/dev/null
257 if [[ "$?" != "0" ]]; then
258 echo "Starting crosbymichael/skydns container..."
259 $DOCKER rm "skydns" 2>/dev/null
260 $DOCKER run -d -p 172.17.42.1:53:53/udp --name skydns crosbymichael/skydns -nameserver 8.8.8.8:53 -domain arvados
262 $DOCKER images | grep skydock >/dev/null
263 if [[ "$?" != "0" ]]; then
264 echo "Downloading crosbymichael/skydock..."
265 $DOCKER pull crosbymichael/skydock
267 $DOCKER ps | grep skydock >/dev/null
268 if [[ "$?" != "0" ]]; then
269 echo "Starting crosbymichael/skydock container..."
270 $DOCKER rm "skydock" 2>/dev/null
271 $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
275 if [[ $start_compute != false ]]
277 for i in `seq 0 $(($start_compute - 1))`; do
278 start_container "" "compute" '' "api_server:api" "arvados/compute"
282 if [[ $start_keep != false ]]
284 # create `keep_volumes' array with a list of keep mount points
285 # remove any stale metadata from those volumes before starting them
287 for v in ${keep_volumes[*]}
289 [ -f $v/keep/.metadata.yml ] && sudo rm $v/keep/.metadata.yml
291 start_container "25107:25107" "keep_server_0" \
292 "${keep_volumes[0]}:/dev/keep-0" \
295 start_container "25108:25107" "keep_server_1" \
296 "${keep_volumes[1]}:/dev/keep-0" \
301 if [[ $start_doc != false ]]
303 start_container "$start_doc:80" "doc_server" '' '' "arvados/doc"
306 if [[ $start_workbench != false ]]
308 start_container "$start_workbench:80" "workbench_server" '' "api_server:api" "arvados/workbench"
311 if [ -d $HOME/.config/arvados ] || mkdir -p $HOME/.config/arvados
313 cat >$HOME/.config/arvados/settings.conf <<EOF
314 ARVADOS_API_HOST=$(ip_address "api_server")
315 ARVADOS_API_HOST_INSECURE=yes
316 ARVADOS_API_TOKEN=$(cat api/generated/superuser_token)
326 local stop_compute=""
327 local stop_workbench=""
328 local stop_nameserver=""
331 # NOTE: This requires GNU getopt (part of the util-linux package on Debian-based distros).
332 local TEMP=`getopt -o dsacwnkh \
333 --long doc,sso,api,compute,workbench,nameserver,keep,help \
336 if [ $? != 0 ] ; then echo "Use -h for help"; exit 1 ; fi
338 # Note the quotes around `$TEMP': they are essential!
345 stop_doc=doc_server ; shift ;;
347 stop_sso=sso_server ; shift ;;
349 stop_api=api_server ; shift ;;
351 stop_compute=`$DOCKER ps |grep -P "compute\d+" |grep -v api_server |cut -f1 -d ' '` ; shift ;;
353 stop_workbench=workbench_server ; shift ;;
355 stop_keep="skydock skydns" ; shift ;;
357 stop_keep="keep_server_0 keep_server_1" ; shift ;;
369 # If no options were selected, then stop all servers.
370 if [[ $stop_doc == "" &&
373 $stop_compute == "" &&
374 $stop_workbench == "" &&
375 $stop_nameserver == "" &&
381 stop_compute=`$DOCKER ps |grep -P "compute\d+" |grep -v api_server |cut -f1 -d ' '`
382 stop_workbench=workbench_server
383 stop_nameserver="skydock skydns"
384 stop_keep="keep_server_0 keep_server_1"
387 $DOCKER stop $stop_doc $stop_sso $stop_api $stop_compute $stop_workbench $stop_nameserver $stop_keep \
395 alltests="python-sdk api"
400 for testname in $alltests
402 echo "testing $testname..."
405 do_start --api --keep --sso
406 export ARVADOS_API_HOST=$(ip_address "api_server")
407 export ARVADOS_API_HOST_INSECURE=yes
408 export ARVADOS_API_TOKEN=$(cat api/generated/superuser_token)
409 python -m unittest discover ../sdk/python
412 $DOCKER run -t -i arvados/api \
413 /usr/src/arvados/services/api/script/rake_test.sh
416 echo >&2 "unknown test $testname"