#!/bin/bash

function disable_systemd {
    systemctl disable amonagent
    rm -f /lib/systemd/system/amonagent.service
}

function disable_update_rcd {
    update-rc.d -f amonagent remove
    rm -f /etc/init.d/amonagent
}

function disable_chkconfig {
    chkconfig --del amonagent
    rm -f /etc/init.d/amonagent
}

if [[ -f /etc/redhat-release ]]; then
    # RHEL-variant logic
    if [[ "$1" = "0" ]]; then
  		rm -f /etc/default/amonagent

	  which systemctl &>/dev/null
	  if [[ $? -eq 0 ]]; then
	      disable_systemd
	  else
	      # Assuming sysv
	      disable_chkconfig
	  fi
    fi
elif [[ -f /etc/debian_version ]]; then
    # Debian/Ubuntu logic
    if [[ "$1" != "upgrade" ]]; then
      # Remove/purge
      rm -f /etc/default/amonagent

      which systemctl &>/dev/null
      if [[ $? -eq 0 ]]; then
          disable_systemd
      else
          # Assuming sysv
          disable_update_rcd
      fi
    fi
fi

#!/bin/bash

function disable_systemd {
    systemctl disable amonagent
    rm -f /lib/systemd/system/amonagent.service
}

function disable_update_rcd {
    update-rc.d -f amonagent remove
    rm -f /etc/init.d/amonagent
}

function disable_chkconfig {
    chkconfig --del amonagent
    rm -f /etc/init.d/amonagent
}

if [[ -f /etc/redhat-release ]]; then
    # RHEL-variant logic
    if [[ "$1" = "0" ]]; then
  		rm -f /etc/default/amonagent

	  which systemctl &>/dev/null
	  if [[ $? -eq 0 ]]; then
	      disable_systemd
	  else
	      # Assuming sysv
	      disable_chkconfig
	  fi
    fi
elif [[ -f /etc/debian_version ]]; then
    # Debian/Ubuntu logic
    if [[ "$1" != "upgrade" ]]; then
      # Remove/purge
      rm -f /etc/default/amonagent

      which systemctl &>/dev/null
      if [[ $? -eq 0 ]]; then
          disable_systemd
          deb-systemd-invoke stop amonagent.service
      else
          # Assuming sysv
          disable_update_rcd
          invoke-rc.d amonagent stop
      fi
    fi
fi
--- 
+++ 
@@ -37,11 +37,9 @@
       which systemctl &>/dev/null
       if [[ $? -eq 0 ]]; then
           disable_systemd
-          deb-systemd-invoke stop amonagent.service
       else
           # Assuming sysv
           disable_update_rcd
-          invoke-rc.d amonagent stop
       fi
     fi
 fi
Remove calls to stop service

It looks like the prerm handles stopping the service so it shouldn't need to be called here as well.
If you try to remove this package you get the following error because it's trying to stop a service after the systemd or sysv scripts are removed:

Removing amonagent (1:0.7.2) ...
Removed symlink /etc/systemd/system/multi-user.target.wants/amonagent.service.
Removed symlink /etc/systemd/system/amonagent.service.
Failed to stop amonagent.service: Unit amonagent.service not loaded.
dpkg: error processing package amonagent (--remove):
 subprocess installed post-removal script returned error exit status 5
Errors were encountered while processing:
 amonagent
E: Sub-process /usr/bin/dpkg returned an error code (1)