#!/bin/bash
#
# 重启 Web 服务（Tomcat）

TOMCAT_HOME="/opt/smartclean/web/tomcat"

echo "[INFO] 停止 Tomcat..."
"$TOMCAT_HOME/bin/shutdown.sh" 2>/dev/null
sleep 3

# 确保进程已停
TOMCAT_PID=$(ps -ef | grep "[c]atalina" | awk '{print $2}')
if [ -n "$TOMCAT_PID" ]; then
    echo "[WARN] Tomcat 未正常关闭，强制终止 PID=$TOMCAT_PID"
    kill -9 $TOMCAT_PID
    sleep 1
fi

# 清理旧的解压目录，保留 WAR
rm -rf "$TOMCAT_HOME/webapps/ROOT"
rm -rf "$TOMCAT_HOME/work/Catalina"

echo "[INFO] 启动 Tomcat..."
"$TOMCAT_HOME/bin/startup.sh"

echo "[INFO] Tomcat 已启动"
