#!/bin/sh

# EXPORT
export MGR_EXEM_HOME={{ EXEM_HOME }}
export MGR_EXEM_MANAGER_HOME={{ EXEM_HOME }}/manager
export MGR_RECEIVER_ADDR={{ RECEIVER_ADDR }}:{{ MANAGER_RECEIVER_PORT | default('9010') }}

PIDFILE=${MGR_EXEM_MANAGER_HOME}/data/manager_agent_pid

if [ -f "${PIDFILE}" ]; then
  PID=`echo -n | cat ${PIDFILE}`
  IS_RUNNING=`ps -fp "${PID}" | grep -c exem-manager-agent`

  if [ "${IS_RUNNING}" -ne 0 ]; then
    echo "exem-manager-agent is already running (${PID})"
    exit 1
  fi
fi

chmod 755 ${MGR_EXEM_MANAGER_HOME}/bin/exem-manager-agent

ulimit -n 1024

${MGR_EXEM_MANAGER_HOME}/bin/exem-manager-agent -D

echo "exem-manager-agent is started [binary_start.sh]"