#!/bin/sh
set -e

# 仅在卸载(remove)时停用服务；升级(upgrade)时保持运行，
# 由 postinst 的 try-restart 重启以加载新二进制
if [ "$1" = "remove" ] && [ -d /run/systemd/system ]; then
    if systemctl is-active --quiet p2pool.service; then
        echo "Stopping p2pool service..."
        systemctl stop p2pool.service
    fi

    if systemctl is-enabled --quiet p2pool.service 2>/dev/null; then
        echo "Disabling p2pool service..."
        systemctl disable p2pool.service
    fi
fi

exit 0
