#!/bin/sh
# Cerynix — prerm
# Copyright (c) 2026 SIA Cerynix. All rights reserved.
# SPDX-License-Identifier: LicenseRef-Cerynix-Proprietary
#
# Stop the stack on removal. Data volumes (DB, object store) are Docker-managed
# and are intentionally left intact so a reinstall keeps the tenant's data.
set -e

UNIT=cerynix.service

case "$1" in
  remove|deconfigure)
    if [ -d /run/systemd/system ] && command -v deb-systemd-invoke >/dev/null 2>&1; then
      deb-systemd-invoke stop "$UNIT" >/dev/null 2>&1 || true
    elif command -v systemctl >/dev/null 2>&1; then
      systemctl stop "$UNIT" >/dev/null 2>&1 || true
    fi
    ;;
  upgrade|failed-upgrade)
    ;;
esac

exit 0
