#!/bin/bash

PATH=/sbin:/usr/sbin:/bin:/usr/bin

NAME=yasmagent
PORTO_CONTAINER_NAME="${NAME}_cocaine"

BASEDIR="/usr/local/yasmagent"
LOGDIR="/var/log/yasmagent"
RUNDIR="/var/run/yasmagent"
PIDFILE="${BASEDIR}/run/agent.pid"
[ -z "${USER}" ] && USER="monitor"
[ -z "${GROUP}" ] && GROUP="monitor"

echo "Stopping ${NAME}..."
# Check if we are in porto-container
#if ! grep -q "PORTO" /proc/1/environ && command -v portoctl >/dev/null 2>&1 && [ "${PORTO}" = "true" ]; then
#portoctl --timeout 180 destroy "${PORTO_CONTAINER_NAME}" || true
if [ -f "${PIDFILE}" ]; then
    su - "${USER}" -c "kill -9 $(cat ${PIDFILE})"
fi

echo [`date`] `pwd | cut -d/ -f4` >> /tmp/runit_flap_log

