6aab2950059ea6ccc3fc76c6de45d81aeb9090f4
[arvados.git] / tools / arvbox / lib / arvbox / docker / service / ready / run-service
1 #!/bin/bash
2 # Copyright (C) The Arvados Authors. All rights reserved.
3 #
4 # SPDX-License-Identifier: AGPL-3.0
5
6 . /usr/local/lib/arvbox/common.sh
7
8 set -eu -o pipefail
9
10 if ! [[ -d /tmp/arvbox-ready ]] ; then
11    echo "Note: if this is a fresh arvbox installation, it may take 10-15 minutes (or longer) to download and"
12    echo "install dependencies.  Use \"arvbox log\" to monitor the progress of specific services."
13    echo
14    mkdir -p /tmp/arvbox-ready
15 fi
16
17 sleep 3
18
19 waiting=""
20
21 for s in "${!services[@]}"
22 do
23   if ! [[ -f /tmp/arvbox-ready/$s ]] ; then
24     if nc -z localhost ${services[$s]} ; then
25       echo "$s is ready at $localip:${services[$s]}"
26       touch /tmp/arvbox-ready/$s
27     else
28       waiting="$waiting $s"
29     fi
30   fi
31 done
32
33 if ! docker version >/dev/null 2>/dev/null ; then
34   waiting="$waiting docker"
35 fi
36
37 for sdk_app in arv arv-get cwl-runner arv-mount ; do
38     if ! which $sdk_app >/dev/null ; then
39         waiting="$waiting sdk"
40         break
41     fi
42 done
43
44 if ! (ps ax | grep -v grep | grep "crunch-dispatch") > /dev/null ; then
45     waiting="$waiting crunch-dispatch"
46 fi
47
48 export ARVADOS_API_HOST=$localip:${services[controller-ssl]}
49 export ARVADOS_API_HOST_INSECURE=1
50
51 vm_ok=0
52 if test -s $ARVADOS_CONTAINER_PATH/vm-uuid -a -s $ARVADOS_CONTAINER_PATH/superuser_token; then
53     vm_uuid=$(cat $ARVADOS_CONTAINER_PATH/vm-uuid)
54     export ARVADOS_API_TOKEN=$(cat $ARVADOS_CONTAINER_PATH/superuser_token)
55     if (which arv && arv virtual_machine get --uuid $vm_uuid) >/dev/null 2>/dev/null ; then
56         vm_ok=1
57     fi
58 fi
59
60 if test $vm_ok = 0 ; then
61     waiting="$waiting vm"
62 fi
63
64 if ! [[ -z "$waiting" ]] ; then
65     if ps x | grep -v grep | grep "bundle install" > /dev/null; then
66         gemcount=0  # $(ls $GEM_HOME/gems 2>/dev/null | wc -l)
67
68         gemlockcount=0
69         for l in /usr/src/arvados/services/api/Gemfile.lock \
70                      /usr/src/arvados/apps/workbench/Gemfile.lock ; do
71             gc=$(cat $l \
72                         | grep -vE "(GEM|PLATFORMS|DEPENDENCIES|BUNDLED|GIT|$^|remote:|specs:|revision:)" \
73                         | sed 's/^ *//' | sed 's/(.*)//' | sed 's/ *$//' | sort | uniq | wc -l)
74             gemlockcount=$(($gemlockcount + $gc))
75         done
76         waiting="$waiting (installing ruby gems $gemcount of about $gemlockcount)"
77     fi
78
79     if ps x | grep -v grep | grep "c++.*/var/lib/passenger" > /dev/null ; then
80         waiting="$waiting (compiling passenger)"
81     fi
82
83     if ps x | grep -v grep | grep "pip install" > /dev/null; then
84         waiting="$waiting (installing python packages)"
85     fi
86     echo "    Waiting for$waiting ..."
87     exit 1
88 fi
89
90 echo
91 echo "Your Arvados-in-a-box is ready!"
92 echo "Workbench is running at https://$localip"
93 echo "Workbench2 is running at https://$localip:${services[workbench2-ssl]}"
94
95 rm -r /tmp/arvbox-ready