forked from stellar-deprecated/docker-stellar-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart
executable file
·130 lines (110 loc) · 3.11 KB
/
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
#!/usr/bin/env bash
set -e
export SELF="$1"
if [[ -z "${SELF}" ]]; then
echo "Usage: $0 <node> [commands...]" >&2
exit 1
fi
shift
export CONTAINER_ID=$(grep cpu: /proc/self/cgroup | awk -F/ '{ print $3 }')
confd -onetime -backend=env
source /etc/profile
if [[ -f "/stellar-core-override.cfg" ]]; then
CONFIG_OPTION="--conf /stellar-core-override.cfg"
fi
if [[ "$1" == "nopsql" ]]; then
NOPSQL=true
shift
else
while ! psql -c 'select 1' >/dev/null 2>&1; do
echo "Waiting for postgres to be available..."
sleep 1
done
fi
function newdb() {
rm -rf /data/*
if [[ -z "${NOPSQL}" ]]; then
dropdb stellar || true
createdb stellar
if [[ -n "${HORIZON_PASSWORD}" ]]; then
dropuser horizon || true
createuser horizon
psql -c "alter user horizon with password '${HORIZON_PASSWORD}'"
psql >/dev/null <<-SQL
GRANT CONNECT ON DATABASE stellar to horizon;
\c stellar
REVOKE ALL ON schema public FROM public;
GRANT ALL ON schema public TO postgres;
GRANT USAGE ON SCHEMA public to horizon;
GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO horizon;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO horizon;
ALTER DEFAULT PRIVILEGES FOR USER postgres IN SCHEMA public GRANT SELECT ON SEQUENCES TO horizon;
ALTER DEFAULT PRIVILEGES FOR USER postgres IN SCHEMA public GRANT SELECT ON TABLES TO horizon;
SQL
fi
fi
stellar-core $CONFIG_OPTION --newdb
}
while [[ -n "$1" ]]; do
COMMAND="$1"
shift
case "${COMMAND}" in
newdb)
newdb
;;
fresh)
newdb
[[ -n "${HISTORY_RESET}" ]] && $(printf "${HISTORY_RESET}" "${SELF}") || true
[[ -n "${HISTORY_PUT}" ]] && stellar-core $CONFIG_OPTION --newhist "${SELF}"
;;
newhist)
[[ -n "${HISTORY_RESET}" ]] && $(printf "${HISTORY_RESET}" "${SELF}") || true
[[ -n "${HISTORY_PUT}" ]] && stellar-core $CONFIG_OPTION --newhist "${SELF}"
;;
forcescp)
stellar-core $CONFIG_OPTION --forcescp
;;
catchupcomplete)
stellar-core $CONFIG_OPTION --catchup-complete
;;
catchuprange)
FROM=$1
shift
TO=$1
shift
if [ "${FROM}" -eq "${FROM}" -a "${TO}" -eq "${TO}" ]; then
OUTPUT=$1
if [[ "${OUTPUT}" ]]; then
stellar-core $CONFIG_OPTION --catchup-at $FROM --catchup-to $TO --output-file "${OUTPUT}"
shift
else
stellar-core $CONFIG_OPTION --catchup-at $FROM --catchup-to $TO
fi
else
echo "Valid ledger range required" >&2
exit 1
fi
;;
lasthistorycheckpoint)
OUTPUT=$1
if [[ "${OUTPUT}" ]]; then
stellar-core $CONFIG_OPTION --report-last-history-checkpoint --output-file "${OUTPUT}"
shift
else
stellar-core $CONFIG_OPTION --report-last-history-checkpoint
fi
SKIP_START=true
;;
skipstart)
SKIP_START=true
;;
*)
echo "Unknown container command $COMMAND" >&2
exit 1
esac
done
if [[ -z "${SKIP_START}" ]]; then
exec /init -- stellar-core $CONFIG_OPTION
else
echo "Setup complete. Skipping server start."
fi