-
Notifications
You must be signed in to change notification settings - Fork 25
/
databox-start
executable file
·177 lines (147 loc) · 4.06 KB
/
databox-start
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/bin/bash
#include helper functions
source ./scripts/utils.sh
## debug
if [[ "$DATABOX_DEBUG" = "true" ]]; then
set -x
PS4='$LINENO: '
fi
declare -r ME="$(basename $0)"
## check we have the tools
if ! [ -x "$(command -v docker)" ]; then
die 1 "docker is not installed;"`
`"see https://docs.docker.com/engine/installation/"
fi
if ! [ -x "$(command -v docker-compose)" ]; then
die 2 "docker-compose is not installed;"`
`"see https://docs.docker.com/compose/install/#install-compose"
fi
## parse command line args
DOCKER_REPO="" #default to local images
DATABOX_SDK="0"
DATABOX_DEV="0"
DEV=0
SDK=0
case "$1" in
dev )
DEV=1
export DATABOX_DEV="1"
;;
sdk )
SDK=1
;;
esac
#Start the SDK
if [ "$SDK" == "1" ]
then
err "Starting SDK"
export HOSTMOUNT=$(pwd -P)
docker-compose -f docker-databox-sdk.yaml up -d
fi
## test if Databox is already running
err "testing if Databox is already running ..."
docker node ls >/dev/null 2>&1
assert_or_die $? 1 "Databox is already running!"
## extract a host interface IP address
err "extracting host interface IP address ..."
ips=($(ifconfig | grep "inet " | grep -v 127.0.0.1|awk 'match($0, /([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/) {print substr($0,RSTART,RLENGTH)}'))
EXT_IP=${ips}
if [[ "${#ips[@]}" -gt "1" ]]; then
err "More than one IP found! Please select one:"
if [[ "${DATABOX_TESTING}" == 1 ]]
then
err "running in testing mode select second IP ${ips[1]}"
EXT_IP=${ips[1]}
else
select ip in ${ips[*]}; do
case ${ip} in
exit )
die 0 "exiting ..."
break
;;
* )
EXT_IP=${ip}
break
;;
esac
done
fi
fi
err "host interface IP address = ${EXT_IP}"
## base images: what are we running on?
ARCH=$(uname -m)
case "$ARCH" in
armv7l )
NODE_IMAGE="hypriot/rpi-node:slim"
DEV=1 #ARM is only supported in dev mode with localy built images (for now)
export DATABOX_ARCH="-"${ARCH}
export DATABOX_DEV="1"
;;
aarch64 )
NODE_IMAGE="forumi0721alpineaarch64/alpine-aarch64-nodejs"
DEV=1 #ARM is only supported in dev mode with localy built images (for now)
export DATABOX_ARCH="-"${ARCH}
export DATABOX_DEV="1"
;;
* )
ARCH=""
NODE_IMAGE="node:alpine"
export DATABOX_ARCH=""
;;
esac
DOCKER_REPO=""
DATABOX_VERSION=$(<./Version)
DATABOX_CORE_IMAGE_VERSION=$(<./Version)
# use images from https://hub.docker.com/r/databoxsystems/
DOCKER_REPO="databoxsystems/"
if [ "$DEV" == "1" ]
then
DOCKER_REPO=""
DATABOX_CORE_IMAGE_VERSION="latest"
fi
err "Starting version ${DATABOX_VERSION}"
export DOCKER_REPO=${DOCKER_REPO}
export DATABOX_VERSION=${DATABOX_VERSION}
export DATABOX_CORE_IMAGE_VERSION=${DATABOX_CORE_IMAGE_VERSION}
function _exec {
docker run \
--net=host -ti --rm -v "$(pwd -P)":/cwd -w /cwd \
${DARGS} ${NODE_IMAGE} "$@"
}
if [ ! -d "node_modules" ]; then
_exec npm install -loglevel silent
fi
mkdir -p ./certs
err "Creating Certificates"
_exec node ./src/createCerts.js ${ips[@]}
if [ "$DEV" == "1" ]
then
# build all images locally in dev mode
err "Building Databox localy in dev mode"
./databox-fetch-components
source ./databox-build-core
assert_or_die $? 0 "Problem building core images"
fi
err "Starting the Databox swarm"
docker swarm init --advertise-addr ${EXT_IP} > /dev/null
err "Starting Databox"
docker network create -d overlay --attachable databox-system-net
docker-compose -f ./docker-core-network.yaml up -d
_exec node ./src/createResolvConf.js "$(docker inspect $(docker ps -q --filter="name=databox-network"))"
docker-compose -f ./docker-databox-appstore.yaml up -d
docker stack deploy -c docker-compose.yaml databox
assert_or_die $? 0 "Problem with docker stack deploy"
if [ "$DEV" == "1" ]
then
err "Sleeping..."
sleep 10
./databox-install-component driver-sensingkit &
./databox-install-component driver-os-monitor &
./databox-install-component app-os-monitor &
wait
fi
err "Databox started! Visit http://localhost:8448"
if [ -z "$DATABOX_TESTING" ]
then
docker service logs databox_container-manager -f
fi