#!/bin/sh -e


pre_rm()
{
	SVC="mega-graphite-storage"
	if [ -x /bin/systemctl -a -f /etc/systemd/system/${SVC}.service ] ; then
		if ! /bin/systemctl stop ${SVC} ; then
			echo "Cannot stop ${SVC} service!"
		fi
		if ! /bin/systemctl disable ${SVC} ; then
			echo "Cannot disable ${SVC} service!"
		fi
	elif [ -x /usr/sbin/service -a -f /etc/init/${SVC}.conf ] ; then
		if ! /usr/sbin/service ${SVC} stop ; then
			echo "Cannot stop ${SVC} service!"
		fi
	fi
}


case "$1" in
	remove|purge|disappear|failed-upgrade|upgrade|deconfigure)
		pre_rm || true
	;;

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

exit 0
