Automatically vacuum database if it gets too large in the Docker container (#792)

This commit is contained in:
Roy Keene 2018-04-10 22:59:28 -05:00 committed by Lee Bousfield
commit 74943c7d6e

View file

@ -1,5 +1,8 @@
#!/bin/bash
PATH="${PATH:-/bin}:/usr/bin"
export PATH
set -euo pipefail
IFS=$'\n\t'
@ -18,10 +21,45 @@ case "${network}" in
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
/usr/bin/rai_node --daemon
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