Files
users/scripts/start.sh

46 lines
1.1 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 神射手 - 智能启动脚本(端口冲突检查 + 指定端口)
# 端口: 3117见 端口登记.md
# 用法: ./scripts/start.sh [--kill] # --kill 自动终止占用进程
set -e
cd "$(dirname "$0")/.."
PORT=3117
AUTO_KILL=false
[[ "$1" == "--kill" ]] && AUTO_KILL=true
# 检查端口是否被占用
check_port() {
if lsof -i :$PORT >/dev/null 2>&1; then
echo "⚠️ 端口 $PORT 已被占用:"
lsof -i :$PORT
echo ""
if $AUTO_KILL; then
echo "正在终止占用进程..."
lsof -ti :$PORT | xargs kill -9 2>/dev/null || true
sleep 2
else
echo "解决方式:"
echo " 1) 运行 ./scripts/start.sh --kill 自动终止后启动"
echo " 2) 或手动执行: lsof -ti :$PORT | xargs kill -9"
exit 1
fi
fi
}
echo "=== 神射手 启动 ==="
echo "端口: $PORT | 访问: http://localhost:$PORT"
echo ""
check_port
# 优先 pnpm其次 npm
if command -v pnpm &>/dev/null; then
pnpm dev
elif command -v npm &>/dev/null; then
npm run dev
else
echo "❌ 未找到 pnpm 或 npm"
exit 1
fi