Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Apr 11, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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