Files
KamadoPool-StartOS-0351/docker_entrypoint.sh
T
satoshi 54935bf638 Add configurable stratum port (default 3333)
Exposes stratum-port in the StartOS config UI so users running
simpleproxy or another TCP forwarder can point Kamado at a
non-default port. Entrypoint substitutes the value into
ckpool.conf serverurl.

Also pins placeholder KAMADO_SHA in the Dockerfile — swap to a
real pushed commit before the first build.
2026-04-13 03:54:49 +03:00

102 lines
2.8 KiB
Bash
Executable File

#!/bin/bash
# Kamado Pool StartOS entrypoint.
#
# Renders ckpool.conf from /root/.kamado/start9/config.yaml, resolves
# which bitcoind variant the user picked (mainnet vs testnet4), then
# supervises ckpool and kamado-api as a pair — if either exits, tear
# the container down so StartOS restarts the service cleanly.
set -euo pipefail
CONFIG_FILE="/root/.kamado/start9/config.yaml"
CKPOOL_DIR="/root/.ckpool"
CKPOOL_CONF="${CKPOOL_DIR}/ckpool.conf"
CKPOOL_LOG_DIR="${CKPOOL_DIR}/logs"
mkdir -p "${CKPOOL_DIR}" "${CKPOOL_LOG_DIR}"
if [[ ! -f "${CONFIG_FILE}" ]]; then
echo "kamado-entrypoint: config file missing: ${CONFIG_FILE}" >&2
exit 1
fi
q() { yq -r "$1" "${CONFIG_FILE}"; }
BITCOIND_VARIANT=$(q '.bitcoind.type')
case "${BITCOIND_VARIANT}" in
bitcoind)
BITCOIN_HOST="bitcoind.embassy"
BITCOIN_PORT=8332
;;
bitcoind-testnet)
BITCOIN_HOST="bitcoind-testnet.embassy"
BITCOIN_PORT=48332
;;
*)
echo "kamado-entrypoint: unknown bitcoind variant: ${BITCOIND_VARIANT}" >&2
exit 1
;;
esac
BITCOIN_USER=$(q '.bitcoind.user')
BITCOIN_PASS=$(q '.bitcoind.password')
POOL_BTCADDRESS=$(q '.pool-address')
POOL_IDENTIFIER=$(q '.pool-identifier')
STRATUM_PORT=$(q '.stratum-port // 3333')
DROPIDLE=$(q '.dropidle // 0')
STARTDIFF=$(q '.startdiff // 16384')
MINDIFF=$(q '.mindiff // 1000')
MAXDIFF=$(q '.maxdiff // 0')
LOG_LEVEL=$(q '.log-level // "info"')
cat > "${CKPOOL_CONF}" <<EOF
{
"btcd": [
{
"url": "${BITCOIN_HOST}:${BITCOIN_PORT}",
"auth": "${BITCOIN_USER}",
"pass": "${BITCOIN_PASS}",
"notify": true
}
],
"btcaddress": "${POOL_BTCADDRESS}",
"btcsig": "${POOL_IDENTIFIER}",
"serverurl": [
"0.0.0.0:${STRATUM_PORT}"
],
"mindiff": ${MINDIFF},
"startdiff": ${STARTDIFF},
"maxdiff": ${MAXDIFF},
"logdir": "${CKPOOL_LOG_DIR}"
}
EOF
echo "kamado-entrypoint: starting ckpool (solo, ${BITCOIND_VARIANT})"
ckpool -B -c "${CKPOOL_CONF}" &
CKPOOL_PID=$!
export KAMADO_CKPOOL_SOCKET="${CKPOOL_DIR}/solo/listener"
export KAMADO_CKPOOL_LOGFILE="${CKPOOL_LOG_DIR}/ckpool.log"
export KAMADO_BITCOIND_URL="http://${BITCOIN_HOST}:${BITCOIN_PORT}"
export KAMADO_BITCOIND_USER="${BITCOIN_USER}"
export KAMADO_BITCOIND_PASS="${BITCOIN_PASS}"
export KAMADO_HTTP_ADDR=":8080"
export KAMADO_LOG_LEVEL="${LOG_LEVEL}"
echo "kamado-entrypoint: starting kamado-api"
kamado-api &
API_PID=$!
term() {
echo "kamado-entrypoint: SIGTERM — shutting down"
kill -TERM "${API_PID}" "${CKPOOL_PID}" 2>/dev/null || true
wait "${API_PID}" "${CKPOOL_PID}" 2>/dev/null || true
exit 0
}
trap term TERM INT
wait -n "${CKPOOL_PID}" "${API_PID}"
EXIT_CODE=$?
echo "kamado-entrypoint: one of ckpool/kamado-api exited (${EXIT_CODE}), stopping the other"
kill -TERM "${API_PID}" "${CKPOOL_PID}" 2>/dev/null || true
wait || true
exit "${EXIT_CODE}"