From 23b4babc232ba69970a3debd17fea33a7d521946 Mon Sep 17 00:00:00 2001 From: Leon <147289645+LeoninCS@users.noreply.github.com> Date: Tue, 23 Dec 2025 02:27:41 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E5=90=AF=E5=8A=A8=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=8A=A0=E5=85=A5=E4=BA=86redis=E7=9A=84=E5=90=AF?= =?UTF-8?q?=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- start.sh | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/start.sh b/start.sh index ec1c72f..e7eb07e 100644 --- a/start.sh +++ b/start.sh @@ -1,2 +1,41 @@ -# 启动服务器 -go run cmd/main.go \ No newline at end of file +#!/usr/bin/env sh +set -eu + +ROOT_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)" +cd "$ROOT_DIR" + +RUN_DIR="$ROOT_DIR/.run" +mkdir -p "$RUN_DIR" + +# Start Redis (optional). +# - If you already run Redis elsewhere, this will detect it (when redis-cli exists) and skip. +REDIS_HOST="${REDIS_HOST:-127.0.0.1}" +REDIS_PORT="${REDIS_PORT:-6379}" +REDIS_CONF="${REDIS_CONF:-}" + +start_redis() { + if ! command -v redis-server >/dev/null 2>&1; then + echo "[start.sh] redis-server not found; skip starting Redis" + return 0 + fi + + if command -v redis-cli >/dev/null 2>&1; then + if redis-cli -h "$REDIS_HOST" -p "$REDIS_PORT" ping >/dev/null 2>&1; then + echo "[start.sh] Redis already running at $REDIS_HOST:$REDIS_PORT" + return 0 + fi + fi + + echo "[start.sh] Starting Redis at $REDIS_HOST:$REDIS_PORT" + if [ -n "$REDIS_CONF" ]; then + nohup redis-server "$REDIS_CONF" >"$RUN_DIR/redis.log" 2>&1 & + else + nohup redis-server --bind "$REDIS_HOST" --port "$REDIS_PORT" >"$RUN_DIR/redis.log" 2>&1 & + fi + echo $! >"$RUN_DIR/redis.pid" +} + +start_redis + +echo "[start.sh] Starting app" +go run ./cmd