Files

42 lines
1.3 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
log() { echo "[rathole] $(date -Is) $*"; }
abort() { echo "[rathole] ERROR: $*" >&2; exit 1; }
: "${APP_PORT:=3000}"
: "${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 server mode with config ${RATHOLE_CONFIG_PATH}"
exec /app/pkg/rathole server -c "$RATHOLE_CONFIG_PATH"