-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathrestartWithCleanup.sh
More file actions
executable file
·94 lines (75 loc) · 1.88 KB
/
restartWithCleanup.sh
File metadata and controls
executable file
·94 lines (75 loc) · 1.88 KB
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
#!/bin/bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
usage() {
cat <<'USAGE'
Usage: ./restartWithCleanup.sh [ROLE]
ROLE matches the options from blockdag.sh (miner, full, relay).
If omitted, the miner template is used. NODE_ROLE environment variable can also
set the default role.
USAGE
}
resolve_compose_file() {
local role_input="$1"
case "$role_input" in
full)
echo "docker-compose.full.yml"
;;
relay)
echo "docker-compose.relay.yml"
;;
miner|default)
echo "docker-compose.yml"
;;
*)
return 1
;;
esac
}
ROLE_INPUT=${1:-${NODE_ROLE:-miner}}
case "$ROLE_INPUT" in
-h|--help)
usage
exit 0
;;
esac
if ! COMPOSE_FILE=$(resolve_compose_file "$ROLE_INPUT"); then
echo "Unknown node role: $ROLE_INPUT" >&2
usage >&2
exit 1
fi
if [[ "$COMPOSE_FILE" = /* ]]; then
compose_path="$COMPOSE_FILE"
else
compose_path="$SCRIPT_DIR/$COMPOSE_FILE"
fi
ENV_FILE="$SCRIPT_DIR/.env"
if [ -f "$ENV_FILE" ]; then
# shellcheck disable=SC1090
source "$ENV_FILE"
fi
if [ -z "${PUB_ETH_ADDR:-}" ]; then
if [ -f "$SCRIPT_DIR/wallet.txt" ]; then
PUB_ETH_ADDR=$(tail -n 1 "$SCRIPT_DIR/wallet.txt")
else
echo "PUB_ETH_ADDR not set. Please populate $ENV_FILE or wallet.txt" >&2
exit 1
fi
fi
if docker compose version >/dev/null 2>&1; then
compose_cmd=(docker compose)
elif docker-compose version >/dev/null 2>&1; then
compose_cmd=(docker-compose)
else
echo "Neither 'docker compose' nor 'docker-compose' command is available." >&2
exit 1
fi
"${compose_cmd[@]}" -f "$compose_path" down || true
image_name=$(awk '/^\s*image:/ {print $2; exit}' "$compose_path")
if [ -n "$image_name" ]; then
docker image rm "$image_name" || true
fi
sudo rm -rf ./bin/bdag/*
# restart the blockdag node
"$SCRIPT_DIR"/node.sh "$PUB_ETH_ADDR" "$COMPOSE_FILE"