VPSHUB/app/uninstall.sh
2026-05-24 03:04:41 +08:00

72 lines
1.9 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
# 核云IDC服务商VPS自动监测重启程序 - 卸载脚本
# 该脚本会移除systemd服务并清理相关文件
# 定义服务名称
SERVICE_NAME="idc-monitor"
SERVICE_FILE="/etc/systemd/system/${SERVICE_NAME}.service"
echo "正在卸载 ${SERVICE_NAME} 服务..."
# 检查是否以root权限运行
if [ "$EUID" -ne 0 ]; then
echo "错误: 请以root权限运行此脚本 (sudo ./uninstall.sh)"
exit 1
fi
# 检查服务是否存在
if [ ! -f "${SERVICE_FILE}" ]; then
echo "警告: 服务文件 ${SERVICE_FILE} 不存在"
echo "可能服务未安装或已被卸载"
exit 0
fi
# 停止服务
echo "正在停止服务..."
if systemctl is-active --quiet ${SERVICE_NAME}; then
systemctl stop ${SERVICE_NAME}
echo "✅ 服务已停止"
else
echo "服务未运行,跳过停止步骤"
fi
# 禁用服务(取消开机自启)
echo "正在禁用服务..."
if systemctl is-enabled --quiet ${SERVICE_NAME} 2>/dev/null; then
systemctl disable ${SERVICE_NAME}
echo "✅ 服务已禁用"
else
echo "服务未启用,跳过禁用步骤"
fi
# 重新加载systemd配置
echo "正在清理systemd配置..."
systemctl daemon-reload
systemctl reset-failed ${SERVICE_NAME} 2>/dev/null
# 删除服务文件
echo "正在删除服务文件..."
rm -f ${SERVICE_FILE}
echo "✅ 服务文件已删除: ${SERVICE_FILE}"
# 清理journal日志可选
echo ""
read -p "是否同时清理该服务的历史日志?(y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
journalctl --rotate
journalctl --vacuum-time=1s 2>/dev/null
echo "✅ 日志已清理"
else
echo "跳过日志清理"
fi
echo ""
echo "${SERVICE_NAME} 服务已成功卸载"
echo ""
echo "注意:"
echo " - Python依赖包未被卸载如需清理请手动执行: pip uninstall -r requirements.txt"
echo " - 项目文件未被删除,如需删除请手动清理项目目录"
echo ""
echo "卸载完成!"