Skip to content

Commit

Permalink
Merge pull request #10242 from MinaProtocol/lk86/improve-docker-entry…
Browse files Browse the repository at this point in the history
…point

lk86/improve-docker-entrypoint
  • Loading branch information
lk86 authored Feb 15, 2022
2 parents 60fabf0 + c03a8fc commit e6db28e
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions dockerfiles/scripts/daemon-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ set -euo pipefail
# If glob doesn't match anything, return empty string rather than literal pattern
shopt -s nullglob


set -x

INPUT_ARGS="$@"

# These arrays can be overwritten or extended in scripts to adjust verbosity
# Example: LOG_FILES+=("${VERBOSE_LOG_FILES[@]}")
# Example:
declare -a LOG_FILES=('mina.log')
declare -a VERBOSE_LOG_FILES=('.mina-config/mina-prover.log' '.mina-config/mina-verifier.log' '.mina-config/mina-best-tip.log')
# stderr is mostly used to print "reading password from environment varible ..."
# prover and verifier logs are also sparse, mostly memory stats and debug info
# mina-best-tip.log is useful for organizing a hard fork and is one way to monitor new blocks as they are added, but not critical
declare -a VERBOSE_LOG_FILES=('mina-stderr.log' '.mina-config/mina-prover.log' '.mina-config/mina-verifier.log' '.mina-config/mina-best-tip.log')

# Attempt to execute or source custom entrypoint scripts accordingly
# Example: mount a mina-env file with variable evironment variables to source and pass to the daemon
for script in /entrypoint.d/*; do
if [ -x "$script" ]; then
"$script" $INPUT_ARGS
Expand All @@ -24,16 +25,34 @@ for script in /entrypoint.d/*; do
fi
done

# Support flags from .mina-env on debian
if [[ ${PEER_LIST_URL} ]]; then
EXTRA_FLAGS+=" --peer-list-url ${PEER_LIST_URL}"
fi
if [[ ${LOG_LEVEL} ]]; then
EXTRA_FLAGS+=" --log-level ${LOG_LEVEL}"
fi
if [[ ${FILE_LOG_LEVEL} ]]; then
EXTRA_FLAGS+=" --file-log-level ${FILE_LOG_LEVEL}"
fi

# If VERBOSE=true then also append other log files
if [[ ${VERBOSE} ]]; then
LOG_FILES+=("${VERBOSE_LOG_FILES[@]}")
# Print the flags to the daemon for debugging use
echo "[Debug] Input Args: ${INPUT_ARGS}"
echo "[Debug] Extra Flags: ${EXTRA_FLAGS}"
fi

# Mina daemon initialization
mkdir -p .mina-config
touch .mina-config/mina-prover.log
touch .mina-config/mina-verifier.log
touch .mina-config/mina-best-tip.log
# Create all of the log files that we will tail later
touch "${LOG_FILES[@]}"

set +ex # Allow wait and kill commands to fail in this loop, don't print these commands
set +e # Allow wait and kill commands to fail in this loop
while true; do
rm -f .mina-config/.mina-lock
mina $INPUT_ARGS 2>&1 >mina.log &
mina $INPUT_ARGS $EXTRA_FLAGS 2>mina-stderr.log 1>mina.log &
mina_pid=$!

tail -q -f "${LOG_FILES[@]}" &
Expand Down

0 comments on commit e6db28e

Please sign in to comment.