forked from stellar-deprecated/docker-stellar-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start
executable file
·163 lines (143 loc) · 3.89 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
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
#!/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 new-db
}
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 new-hist "${SELF}"
;;
newhist)
[[ -n "${HISTORY_RESET}" ]] && $(printf "${HISTORY_RESET}" "${SELF}") || true
[[ -n "${HISTORY_PUT}" ]] && stellar-core $CONFIG_OPTION new-hist "${SELF}"
;;
forcescp)
stellar-core $CONFIG_OPTION force-scp
;;
catchupcomplete)
stellar-core $CONFIG_OPTION catchup current/max
;;
catchuprange)
FROM=$1
shift
TO=$1
shift
if [ "${FROM}" -eq "${FROM}" -a "${TO}" -eq "${TO}" ]; then
OUTPUT=$1
COUNT=$((TO-FROM+1))
if [[ "${OUTPUT}" ]]; then
stellar-core $CONFIG_OPTION catchup $TO/$COUNT --output-file "${OUTPUT}"
shift
else
stellar-core $CONFIG_OPTION catchup $TO/$COUNT
fi
else
echo "Valid ledger range required" >&2
exit 1
fi
;;
catchupat)
AT=$1
shift
if [[ "${AT}" == "current" || "${AT}" -eq "${AT}" ]]; then
OUTPUT=$1
if [[ "${OUTPUT}" ]]; then
stellar-core $CONFIG_OPTION catchup $AT/0 --output-file "${OUTPUT}"
shift
else
stellar-core $CONFIG_OPTION catchup $AT/0
fi
else
echo "Valid ledger required" >&2
exit 1
fi
;;
catchupto)
TO=$1
shift
if [[ "${TO}" == "current" || "${TO}" -eq "${TO}" ]]; then
OUTPUT=$1
if [[ "${OUTPUT}" ]]; then
stellar-core $CONFIG_OPTION catchup $TO/max --output-file "${OUTPUT}"
shift
else
stellar-core $CONFIG_OPTION catchup $TO/max
fi
else
echo "Valid ledger 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 run
else
echo "Setup complete. Skipping server start."
fi