File size: 2,002 Bytes
9b205e1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5b0a02b
 
9b205e1
 
 
 
 
 
 
 
 
5b0a02b
9b205e1
 
5b0a02b
9b205e1
 
 
 
 
 
 
 
 
 
 
 
5b0a02b
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/bash

set -e

# Log function
log() {
    echo "[$(date '+%Y-%m-%d %H:%M:%S')] [FRPC] $*"
}

log "Starting frpc (Fast Reverse Proxy Client)..."

# Check required environment variables
if [[ -z "${FRPC_SERVER_ADDR}" ]]; then
    log "ERROR: FRPC_SERVER_ADDR environment variable is required"
    exit 1
fi

# FRPC_SERVER_PORT is optional, defaults to 7000
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}..."

# Check if frpc configuration template exists
if [[ ! -f "/home/user/config/frpc.toml" ]]; then
    log "ERROR: frpc configuration template not found at /home/user/config/frpc.toml"
    exit 1
fi

# Create runtime configuration by substituting environment variables
log "Creating runtime configuration from template..."
    mkdir -p /home/user/log
    envsubst < /home/user/config/frpc.toml > /home/user/log/frpc_runtime.toml

# Check if frpc binary exists
if ! command -v frpc &> /dev/null; then
    log "ERROR: frpc binary not found in PATH"
    exit 1
fi

# Validate runtime configuration file
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"

# Check if FRPC_ENABLED environment variable is set
if [[ "${FRPC_ENABLED:-true}" != "true" ]]; then
    log "frpc is disabled via FRPC_ENABLED environment variable"
    exit 0
fi

# Start frpc with runtime configuration
log "Starting frpc with runtime configuration: /home/user/log/frpc_runtime.toml"
exec frpc -c /home/user/log/frpc_runtime.toml