#!/bin/sh
# Copyright (c) 2026 Athan Clark. SPDX-License-Identifier: GPL-3.0-only
# Stops the services before removal or an upgrade. After an upgrade the server starts again
# with openchronology-migrate, once the database matches the new version.
set -e
case "$1" in
  remove | upgrade | deconfigure)
    if [ -d /run/systemd/system ]; then
      systemctl stop openchronology.service openchronology-mail.service \
        openchronology-syslog.service openchronology-journald.service >/dev/null 2>&1 || true
    fi
    ;;
esac
if [ "$1" = remove ] && [ -d /run/systemd/system ]; then
  systemctl disable --quiet openchronology.service openchronology-mail.service \
    openchronology-syslog.service openchronology-journald.service >/dev/null 2>&1 || true
fi
exit 0
