/
entry.sh
69 lines (58 loc) · 1.46 KB
/
entry.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
#!/bin/bash
PATH="${PATH:-/bin}:/usr/bin"
export PATH
set -euo pipefail
IFS=$'\n\t'
network="$(cat /etc/nano-network)"
case "${network}" in
live|'')
network='live'
dirSuffix=''
;;
beta)
dirSuffix='Beta'
;;
test)
dirSuffix='Test'
;;
esac
nanodir="${HOME}/RaiBlocks${dirSuffix}"
dbFile="${nanodir}/data.ldb"
mkdir -p "${nanodir}"
if [ ! -f "${nanodir}/config.json" ]; then
echo "Config File not found, adding default."
cp "/usr/share/raiblocks/config/${network}.json" "${nanodir}/config.json"
fi
# Start watching the log file we are going to log output to
logfile="${nanodir}/nano-docker-output.log"
tail -F "${logfile}" &
pid=''
firstTimeComplete=''
while true; do
if [ -n "${firstTimeComplete}" ]; then
sleep 10
fi
firstTimeComplete='true'
if [ -f "${dbFile}" ]; then
dbFileSize="$(stat -c %s "${dbFile}" 2>/dev/null)"
if [ "${dbFileSize}" -gt $[1024 * 1024 * 1024 * 20] ]; then
echo "ERROR: Database size grew above 20GB (size = ${dbFileSize})" >&2
while [ -n "${pid}" ]; do
kill "${pid}" >/dev/null 2>/dev/null || :
if ! kill -0 "${pid}" >/dev/null 2>/dev/null; then
pid=''
fi
done
rai_node --vacuum
fi
fi
if [ -n "${pid}" ]; then
if ! kill -0 "${pid}" >/dev/null 2>/dev/null; then
pid=''
fi
fi
if [ -z "${pid}" ]; then
rai_node --daemon &
pid="$!"
fi
done > "${logfile}" 2>&1