case "$1" in
    upgrade)
        # Stop service only during upgrade, keep enabled state
        if [ -d /run/systemd/system ]; then
            if systemctl is-active --quiet p2pool.service; then
                echo "Stopping p2pool service for upgrade..."
                systemctl stop p2pool.service
            fi
        fi
        ;;
    remove|deconfigure)
        # Stop and disable service during removal
        if [ -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
        ;;
    failed-upgrade)
        # Do nothing on failed upgrade
        ;;
    *)
        echo "prerm called with unknown argument \`$1'" >&2
        exit 1
        ;;
esac

exit 0