#!/bin/sh

SYSTEMCTL=$(which systemctl 2> /dev/null)
SERVICE=$(which service 2> /dev/null)
CHKCONFIG=$(which chkconfig 2> /dev/null)


######################################################
# (SYSTEMCTL)
######################################################
if [ -n "${SYSTEMCTL}" ]; then
  systemctl stop exem-manager-agent
  echo "exem-manager-agent is stopped [service_stop.sh]"

  systemctl disable exem-manager-agent
  systemctl daemon-reload

  if [ -e "/etc/systemd/system/exem-manager-agent.service" ]; then
    rm -f /etc/systemd/system/exem-manager-agent.service
    systemctl daemon-reload
  fi

  if [ -e "/etc/systemd/system/default.target.wants/exem-manager-agent.service" ]; then
    rm -f /etc/systemd/system/default.target.wants/exem-manager-agent.service
    systemctl daemon-reload
  fi

  echo "exem-manager-agent is disabled [service_stop.sh]"

  exit 0

######################################################
# (others)
######################################################
else
  echo "this OS version that does not support service registration"
  exit 1
fi
