#!/bin/bash
set -e

SERVICE_NAME="drone-task-manager"
SERVICE_FILE="/etc/systemd/system/${SERVICE_NAME}.service"

if [ "$EUID" -ne 0 ]; then
    echo "请使用 sudo 运行此脚本"
    exit 1
fi

if [ -f "${SERVICE_FILE}" ]; then
    echo "停止并禁用服务..."
    systemctl stop "${SERVICE_NAME}" 2>/dev/null || true
    systemctl disable "${SERVICE_NAME}" 2>/dev/null || true
    rm -f "${SERVICE_FILE}"
    systemctl daemon-reload
    echo "服务已卸载。"
else
    echo "服务文件不存在，无需卸载。"
fi
