From f98e5f0333b580e86cf80afbcaee41bfe640d9dd Mon Sep 17 00:00:00 2001 From: Djeex Date: Wed, 24 Sep 2025 15:43:35 +0200 Subject: [PATCH] Debug mode --- README.MD | 1 + VERSION | 2 +- entrypoint.sh | 21 ++++++++++++++++----- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/README.MD b/README.MD index 713a2e0..5b0736c 100644 --- a/README.MD +++ b/README.MD @@ -23,6 +23,7 @@ A lightweight Docker container that creates a UNIX socket proxy to TCP connectio | `UNIX_SOCKET_NAME` | - | Name of the socket file | `docker.sock` | | `UNIX_SOCKET_PATH` | - | Path to UNIX socket inside container | `/socket` | | `HOST_SOCKET_PATH` | - | Host path for socket mounting | `/docker/beszel-agent/sock` | +| `DEBUG_LEVEL` | - | Level of logs verbose | `0`,`1`,`2`,`3` | ## 🚢 Quick Start diff --git a/VERSION b/VERSION index 9f8e9b6..afaf360 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0 \ No newline at end of file +1.0.0 \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh index bdbdc3d..3247d77 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -9,6 +9,7 @@ TARGET_PORT=${TARGET_PORT} UNIX_SOCKET_NAME=${UNIX_SOCKET_NAME} UNIX_SOCKET_PATH=${UNIX_SOCKET_PATH} HOST_SOCKET_PATH=${HOST_SOCKET_PATH} +DEBUG_LEVEL=${DEBUG_LEVEL:-1} # Default to basic logging # Remove trailing slashes to avoid double slashes UNIX_SOCKET_PATH=${UNIX_SOCKET_PATH%/} @@ -20,7 +21,7 @@ FULL_UNIX_SOCKET_PATH="$UNIX_SOCKET_PATH/$UNIX_SOCKET_NAME" VERSION=$(cat VERSION) echo -e "${CYAN}╭────────────────────────────────────────────────╮${NC}" -echo -e "${CYAN}│${NC} Socat-proxy - Version ${VERSION}${NC} ${CYAN}│${NC}" +echo -e "${CYAN}│${NC} Socat-proxy - Version ${VERSION}${NC} ${CYAN}│${NC}" echo -e "${CYAN}├────────────────────────────────────────────────┤${NC}" echo -e "${CYAN}│${NC} Source: https://git.djeex.fr/Djeex/socat-proxy ${CYAN}│${NC}" echo -e "${CYAN}│${NC} Mirror: https://github.com/Djeex/socat-proxy ${CYAN}│${NC}" @@ -118,8 +119,19 @@ cleanup() { trap cleanup SIGTERM SIGINT echo "[~] Starting socat proxy..." -# Start socat with verbose logging and redirect to stdout/stderr -if socat -d -d UNIX-LISTEN:$FULL_UNIX_SOCKET_PATH,fork,unlink-early TCP:$TARGET_HOST:$TARGET_PORT & then +# Start socat with configurable verbosity +DEBUG_FLAGS="" +if [ "$DEBUG_LEVEL" -eq 1 ]; then + DEBUG_FLAGS="-d" +elif [ "$DEBUG_LEVEL" -eq 2 ]; then + DEBUG_FLAGS="-d -d" +elif [ "$DEBUG_LEVEL" -eq 3 ]; then + DEBUG_FLAGS="-d -d -d" +fi + +echo "[i] Using debug level: $DEBUG_LEVEL ($DEBUG_FLAGS)" + +if socat $DEBUG_FLAGS UNIX-LISTEN:$FULL_UNIX_SOCKET_PATH,fork,unlink-early TCP:$TARGET_HOST:$TARGET_PORT & then SOCAT_PID=$! echo "[✓] Socat started with PID: $SOCAT_PID" echo "[i] Socat command: socat -d -d UNIX-LISTEN:$FULL_UNIX_SOCKET_PATH,fork,unlink-early TCP:$TARGET_HOST:$TARGET_PORT" @@ -144,5 +156,4 @@ while kill -0 "$SOCAT_PID" 2>/dev/null; do done echo "[✗] Socat process has stopped" -exit 1 - +exit 1 \ No newline at end of file