2023-06-07 22:44:30 -07:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2023-06-27 19:36:07 -07:00
|
|
|
# Show the commands we are executing
|
2023-06-07 22:44:30 -07:00
|
|
|
set -x
|
2023-06-27 19:36:07 -07:00
|
|
|
# Exit if a command fails
|
2023-06-07 22:44:30 -07:00
|
|
|
set -e
|
2023-06-27 19:36:07 -07:00
|
|
|
# Exit if any command in a pipeline fails
|
2023-06-07 22:44:30 -07:00
|
|
|
set -o pipefail
|
|
|
|
|
2023-06-27 19:36:07 -07:00
|
|
|
# Set this to change the default cached state directory
|
|
|
|
# Path and name of the config file
|
|
|
|
: "${ZEBRA_CONF_DIR:=/etc/zebrad}"
|
|
|
|
: "${ZEBRA_CONF_FILE:=zebrad.toml}"
|
|
|
|
if [[ -n "$ZEBRA_CONF_DIR" ]] && [[ -n "$ZEBRA_CONF_FILE" ]]; then
|
|
|
|
ZEBRA_CONF_PATH="$ZEBRA_CONF_DIR/$ZEBRA_CONF_FILE"
|
|
|
|
fi
|
2023-06-07 22:44:30 -07:00
|
|
|
|
2023-06-27 19:36:07 -07:00
|
|
|
# [network]
|
|
|
|
: "${NETWORK:=Mainnet}"
|
|
|
|
: "${ZEBRA_LISTEN_ADDR:=0.0.0.0}"
|
|
|
|
# [consensus]
|
|
|
|
: "${ZEBRA_CHECKPOINT_SYNC:=true}"
|
|
|
|
# [state]
|
|
|
|
: "${ZEBRA_CACHED_STATE_DIR:=/var/cache/zebrad-cache}"
|
|
|
|
# [metrics]
|
|
|
|
: "${METRICS_ENDPOINT_ADDR:=0.0.0.0}"
|
|
|
|
: "${METRICS_ENDPOINT_PORT:=9999}"
|
|
|
|
# [tracing]
|
|
|
|
: "${LOG_COLOR:=false}"
|
|
|
|
: "${TRACING_ENDPOINT_ADDR:=0.0.0.0}"
|
|
|
|
: "${TRACING_ENDPOINT_PORT:=3000}"
|
|
|
|
# [rpc]
|
|
|
|
: "${RPC_LISTEN_ADDR:=0.0.0.0}"
|
2023-07-06 16:23:47 -07:00
|
|
|
if [[ "${NETWORK}" = "Mainnet" ]]; then
|
|
|
|
: "${RPC_PORT:=8232}"
|
|
|
|
elif [[ "${NETWORK}" = "Testnet" ]]; then
|
|
|
|
: "${RPC_PORT:=18232}"
|
|
|
|
fi
|
2023-06-07 22:44:30 -07:00
|
|
|
|
|
|
|
|
|
|
|
# Populate `zebrad.toml` before starting zebrad, using the environmental
|
2023-06-27 19:36:07 -07:00
|
|
|
# variables set by the Dockerfile or the user. If the user has already created a config, don't replace it.
|
2023-06-07 22:44:30 -07:00
|
|
|
#
|
|
|
|
# We disable most ports by default, so the default config is secure.
|
|
|
|
# Users have to opt-in to additional functionality by setting environmental variables.
|
2023-06-27 19:36:07 -07:00
|
|
|
if [[ -n "$ZEBRA_CONF_PATH" ]] && [[ ! -f "$ZEBRA_CONF_PATH" ]]; then
|
|
|
|
|
|
|
|
# Create the conf path and file
|
|
|
|
mkdir -p "$ZEBRA_CONF_DIR"
|
|
|
|
touch "$ZEBRA_CONF_PATH"
|
|
|
|
|
|
|
|
# Populate the conf file
|
2023-06-07 22:44:30 -07:00
|
|
|
cat <<EOF > "$ZEBRA_CONF_PATH"
|
|
|
|
[network]
|
|
|
|
network = "$NETWORK"
|
2023-06-27 19:36:07 -07:00
|
|
|
listen_addr = "$ZEBRA_LISTEN_ADDR"
|
2023-06-07 22:44:30 -07:00
|
|
|
[state]
|
2023-06-09 12:16:39 -07:00
|
|
|
cache_dir = "$ZEBRA_CACHED_STATE_DIR"
|
2023-06-27 19:36:07 -07:00
|
|
|
EOF
|
2023-06-07 22:44:30 -07:00
|
|
|
|
2023-06-27 19:36:07 -07:00
|
|
|
if [[ " $FEATURES " =~ " prometheus " ]]; then # spaces are important here to avoid partial matches
|
|
|
|
cat <<EOF >> "$ZEBRA_CONF_PATH"
|
2023-06-07 22:44:30 -07:00
|
|
|
[metrics]
|
2023-06-27 19:36:07 -07:00
|
|
|
endpoint_addr = "${METRICS_ENDPOINT_ADDR}:${METRICS_ENDPOINT_PORT}"
|
2023-06-07 22:44:30 -07:00
|
|
|
EOF
|
2023-06-27 19:36:07 -07:00
|
|
|
fi
|
2023-06-07 22:44:30 -07:00
|
|
|
|
2023-06-27 19:36:07 -07:00
|
|
|
# Set this to enable the RPC port
|
|
|
|
if [[ " $FEATURES " =~ " getblocktemplate-rpcs " ]]; then # spaces are important here to avoid partial matches
|
2023-06-07 22:44:30 -07:00
|
|
|
cat <<EOF >> "$ZEBRA_CONF_PATH"
|
|
|
|
[rpc]
|
2023-06-27 19:36:07 -07:00
|
|
|
listen_addr = "${RPC_LISTEN_ADDR}:${RPC_PORT}"
|
2023-06-07 22:44:30 -07:00
|
|
|
EOF
|
|
|
|
fi
|
|
|
|
|
2023-06-27 19:36:07 -07:00
|
|
|
if [[ -n "$LOG_FILE" ]] || [[ -n "$LOG_COLOR" ]] || [[ -n "$TRACING_ENDPOINT_ADDR" ]]; then
|
2023-06-09 00:41:09 -07:00
|
|
|
cat <<EOF >> "$ZEBRA_CONF_PATH"
|
|
|
|
[tracing]
|
2023-06-27 19:36:07 -07:00
|
|
|
EOF
|
|
|
|
if [[ " $FEATURES " =~ " filter-reload " ]]; then # spaces are important here to avoid partial matches
|
|
|
|
cat <<EOF >> "$ZEBRA_CONF_PATH"
|
|
|
|
endpoint_addr = "${TRACING_ENDPOINT_ADDR}:${TRACING_ENDPOINT_PORT}"
|
2023-06-09 00:41:09 -07:00
|
|
|
EOF
|
|
|
|
fi
|
2023-06-27 19:36:07 -07:00
|
|
|
# Set this to log to a file, if not set, logs to standard output
|
2023-06-07 22:44:30 -07:00
|
|
|
if [[ -n "$LOG_FILE" ]]; then
|
2023-06-27 19:36:07 -07:00
|
|
|
mkdir -p "$(dirname "$LOG_FILE")"
|
2023-06-07 22:44:30 -07:00
|
|
|
cat <<EOF >> "$ZEBRA_CONF_PATH"
|
|
|
|
log_file = "${LOG_FILE}"
|
2023-06-09 00:41:09 -07:00
|
|
|
EOF
|
|
|
|
fi
|
|
|
|
|
2023-06-27 19:36:07 -07:00
|
|
|
# Zebra automatically detects if it is attached to a terminal, and uses colored output.
|
|
|
|
# Set this to 'true' to force using color even if the output is not a terminal.
|
|
|
|
# Set this to 'false' to disable using color even if the output is a terminal.
|
2023-06-09 00:41:09 -07:00
|
|
|
if [[ "$LOG_COLOR" = "true" ]]; then
|
|
|
|
cat <<EOF >> "$ZEBRA_CONF_PATH"
|
|
|
|
force_use_color = true
|
|
|
|
EOF
|
|
|
|
elif [[ "$LOG_COLOR" = "false" ]]; then
|
|
|
|
cat <<EOF >> "$ZEBRA_CONF_PATH"
|
|
|
|
use_color = false
|
2023-06-07 22:44:30 -07:00
|
|
|
EOF
|
|
|
|
fi
|
2023-06-27 19:36:07 -07:00
|
|
|
fi
|
|
|
|
fi
|
2023-06-07 22:44:30 -07:00
|
|
|
|
|
|
|
echo "Using zebrad.toml:"
|
|
|
|
cat "$ZEBRA_CONF_PATH"
|
|
|
|
|
|
|
|
exec zebrad -c "$ZEBRA_CONF_PATH" "$@"
|