#!/bin/bash ############################################## # Snapshot 前端停止服务脚本 # 适用于 Linux 环境 ############################################## # 颜色输出 RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color print_info() { echo -e "${GREEN}[INFO]${NC} $1" } print_error() { echo -e "${RED}[ERROR]${NC} $1" } print_warning() { echo -e "${YELLOW}[WARNING]${NC} $1" } echo "============================================" echo "Snapshot 前端停止服务" echo "============================================" echo # 查找npm/node相关进程 PIDS=$(pgrep -f "vue-cli-service serve") if [ -z "$PIDS" ]; then PIDS=$(pgrep -f "npm run serve") fi if [ -z "$PIDS" ]; then PIDS=$(pgrep -f "node.*8081") fi if [ -z "$PIDS" ]; then print_warning "未找到运行中的Snapshot前端服务" exit 0 fi print_info "找到运行中的服务进程:" echo "$PIDS" echo # 尝试优雅停止 print_info "正在停止服务..." for PID in $PIDS; do if ps -p $PID > /dev/null; then kill $PID print_info "已发送停止信号到进程: $PID" fi done # 等待进程结束 sleep 3 # 检查是否还有进程运行 REMAINING_PIDS="" if pgrep -f "vue-cli-service serve" > /dev/null; then REMAINING_PIDS=$(pgrep -f "vue-cli-service serve") elif pgrep -f "npm run serve" > /dev/null; then REMAINING_PIDS=$(pgrep -f "npm run serve") elif pgrep -f "node.*8081" > /dev/null; then REMAINING_PIDS=$(pgrep -f "node.*8081") fi if [ -n "$REMAINING_PIDS" ]; then print_warning "服务未响应,强制停止..." for PID in $REMAINING_PIDS; do if ps -p $PID > /dev/null; then kill -9 $PID print_info "已强制停止进程: $PID" fi done sleep 1 fi # 最终检查 FINAL_CHECK="" if pgrep -f "vue-cli-service serve" > /dev/null; then FINAL_CHECK="running" elif pgrep -f "npm run serve" > /dev/null; then FINAL_CHECK="running" elif pgrep -f "node.*8081" > /dev/null; then FINAL_CHECK="running" fi if [ "$FINAL_CHECK" = "running" ]; then print_error "停止失败,请手动检查" echo "尝试手动执行: pkill -f 'vue-cli-service serve'" exit 1 else print_info "服务已成功停止" fi echo print_info "Snapshot 前端服务已停止"