-
Notifications
You must be signed in to change notification settings - Fork 189
/
Copy pathdeploy.sh
executable file
·287 lines (255 loc) · 9.09 KB
/
deploy.sh
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
#!/bin/bash
############################################
#
# Usage: deploy.sh
#
# To deploy AIStore as a next tier cluster to the *already running*
# AIStore cluster set DEPLOY_AS_NEXT_TIER=1.
#
# NOTE: system environment variables are listed in the `env` package.
# See https://github.com/NVIDIA/aistore/blob/main/api/env/README.md
#
# NOTE: by default, configuration files are stored under $HOME/.config/ais/<app-name>
# E.g., $HOME/.config/ais/authn - AuthN config, $HOME/.config/ais/cli - CLI config
# and so on. This rule holds for all AIS "applications" except `aisnode` itself.
# See https://github.com/NVIDIA/aistore/tree/main/cmn/fname for the most updated locations.
#
# NOTE: Prometheus is the Local Playground's default; use TAGS to specify `statsd` and/or
# any other non-default build tag.
#
############################################
if ! command -v go &> /dev/null; then
echo "Go (toolchain) is not installed"
echo "Use https://go.dev/dl to install the required (as per go.mod) version of Go"
echo "See https://aiatscale.org/docs/getting-started for step-by-step instruction"
exit 1
fi
if [[ -z $GOPATH ]]; then
echo "Warning: GOPATH variable is not defined, using home directory ${HOME}"
echo "(Tip: see https://aiatscale.org/docs/getting-started for step-by-step instruction)"
echo ""
if [ ! -d "${HOME}/go/pkg" ]; then
echo "${HOME}/go/pkg does not exist (deploying the very first time and from scratch?)"
echo "(Tip: run 'make mod-tidy' to download required packages)"
mkdir -p "${HOME}/go/pkg"
echo ""
fi
if [ ! -w "${HOME}/go/pkg" ]; then
echo "${HOME}/go/pkg is not writable - exiting"
exit 1
fi
else
if [ ! -d "${GOPATH}/pkg" ]; then
echo "${GOPATH}/pkg does not exist (deploying the very first time and from scratch?)"
echo "(Tip: run 'make mod-tidy' to download required packages)"
mkdir -p "${GOPATH}/pkg"
echo ""
fi
if [ ! -w "${GOPATH}/pkg" ]; then
echo "${GOPATH}/pkg is not writable - exiting"
exit 1
fi
fi
## NOTE: absolute path to aistore root
## (should we use `git rev-parse --show-toplevel` instead?)
AISTORE_PATH=$(cd "$(dirname "$0")/../../../"; pwd -P)
source $AISTORE_PATH/deploy/dev/utils.sh
AIS_USE_HTTPS=${AIS_USE_HTTPS:-false}
AIS_HTTP_CHUNKED_TRANSFER=true
HTTP_WRITE_BUFFER_SIZE=65536
HTTP_READ_BUFFER_SIZE=65536
if [[ -z $DEPLOY_AS_NEXT_TIER ]]; then
PORT=${PORT:-8080}
PORT_INTRA_CONTROL=${PORT_INTRA_CONTROL:-9080}
PORT_INTRA_DATA=${PORT_INTRA_DATA:-10080}
NEXT_TIER=
else
PORT=${PORT:-11080}
PORT_INTRA_CONTROL=${PORT_INTRA_CONTROL:-12080}
PORT_INTRA_DATA=${PORT_INTRA_DATA:-13080}
NEXT_TIER="_next"
fi
PRIMARY_HOST=${AIS_PRIMARY_HOST:-localhost}
AIS_PRIMARY_URL="http://$PRIMARY_HOST:$PORT"
if $AIS_USE_HTTPS; then
AIS_PRIMARY_URL="https://$PRIMARY_HOST:$PORT"
fi
LOG_ROOT="${LOG_ROOT:-/tmp/ais}${NEXT_TIER}"
#### Authentication setup #########
AIS_AUTHN_SECRET_KEY="${AIS_AUTHN_SECRET_KEY:-aBitLongSecretKey}"
AIS_AUTHN_ENABLED="${AIS_AUTHN_ENABLED:-false}"
AIS_AUTHN_SU_NAME="${AIS_AUTHN_SU_NAME:-admin}"
AIS_AUTHN_SU_PASS="${AIS_AUTHN_SU_PASS:-admin}"
###################################
#
# fspaths config is used if and only if test_fspaths.count == 0
# existence of each fspath is checked at runtime
#
###################################
# NOTE:
# for system-wide conventions on locations of these and other configs,
# see: `cmn/fname`
AIS_CONF_DIR="$HOME/.ais$NEXT_TIER"
APP_CONF_DIR="$HOME/.config/ais"
mkdir -p $AIS_CONF_DIR
mkdir -p $APP_CONF_DIR
COLLECTD_CONF_FILE="${APP_CONF_DIR}/collectd.conf"
STATSD_CONF_FILE="${APP_CONF_DIR}/statsd.conf"
if lsof -Pi :$PORT -sTCP:LISTEN -t >/dev/null; then
exit_error "TCP port $PORT is not open (check if AIStore is already running)"
fi
TMPF=$(mktemp /tmp/ais$NEXT_TIER.XXXXXXXXX)
touch $TMPF
OS=$(uname -s)
case $OS in
Linux) # Linux
if ! [ -x "$(command -v setfattr)" ]; then
echo "Warning: setfattr not installed" >&2
elif ! setfattr -n user.comment -v comment $TMPF; then
echo "Warning: bad kernel configuration: extended attributes are not enabled."
fi
;;
Darwin) # macOS
if ! xattr -w user.comment comment $TMPF; then
echo "Warning: bad macOS configuration: extended attributes are not enabled."
fi
echo "Warning: Darwin architecture is not yet fully supported. You may stumble upon bugs and issues when testing on Mac."
;;
*)
rm $TMPF 2>/dev/null
echo "Error: '${OS}' is not supported."
exit 1
;;
esac
rm $TMPF 2>/dev/null
### begin reading STDIN =================== 5 steps below ========================================
# 1. read target count
echo "Enter number of storage targets:"
read -r TARGET_CNT
is_number ${TARGET_CNT}
# 2. read proxy count
echo "Enter number of proxies (gateways):"
read -r PROXY_CNT
is_number ${PROXY_CNT}
if [[ ${PROXY_CNT} -lt 1 && -z "${AIS_PRIMARY_HOST}" ]] ; then
exit_error "Number of proxies must be at least 1 if no external primary proxy is specified with AIS_PRIMARY_HOST. Received "${PROXY_CNT}""
fi
if [[ ${PROXY_CNT} -gt 1 ]] ; then
AIS_DISCOVERY_PORT=$((PORT + 1))
AIS_DISCOVERY_URL="http://$PRIMARY_HOST:$AIS_DISCOVERY_PORT"
if $AIS_USE_HTTPS; then
AIS_DISCOVERY_URL="https://$PRIMARY_HOST:$AIS_DISCOVERY_PORT"
fi
fi
START=0
END=$((TARGET_CNT + PROXY_CNT - 1))
# 3. read mountpath count (and notice the default)
if [[ ! -n "${TEST_FSPATH_COUNT+x}" ]]; then
echo "Number of local mountpaths (enter 0 for preconfigured filesystems):"
TEST_FSPATH_COUNT=$(read_fspath_count)
fi
## default = 4
if [[ -z $TEST_FSPATH_COUNT ]]; then
TEST_FSPATH_COUNT=4
fi
# 4. conditionally linked backends
set_env_backends
# 5. /dev/loop* devices, if any
# see also: TEST_LOOPBACK_SIZE
TEST_LOOPBACK_COUNT=0
create_loopbacks_or_skip
# 6. conditionally enable distributed tracing
set_env_tracing_or_skip
### end reading STDIN ============================ 5 steps above =================================
## NOTE: to enable StatsD instead of Prometheus, use build tag `statsd` in the make command, as follows:
## TAGS=statsd make ...
## see docs/metrics.md and docs/prometheus.md for more information.
##
if ! TAGS=${TAGS} AIS_BACKEND_PROVIDERS=${AIS_BACKEND_PROVIDERS} make --no-print-directory -C ${AISTORE_PATH} node; then
exit_error "failed to compile 'aisnode' binary"
fi
# Not really used for local testing but to keep aisnode_config.sh quiet
GRAPHITE_PORT=2003
GRAPHITE_SERVER="127.0.0.1"
#
# generate conf file(s) based on the settings/selections above
#
if [ "${!#}" != "--dont-generate-configs" ]; then
for (( c=START; c<=END; c++ )); do
AIS_CONF_DIR="$HOME/.ais$NEXT_TIER$c"
INSTANCE=$c
mkdir -p "$AIS_CONF_DIR"
AIS_CONF_FILE="$AIS_CONF_DIR/ais.json"
AIS_LOCAL_CONF_FILE="$AIS_CONF_DIR/ais_local.json"
AIS_LOG_DIR="$LOG_ROOT/$c/log"
source "${AISTORE_PATH}/deploy/dev/local/aisnode_config.sh"
((PORT++))
((PORT_INTRA_CONTROL++))
((PORT_INTRA_DATA++))
done
fi
# run all daemons
CMD="${GOPATH}/bin/aisnode"
listening_on="Proxies are listening on ports: "
if [ $PROXY_CNT -eq 1 ]; then
listening_on="Proxy is listening on port: "
fi
loopback=""
if [[ "$TEST_LOOPBACK_COUNT" != "0" ]] ; then
loopback="-loopback"
fi
for (( c=START; c<=END; c++ )); do
AIS_CONF_DIR="$HOME/.ais${NEXT_TIER}$c"
AIS_CONF_FILE="$AIS_CONF_DIR/ais.json"
AIS_LOCAL_CONF_FILE="$AIS_CONF_DIR/ais_local.json"
PROXY_PARAM="${AIS_NODE_FLAGS} -config=${AIS_CONF_FILE} -local_config=${AIS_LOCAL_CONF_FILE} -role=proxy -ntargets=${TARGET_CNT} ${RUN_ARGS}"
TARGET_PARAM="${AIS_NODE_FLAGS} -config=${AIS_CONF_FILE} -local_config=${AIS_LOCAL_CONF_FILE} -role=target ${RUN_ARGS} $loopback"
pub_port=$(grep "\"port\":" ${AIS_LOCAL_CONF_FILE} | awk '{ print $2 }')
pub_port=${pub_port:1:$((${#pub_port} - 3))}
if [[ $c -eq 0 && $PROXY_CNT -gt 0 ]]; then
run_cmd "${CMD} ${PROXY_PARAM}"
listening_on+=${pub_port}
# Wait for the proxy to start up
sleep 2
elif [[ $c -lt ${PROXY_CNT} ]]; then
run_cmd "${CMD} ${PROXY_PARAM}"
listening_on+=", ${pub_port}"
else
run_cmd "${CMD} ${TARGET_PARAM}"
fi
done
if [[ $AIS_AUTH_ENABLED == "true" ]]; then
exit_error "env var 'AIS_AUTH_ENABLED' is deprecated (use 'AIS_AUTHN_ENABLED')"
exit 1
fi
if [[ $AIS_AUTHN_ENABLED == "true" ]]; then
# conf file for authn
AIS_AUTHN_CONF_DIR="${APP_CONF_DIR}/authn"
mkdir -p "$AIS_AUTHN_CONF_DIR"
AIS_AUTHN_LOG_DIR="$LOG_ROOT/authn/log"
source "${AISTORE_PATH}/deploy/dev/local/authn_config.sh"
if ! make --no-print-directory -C ${AISTORE_PATH} authn; then
exit_error "failed to compile 'authn' binary"
fi
run_cmd "${GOPATH}/bin/authn -config=${AIS_AUTHN_CONF_DIR}"
fi
if [[ $MODE == "debug" ]]; then
sleep 1.5
else
sleep 0.1
fi
##
## TODO: could be in fact HTTPS, not HTTP. Difficult to find out without introducing delay and checking the logs.
##
if command -v pgrep &> /dev/null; then
run_count=$(pgrep -a aisnode | grep -c "${NEXT_TIER}")
if [[ "${run_count}" -eq $((TARGET_CNT + PROXY_CNT)) ]]; then
echo "${listening_on}"
if [[ -z $DEPLOY_AS_NEXT_TIER ]]; then
echo "Primary endpoint: ${AIS_PRIMARY_URL}"
fi
fi
else
echo "Warning: pgrep not found"
echo "${listening_on}"
fi