#!/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') 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}" </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}"