PyBot/uninstall.sh
2026-05-20 00:40:03 +08:00

67 lines
1.7 KiB
Bash
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
set -e
SERVICES=("PyBot")
echo "=============================="
echo "开始卸载 PyBot 服务"
echo "=============================="
for SERVICE in "${SERVICES[@]}"; do
echo ""
echo ">>> 处理服务: $SERVICE"
# 停止并禁用服务
if systemctl is-active --quiet $SERVICE; then
sudo systemctl stop $SERVICE
echo "✅ 服务已停止"
fi
if systemctl is-enabled --quiet $SERVICE 2>/dev/null; then
sudo systemctl disable $SERVICE
echo "✅ 已取消开机自启"
fi
# 删除服务文件
SERVICE_FILE="/etc/systemd/system/${SERVICE}.service"
if [ -f "$SERVICE_FILE" ]; then
sudo rm -f "$SERVICE_FILE"
echo "✅ 服务文件已删除"
fi
# 清理残留进程
PIDS=$(pgrep -f "python.*Core\.py" 2>/dev/null || true)
if [ -n "$PIDS" ]; then
sudo kill -15 $PIDS 2>/dev/null || true
sleep 1
sudo kill -9 $PIDS 2>/dev/null || true
echo "✅ 残留进程已清理"
fi
done
# 重载 systemd
sudo systemctl daemon-reload
echo "✅ systemd 已重载"
echo ""
echo "=============================="
echo "✅ 卸载完成"
echo "=============================="
echo ""
echo "📝 提示:"
echo " • 配置文件保留在 config/ 目录"
echo " • 完全删除项目请手动删除整个文件夹"
echo " • 卸载依赖: pip uninstall -r requirements.txt -y"
echo ""
# 验证
for SERVICE in "${SERVICES[@]}"; do
if ! systemctl status $SERVICE &>/dev/null; then
echo "✅ 服务 $SERVICE 已彻底删除"
else
echo "⚠️ 服务 $SERVICE 可能仍存在"
fi
done
echo ""
echo "感谢使用 PyBot👋"