download_app/stop.sh

51 lines
950 B
Bash
Executable File
Raw 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
# 停止下载管理器
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$SCRIPT_DIR"
echo "================================"
echo " 停止下载管理器"
echo "================================"
PID_FILE="download_manager.pid"
if [ ! -f "$PID_FILE" ]; then
echo "⚠️ PID文件不存在服务可能未运行"
exit 0
fi
PID=$(cat "$PID_FILE")
# 检查进程是否存在
if ! ps -p "$PID" > /dev/null 2>&1; then
echo "⚠️ 进程 $PID 不存在"
rm -f "$PID_FILE"
exit 0
fi
# 显示停止前的状态
echo ""
./show_status.sh
echo ""
# 停止进程
echo "停止进程 $PID ..."
kill "$PID"
# 等待进程结束
for i in {1..10}; do
if ! ps -p "$PID" > /dev/null 2>&1; then
echo "✅ 已成功停止"
rm -f "$PID_FILE"
exit 0
fi
sleep 1
done
# 强制结束
echo "强制停止进程..."
kill -9 "$PID"
rm -f "$PID_FILE"
echo "✅ 已强制停止"