#!/bin/sh

if [ "$1" = "-b" ]; then
  {{ EXEM_HOME }}/manager/script/binary_stop.sh

else
  if [ "$OS_NAME" = "SunOS" ]; then
    ID=`/usr/xpg4/bin/id -u`
  else
    ID=`id -u`
  fi

  if [ "$ID" -eq 0 ]; then
    {{ EXEM_HOME }}/manager/script/service_stop.sh
    if [ "$?" != 0 ]; then
      {{ EXEM_HOME }}/manager/script/binary_stop.sh
    fi
  else
    echo "No root privileges. Stopping without unregistering service."

    {{ EXEM_HOME }}/manager/script/binary_stop.sh
  fi
fi

if [ "$?" = 0 ]; then
  echo "xmSuccess(0): exem-manager-agent is stopped"
else
  echo "xmError(1): Failed to stop exem-manager-agent"
fi
