52c75d7a / scripts /start /frpc-start.sh
autoface's picture
Updated the log directory structure to change all log paths from `/home/user/logs` to `/home/user/log` to simplify file management. Also update related scripts and configuration files to reflect this change.
5b0a02b
#!/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