-
Notifications
You must be signed in to change notification settings - Fork 296
/
setup-ic-boundary.sh
93 lines (74 loc) · 2.22 KB
/
setup-ic-boundary.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
#!/bin/bash
set -euox pipefail
source '/opt/ic/bin/helpers.shlib'
readonly SERVICE_NAME='ic-boundary'
readonly IC_BOUNDARY_CONFIG="${BOOT_DIR}/ic_boundary.conf"
readonly NNS_CONFIG="${BOOT_DIR}/nns.conf"
readonly NNS_PEM="${BOOT_DIR}/nns_public_key.pem"
readonly CFG_DIR='/run/ic-node/etc/ic-boundary'
readonly RUN_DIR='/run/ic-node/etc/default'
readonly ENV_FILE="${RUN_DIR}/${SERVICE_NAME}"
function read_variables() {
if [[ ! -d "${BOOT_DIR}" ]]; then
err "missing node configuration directory: ${BOOT_DIR}"
exit 1
fi
if [ ! -f "${NNS_CONFIG}" ]; then
err "missing nns configuration: ${NNS_CONFIG}"
exit 1
fi
if [ ! -f "${NNS_PEM}" ]; then
err "missing nns public key: ${NNS_PEM}"
exit 1
fi
while IFS="=" read -r key value; do
case "${key}" in
"nns_url") NNS_URL="${value}" ;;
esac
done <"${NNS_CONFIG}"
if [[ -z "${NNS_URL:-}" ]]; then
err "missing NNS configuration value(s): $(cat "${NNS_CONFIG}")"
exit 1
fi
if [ -f "${IC_BOUNDARY_CONFIG}" ]; then
while IFS="=" read -r key value; do
case "${key}" in
"max_concurrency") MAX_CONCURRENCY+=("${value}") ;;
"shed_ewma_param") SHED_EWMA_PARAM+=("${value}") ;;
esac
done <"${IC_BOUNDARY_CONFIG}"
fi
}
function generate_config() {
mkdir -p "${RUN_DIR}"
# Copy NNS Public Key
cp -a "${NNS_PEM}" "${RUN_DIR}/"
# Generate Configuration
cat >"${ENV_FILE}" <<EOF
NNS_URL=${NNS_URL}
CACHE_SIZE=1073741824
CACHE_ITEM_MAX_SIZE=10485760
CACHE_TTL=1
MAX_CONCURRENCY=${MAX_CONCURRENCY:-}
SHED_EWMA_PARAM=${SHED_EWMA_PARAM:-}
EOF
}
function setup_geolite2_dbs() {
local -r BOOT_DBS="${BOOT_DIR}/geolite2_dbs"
local -r EMPTY_DBS='/etc/geoip'
if [[ ! -d "${BOOT_DBS}" ]]; then
err "missing geolite2 dbs dir '${BOOT_DBS}', defaulting to empty dbs '${EMPTY_DBS}'"
local -r DBS_SRC="${EMPTY_DBS}"
else
local -r DBS_SRC="${BOOT_DBS}"
fi
mkdir -p "${CFG_DIR}"
cp "${DBS_SRC}/GeoLite2-Country.mmdb" "${CFG_DIR}"
}
function main() {
read_variables
generate_config
setup_geolite2_dbs
mkdir -p /var/opt/registry/store
}
main "$@"