Merge branch '8080-arvbox' closes #8080
[arvados.git] / lib / arvbox / docker / service / ready / run-service
1 #!/bin/bash
2
3 . /usr/local/lib/arvbox/common.sh
4
5 set -eu -o pipefail
6
7 if ! [[ -d /tmp/arvbox-ready ]] ; then
8    echo
9    echo "Arvados-in-a-box starting"
10    echo
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 if ! which arv >/dev/null ; then
38   waiting="$waiting sdk"
39 elif ! which arv-get >/dev/null ; then
40   waiting="$waiting sdk"
41 fi
42
43 if ! (ps x | grep -v grep | grep "crunch-dispatch") > /dev/null ; then
44     waiting="$waiting crunch-dispatch"
45 fi
46
47 export ARVADOS_API_HOST=$localip:${services[api]}
48 export ARVADOS_API_HOST_INSECURE=1
49
50 vm_ok=0
51 if test -s /var/lib/arvados/vm-uuid -a -s /var/lib/arvados/superuser_token; then
52     vm_uuid=$(cat /var/lib/arvados/vm-uuid)
53     export ARVADOS_API_TOKEN=$(cat /var/lib/arvados/superuser_token)
54     if (which arv && arv virtual_machine get --uuid $vm_uuid) >/dev/null 2>/dev/null ; then
55         vm_ok=1
56     fi
57 fi
58
59 if test $vm_ok = 0 ; then
60     waiting="$waiting vm"
61 fi
62
63 if ! [[ -z "$waiting" ]] ; then
64     if ps x | grep -v grep | grep "bundle install" > /dev/null; then
65         gemcount=$(ls /var/lib/gems/ruby/2.1.0/gems 2>/dev/null | wc -l)
66
67         gemlockcount=0
68         for l in /usr/src/arvados/services/api/Gemfile.lock \
69                      /usr/src/arvados/apps/workbench/Gemfile.lock \
70                      /usr/src/sso/Gemfile.lock ; do
71             gc=$(cat $l \
72                         | grep -vE "(GEM|PLATFORMS|DEPENDENCIES|$^|remote:|specs:)" \
73                         | sed 's/^ *//' | sed 's/(.*)//' | sed 's/ *$//' | sort | uniq | wc -l)
74             gemlockcount=$(($gemlockcount + $gc))
75         done
76         waiting="$waiting (installing ruby gems $gemcount/$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 http://$localip"
93
94 rm -r /tmp/arvbox-ready
95
96 sv stop ready >/dev/null