95 lines
2 KiB
Bash
Executable file
95 lines
2 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# shellcheck source=scripts/_compose.sh
|
|
source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)/_compose.sh"
|
|
|
|
usage() {
|
|
cat <<'EOF'
|
|
Usage: ./scripts/logs.sh [options] [service...]
|
|
|
|
Stream or view logs from GCoordinator Docker Compose services.
|
|
|
|
Options:
|
|
--lan Use LAN compose configuration
|
|
--cloudflare Use Cloudflare compose configuration
|
|
--mode <lan|cloudflare> Explicitly select deployment mode
|
|
-n, --tail <N> Number of historical log lines to show (default: 100)
|
|
--no-follow Print recent logs and exit without following
|
|
--dry-run Print the compose command without executing it
|
|
-h, --help Show this help message
|
|
EOF
|
|
}
|
|
|
|
REQ_MODE=""
|
|
TAIL_LINES="100"
|
|
FOLLOW=1
|
|
SERVICES=()
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
case "$1" in
|
|
--lan)
|
|
REQ_MODE="lan"
|
|
shift
|
|
;;
|
|
--cloudflare)
|
|
REQ_MODE="cloudflare"
|
|
shift
|
|
;;
|
|
--mode)
|
|
[[ $# -ge 2 ]] || die "--mode requires an argument."
|
|
REQ_MODE="$2"
|
|
shift 2
|
|
;;
|
|
--mode=*)
|
|
REQ_MODE="${1#*=}"
|
|
shift
|
|
;;
|
|
-n|--tail)
|
|
[[ $# -ge 2 ]] || die "$1 requires a number."
|
|
TAIL_LINES="$2"
|
|
shift 2
|
|
;;
|
|
--tail=*)
|
|
TAIL_LINES="${1#*=}"
|
|
shift
|
|
;;
|
|
--no-follow)
|
|
FOLLOW=0
|
|
shift
|
|
;;
|
|
--dry-run)
|
|
DRY_RUN=1
|
|
shift
|
|
;;
|
|
-h|--help)
|
|
usage
|
|
exit 0
|
|
;;
|
|
--)
|
|
shift
|
|
SERVICES+=("$@")
|
|
break
|
|
;;
|
|
-*)
|
|
die "Unknown option: $1 (run with --help)"
|
|
;;
|
|
*)
|
|
SERVICES+=("$1")
|
|
shift
|
|
;;
|
|
esac
|
|
done
|
|
|
|
[[ "$TAIL_LINES" =~ ^[0-9]+$ || "$TAIL_LINES" == "all" ]] || die "Invalid --tail value '$TAIL_LINES'."
|
|
|
|
MODE="$(resolve_mode "$REQ_MODE")"
|
|
LOG_ARGS=(logs --tail "$TAIL_LINES")
|
|
if [[ "$FOLLOW" -eq 1 ]]; then
|
|
LOG_ARGS+=(-f)
|
|
fi
|
|
if [[ ${#SERVICES[@]} -gt 0 ]]; then
|
|
LOG_ARGS+=("${SERVICES[@]}")
|
|
fi
|
|
|
|
run_compose "$MODE" "${LOG_ARGS[@]}"
|