#!/bin/sh
# prerm script for yandex-hbf-agent-init
#
# see: dh_installdeb(1)

set -e

case "$1" in
    remove|deconfigure)
        # SystemD
        if [ -x /bin/systemctl ]; then
            # It is possible, that on 'remove' action hbf-agent is already stopped or disabled.
            # In that case, 'remove package' action will fail, so return true.
            /bin/systemctl stop yandex-hbf-agent || :
            /bin/systemctl disable yandex-hbf-agent || :
        fi

        # Upstart
        if [ -x /sbin/initctl ]; then
            # Same here, return true to not break package remove action.
            /sbin/initctl stop yandex-hbf-agent || :
            rm -fv /etc/init/yandex-hbf-agent.conf || :
        fi
    ;;

    upgrade|failed-upgrade)
    ;;

    *)
        echo "prerm called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

exit 0
