Files
nym/docker/localnet/localnet-logs.sh
2026-02-17 08:39:57 +01:00

72 lines
1.9 KiB
Bash
Executable File

#!/bin/bash
# Tmux-based log viewer for Nym Localnet containers
# Shows all container logs in a multi-pane layout
SESSION_NAME="nym-localnet-logs"
# Detect runtime
if command -v container &> /dev/null; then
RUNTIME="container"
else
RUNTIME="docker"
fi
# Container names
CONTAINERS=(
"nym-mixnode1"
"nym-mixnode2"
"nym-mixnode3"
"nym-gateway"
"nym-network-requester"
"nym-socks5-client"
)
# Check if containers are running
running_containers=()
for ctr in "${CONTAINERS[@]}"; do
if $RUNTIME inspect "$ctr" &>/dev/null; then
running_containers+=("$ctr")
fi
done
if [ ${#running_containers[@]} -eq 0 ]; then
echo "Error: No containers are running"
echo "Start the localnet first: ./localnet.sh start"
exit 1
fi
# Check if we're already in tmux
if [ -n "$TMUX" ]; then
# Inside tmux - create new window
tmux new-window -n "logs" "$RUNTIME logs -f ${running_containers[0]}"
# Split for remaining containers
for ((i=1; i<${#running_containers[@]}; i++)); do
tmux split-window -t logs "$RUNTIME logs -f ${running_containers[$i]}"
tmux select-layout -t logs tiled
done
tmux select-layout -t logs tiled
else
# Not in tmux - check if session exists
if tmux has-session -t "$SESSION_NAME" 2>/dev/null; then
# Session exists - attach to it
exec tmux attach-session -t "$SESSION_NAME"
else
# Create new session
tmux new-session -d -s "$SESSION_NAME" -n "logs" "$RUNTIME logs -f ${running_containers[0]}"
# Split for remaining containers
for ((i=1; i<${#running_containers[@]}; i++)); do
tmux split-window -t "$SESSION_NAME:logs" "$RUNTIME logs -f ${running_containers[$i]}"
tmux select-layout -t "$SESSION_NAME:logs" tiled
done
tmux select-layout -t "$SESSION_NAME:logs" tiled
# Attach to the session
exec tmux attach-session -t "$SESSION_NAME"
fi
fi