-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwait-for-stack.sh
executable file
·93 lines (80 loc) · 2.61 KB
/
wait-for-stack.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
SCRIPT_DIR="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 || exit 1; pwd -P )"
SRC_DIR="$SCRIPT_DIR/.."
COMPOSE_PROFILES="${COMPOSE_PROFILES:-}"
COMPOSE_PROJECT_NAME="${COMPOSE_PROJECT_NAME:-}"
COMPOSE_ENV_FILES="${COMPOSE_ENV_FILES:-}"
WAIT_FOR_SYNC="${WAIT_FOR_SYNC:-""}"
print_help () {
cat <<EOF
Usage: $0 OPTION[=VALUE]...
Script for waiting for API stack to be ready
OPTIONS:
--profiles=P1,P2,P3 Profile(s) to use, must be the same as when the stack was started
--project-name=NAME Name of the Compose project, must be the same as when the stack was started
(default: defined at the top of stack/compose.yml)
--env-files=1.env,2.env Specify a file to use to start the stack, uses ${SRC_DIR}/stack/.env
when empty, must be the same as when the stack was started (default: empty)
--wait-for-sync=<Number of blocks> Wait for HAF replay and Hivemind sync or just for stack startup (default: empty)
--help,-h,-? Display this help screen and exit
Available profiles:
- denser - starts auth, blog and wallet services in addition to the API stack
EOF
}
set -e
while [ $# -gt 0 ]; do
case "$1" in
--profiles=*)
arg="${1#*=}"
COMPOSE_PROFILES="$arg"
;;
--project-name=*)
arg="${1#*=}"
COMPOSE_PROJECT_NAME="$arg"
;;
--env-files=*)
arg="${1#*=}"
COMPOSE_ENV_FILES="$arg"
;;
--wait-for-sync=*)
arg="${1#*=}"
WAIT_FOR_SYNC="$arg"
;;
--help|-h|-\?)
print_help
exit 0
;;
*)
echo "ERROR: '$1' is not a valid option/positional argument"
echo
print_help
exit 2
;;
esac
shift
done
pushd "$SRC_DIR"
export COMPOSE_PROFILES
export COMPOSE_PROJECT_NAME
export COMPOSE_ENV_FILES
if [[ -n "$WAIT_FOR_SYNC" ]]
then
until ./scripts/get-stack-logs.sh --service=haf --since=2m | grep "Stopped blockchain replaying on user request."
do
echo "Waiting for HAF replay to finish..."
sleep 60
done
until ./scripts/get-stack-logs.sh --service=hivemind-block-processing --since=2m | grep "Last imported block is: $WAIT_FOR_SYNC"
do
echo "Waiting for Hivemind sync to finish..."
sleep 60
done
else
until ./scripts/get-stack-logs.sh --service=haf --since=2m | grep "Broadcasting block"
do
echo "Waiting for HAF to start producing blocks"
sleep 60
done
fi
echo "HAF API stack is ready!"
popd