imetting/stop-external.sh

58 lines
1.3 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#!/bin/bash
set -e
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
print_info() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
if docker compose version &> /dev/null; then
COMPOSE_CMD="docker compose"
else
COMPOSE_CMD="docker-compose"
fi
print_info "当前应用服务状态:"
$COMPOSE_CMD ps backend frontend
echo ""
echo -e "${YELLOW}是否保留应用容器?${NC}"
echo "1) 仅停止 backend/frontend保留容器"
echo "2) 停止并删除 backend/frontend 容器"
read -p "请选择 (1/2): " choice
case $choice in
1)
print_info "停止应用服务..."
$COMPOSE_CMD stop backend frontend
print_success "应用服务已停止,外部数据库和 Redis 未受影响"
;;
2)
print_info "停止并删除应用容器..."
$COMPOSE_CMD stop backend frontend
$COMPOSE_CMD rm -f backend frontend
print_success "应用容器已删除,外部数据库和 Redis 未受影响"
;;
*)
print_warning "无效选择,仅停止应用服务"
$COMPOSE_CMD stop backend frontend
;;
esac