feat(rathole): add clean Cloudron package using base 5.0.0 with server/client config and health endpoint

This commit is contained in:
2025-09-12 14:26:43 -05:00
parent c835a8438b
commit 11365035b8
5 changed files with 148 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
#!/usr/bin/env bash
set -euo pipefail
log() { echo "[rathole] $(date -Is) $*"; }
abort() { echo "[rathole] ERROR: $*" >&2; exit 1; }
: "${APP_PORT:=3000}"
: "${RATHOLE_MODE:=server}" # server|client
: "${RATHOLE_CONFIG_PATH:=/app/data/rathole.toml}"
# Ensure data dir exists
mkdir -p /app/data
chown -R cloudron:cloudron /app/data || true
# If RATHOLE_CONFIG is provided, write it to config path if file not present
if [[ ! -f "$RATHOLE_CONFIG_PATH" && -n "${RATHOLE_CONFIG:-}" ]]; then
log "Writing config from RATHOLE_CONFIG env to ${RATHOLE_CONFIG_PATH}"
printf "%s\n" "${RATHOLE_CONFIG}" > "$RATHOLE_CONFIG_PATH"
fi
# If still no config, create a minimal example for server mode
if [[ ! -f "$RATHOLE_CONFIG_PATH" ]]; then
log "No config found. Writing a minimal example config (server). Adjust in /app/data/rathole.toml"
cat > "$RATHOLE_CONFIG_PATH" <<'TOML'
# Minimal Rathole server config example
[server]
bind_addr = "0.0.0.0:2333"
# Define services below as needed, for example:
# [server.services.echo]
# type = "tcp"
# local_addr = "127.0.0.1:7"
TOML
fi
# Background: lightweight HTTP health endpoint
python3 -m http.server "$APP_PORT" --bind 0.0.0.0 >/dev/null 2>&1 &
HEALTH_PID=$!
log "Started health endpoint on :${APP_PORT} (pid ${HEALTH_PID})"
log "Launching rathole in ${RATHOLE_MODE} mode with config ${RATHOLE_CONFIG_PATH}"
exec /app/pkg/rathole "$RATHOLE_MODE" -c "$RATHOLE_CONFIG_PATH"