Skip to content

Commit

Permalink
Automatically vacuum database if it gets too large in the Docker cont…
Browse files Browse the repository at this point in the history
…ainer (#792)
  • Loading branch information
rkeene authored and PlasmaPower committed Apr 11, 2018
1 parent 603599f commit 74943c7
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion docker/node/entry.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/bash

PATH="${PATH:-/bin}:/usr/bin"
export PATH

set -euo pipefail
IFS=$'\n\t'

Expand All @@ -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

0 comments on commit 74943c7

Please sign in to comment.