4 DOCKER=`which docker.io`
6 if [[ "$DOCKER" == "" ]]; then
12 echo >&2 "usage: $0 (start|stop|restart|test) [options]"
14 echo >&2 "$0 start/stop/restart options:"
15 echo >&2 " -d [port], --doc[=port] Documentation server (default port 9898)"
16 echo >&2 " -w [port], --workbench[=port] Workbench server (default port 9899)"
17 echo >&2 " -s [port], --sso[=port] SSO server (default port 9901)"
18 echo >&2 " -a [port], --api[=port] API server (default port 9900)"
19 echo >&2 " -k, --keep Keep servers"
20 echo >&2 " --ssh Enable SSH access to server containers"
21 echo >&2 " -h, --help Display this help and exit"
23 echo >&2 " If no options are given, the action is applied to all servers."
25 echo >&2 "$0 test [testname] [testname] ..."
26 echo >&2 " By default, all tests are run."
31 echo `$DOCKER inspect $container |grep IPAddress |cut -f4 -d\"`
34 function start_container {
36 if [[ "$1" != '' ]]; then
40 if [[ "$2" != '' ]]; then
42 args="$args --name $name"
44 if [[ "$3" != '' ]]; then
46 args="$args -v $volume"
48 if [[ "$4" != '' ]]; then
50 args="$args --link $link"
56 args="$args -e ENABLE_SSH=$ENABLE_SSH"
59 `$DOCKER ps |grep -P "$name[^/]" -q`
60 if [[ "$?" == "0" ]]; then
61 echo "You have a running container with name $name -- skipping."
65 # Remove any existing container by this name.
66 $DOCKER rm "$name" 2>/dev/null
68 echo "Starting container:"
69 echo " $DOCKER run $args $image"
70 container=`$DOCKER run $args $image`
71 if [[ "$?" != "0" ]]; then
72 echo "Unable to start container"
77 ip=$(ip_address $container )
79 echo "You can ssh into the container with:"
85 if [[ "$name" == "doc_server" ]]; then
87 echo "*****************************************************************"
88 echo "You can access the Arvados documentation at http://localhost:${port%:*}"
89 echo "*****************************************************************"
93 if [[ "$name" == "workbench_server" ]]; then
95 echo "*****************************************************************"
96 echo "You can access the Arvados workbench at http://localhost:${port%:*}"
97 echo "*****************************************************************"
104 declare -a keep_volumes
106 # Initialize the global `keep_volumes' array. If any keep volumes
107 # already appear to exist (mounted volumes with a top-level "keep"
108 # directory), use them; create temporary volumes if necessary.
110 function make_keep_volumes () {
111 # Mount a keep volume if we don't already have one
112 for mountpoint in $(cut -d ' ' -f 2 /proc/mounts); do
113 if [[ -d "$mountpoint/keep" && "$mountpoint" != "/" ]]; then
114 keep_volumes+=($mountpoint)
118 # Create any keep volumes that do not yet exist.
119 while [ ${#keep_volumes[*]} -lt 2 ]
121 new_keep=$(mktemp -d)
122 echo >&2 "mounting 512M tmpfs keep volume in $new_keep"
123 sudo mount -t tmpfs -o size=512M tmpfs $new_keep
125 keep_volumes+=($new_keep)
130 local start_doc=false
131 local start_sso=false
132 local start_api=false
133 local start_workbench=false
134 local start_keep=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::w::kh \
138 --long doc::,sso::,api::,workbench::,keep,help,ssh \
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 ;;
169 "") start_workbench=9899; shift 2 ;;
170 *) start_workbench=$2; shift 2 ;;
178 # ENABLE_SSH is a global variable
193 # If no options were selected, then start all servers.
194 if [[ $start_doc == false &&
195 $start_sso == false &&
196 $start_api == false &&
197 $start_workbench == false &&
198 $start_keep == false ]]
207 if [[ $start_sso != false ]]
209 start_container "$start_sso:443" "sso_server" '' '' "arvados/sso"
212 if [[ $start_api != false ]]
214 start_container "$start_api:443" "api_server" '' "sso_server:sso" "arvados/api"
217 if [[ $start_keep != false ]]
219 # create `keep_volumes' array with a list of keep mount points
220 # remove any stale metadata from those volumes before starting them
222 for v in ${keep_volumes[*]}
224 [ -f $v/keep/.metadata.yml ] && sudo rm $v/keep/.metadata.yml
226 start_container "25107:25107" "keep_server_0" \
227 "${keep_volumes[0]}:/dev/keep-0" \
230 start_container "25108:25107" "keep_server_1" \
231 "${keep_volumes[1]}:/dev/keep-0" \
236 if [[ $start_doc != false ]]
238 start_container "$start_doc:80" "doc_server" '' '' "arvados/doc"
241 if [[ $start_workbench != false ]]
243 start_container "$start_workbench:80" "workbench_server" '' "api_server:api" "arvados/workbench"
246 if [ -d $HOME/.config/arvados ] || mkdir -p $HOME/.config/arvados
248 cat >$HOME/.config/arvados/settings.conf <<EOF
249 ARVADOS_API_HOST=$(ip_address "api_server")
250 ARVADOS_API_HOST_INSECURE=yes
251 ARVADOS_API_TOKEN=$(cat api/generated/superuser_token)
261 local stop_workbench=""
264 # NOTE: This requires GNU getopt (part of the util-linux package on Debian-based distros).
265 local TEMP=`getopt -o d::s::a::w::kh \
266 --long doc::,sso::,api::,workbench::,keep,help,ssh \
269 if [ $? != 0 ] ; then echo "Use -h for help"; exit 1 ; fi
271 # Note the quotes around `$TEMP': they are essential!
278 stop_doc=doc_server ; shift 2 ;;
280 stop_sso=sso_server ; shift 2 ;;
282 stop_api=api_server ; shift 2 ;;
284 stop_workbench=workbench_server ; shift 2 ;;
286 stop_keep="keep_server_0 keep_server_1" ; shift ;;
301 # If no options were selected, then stop all servers.
302 if [[ $stop_doc == "" &&
305 $stop_workbench == "" &&
311 stop_workbench=workbench_server
312 stop_keep="keep_server_0 keep_server_1"
315 $DOCKER stop $stop_doc $stop_sso $stop_api $stop_workbench $stop_keep \
323 alltests="python-sdk api"
328 for testname in $alltests
330 echo "testing $testname..."
333 do_start --api --keep --sso
334 export ARVADOS_API_HOST=$(ip_address "api_server")
335 export ARVADOS_API_HOST_INSECURE=yes
336 export ARVADOS_API_TOKEN=$(cat api/generated/superuser_token)
337 python -m unittest discover ../sdk/python
340 $DOCKER run -t -i arvados/api \
341 /usr/src/arvados/services/api/script/rake_test.sh
344 echo >&2 "unknown test $testname"