| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- #!/bin/bash
- #
- # DataOps Platform 停止脚本
- # 使用 supervisorctl 停止 gunicorn 服务
- #
- set -e
- # 配置变量
- APP_NAME="dataops-platform"
- APP_DIR="/opt/dataops-platform"
- # 颜色输出
- RED='\033[0;31m'
- GREEN='\033[0;32m'
- YELLOW='\033[1;33m'
- NC='\033[0m' # No Color
- echo_info() {
- echo -e "${GREEN}[INFO]${NC} $1"
- }
- echo_warn() {
- echo -e "${YELLOW}[WARN]${NC} $1"
- }
- echo_error() {
- echo -e "${RED}[ERROR]${NC} $1"
- }
- # 停止应用
- stop_app() {
- echo_info "正在停止 ${APP_NAME}..."
-
- # 检查 supervisor 是否运行
- if ! pgrep -x "supervisord" > /dev/null; then
- echo_warn "supervisord 未运行"
-
- # 尝试直接杀死 gunicorn 进程
- if pgrep -f "gunicorn.*${APP_NAME}" > /dev/null; then
- echo_info "发现 gunicorn 进程,正在终止..."
- pkill -f "gunicorn.*${APP_NAME}" || true
- echo_info "gunicorn 进程已终止"
- else
- echo_info "${APP_NAME} 未在运行"
- fi
- return 0
- fi
-
- # 检查应用状态
- status=$(sudo supervisorctl status ${APP_NAME} 2>/dev/null | awk '{print $2}' || echo "UNKNOWN")
-
- if [ "$status" = "STOPPED" ] || [ "$status" = "UNKNOWN" ]; then
- echo_info "${APP_NAME} 已经停止"
- return 0
- fi
-
- # 停止应用
- sudo supervisorctl stop ${APP_NAME}
-
- # 等待停止
- sleep 2
-
- # 检查停止状态
- status=$(sudo supervisorctl status ${APP_NAME} | awk '{print $2}')
- if [ "$status" = "STOPPED" ]; then
- echo_info "${APP_NAME} 已停止"
- else
- echo_warn "状态: ${status}"
- fi
-
- sudo supervisorctl status ${APP_NAME}
- }
- # 主函数
- main() {
- echo "=========================================="
- echo " DataOps Platform 停止脚本"
- echo "=========================================="
-
- stop_app
-
- echo ""
- echo_info "停止完成!"
- }
- main "$@"
|