| #!/bin/bash |
|
|
| set -e |
|
|
| |
| log() { |
| echo "[$(date '+%Y-%m-%d %H:%M:%S')] [FRPC] $*" |
| } |
|
|
| log "Starting frpc (Fast Reverse Proxy Client)..." |
|
|
| |
| if [[ -z "${FRPC_SERVER_ADDR}" ]]; then |
| log "ERROR: FRPC_SERVER_ADDR environment variable is required" |
| exit 1 |
| fi |
|
|
| |
| if [[ -z "${FRPC_SERVER_PORT}" ]]; then |
| export FRPC_SERVER_PORT=7000 |
| log "Using default server port: ${FRPC_SERVER_PORT}" |
| fi |
|
|
| if [[ -z "${FRPC_AUTH_TOKEN}" ]]; then |
| log "ERROR: FRPC_AUTH_TOKEN environment variable is required" |
| exit 1 |
| fi |
|
|
| log "Environment variables validated successfully" |
| log "Server: ${FRPC_SERVER_ADDR}:${FRPC_SERVER_PORT}" |
| log "Auth token: ${FRPC_AUTH_TOKEN:0:8}..." |
|
|
| |
| if [[ ! -f "/home/user/config/frpc.toml" ]]; then |
| log "ERROR: frpc configuration template not found at /home/user/config/frpc.toml" |
| exit 1 |
| fi |
|
|
| |
| log "Creating runtime configuration from template..." |
| mkdir -p /home/user/log |
| envsubst < /home/user/config/frpc.toml > /home/user/log/frpc_runtime.toml |
|
|
| |
| if ! command -v frpc &> /dev/null; then |
| log "ERROR: frpc binary not found in PATH" |
| exit 1 |
| fi |
|
|
| |
| log "Validating frpc runtime configuration..." |
| if ! frpc verify -c /home/user/log/frpc_runtime.toml; then |
| log "ERROR: Invalid frpc runtime configuration" |
| log "Generated configuration:" |
| cat /home/user/log/frpc_runtime.toml |
| exit 1 |
| fi |
|
|
| log "frpc runtime configuration is valid" |
|
|
| |
| if [[ "${FRPC_ENABLED:-true}" != "true" ]]; then |
| log "frpc is disabled via FRPC_ENABLED environment variable" |
| exit 0 |
| fi |
|
|
| |
| log "Starting frpc with runtime configuration: /home/user/log/frpc_runtime.toml" |
| exec frpc -c /home/user/log/frpc_runtime.toml |
|
|