Files
server/stop-web.sh
2025-11-02 19:34:16 +08:00

94 lines
2.3 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
echo "正在停止Web前端服务..."
# Web服务目录
WEB_DIR="/var/www/html/dist"
# 检查Web服务目录是否存在
if [ ! -d "$WEB_DIR" ]; then
echo "Web服务目录 $WEB_DIR 不存在"
exit 0
fi
echo "找到Web服务目录: $WEB_DIR"
# 备份当前的Web服务文件
BACKUP_DIR="/tmp/web_backup_$(date +%Y%m%d_%H%M%S)"
echo "正在备份Web服务文件到: $BACKUP_DIR"
if cp -r "$WEB_DIR" "$BACKUP_DIR"; then
echo "Web服务文件已备份到: $BACKUP_DIR"
else
echo "警告: 备份失败,继续执行停止操作..."
fi
# 停止Web服务移除服务文件
echo "正在移除Web服务文件..."
if rm -rf "$WEB_DIR"/*; then
echo "Web服务文件已清理"
else
echo "错误: 无法清理Web服务文件"
exit 1
fi
# 创建一个简单的维护页面
echo "正在创建维护页面..."
cat > "$WEB_DIR/index.html" << 'EOF'
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>服务维护中</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
padding: 50px;
background-color: #f5f5f5;
}
.container {
max-width: 600px;
margin: 0 auto;
background: white;
padding: 40px;
border-radius: 10px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
h1 {
color: #333;
margin-bottom: 20px;
}
p {
color: #666;
line-height: 1.6;
}
</style>
</head>
<body>
<div class="container">
<h1>🔧 服务维护中</h1>
<p>Web服务正在维护中请稍后再试。</p>
<p>如有紧急问题,请联系系统管理员。</p>
</div>
</body>
</html>
EOF
if [ $? -eq 0 ]; then
echo "维护页面已创建"
else
echo "警告: 无法创建维护页面"
fi
# 检查nginx是否在运行不停止只是检查状态
if pgrep nginx > /dev/null; then
echo "Nginx服务正在运行Web服务已停止但Nginx保持运行状态"
echo "如需重新部署,请运行 ./deploy-web.sh"
else
echo "注意: Nginx服务未运行可能需要启动Nginx服务"
fi
echo "Web前端服务停止操作完成"
echo "备份文件位置: $BACKUP_DIR"