
#! /bin/sh

#tries to kill mcp up to 10 times
echo "disabling mcp"
i=0
while [ $i -lt 10 ]; do
    mcp_pids=`pgrep isi_mcp`
    if [ $? -eq 1 ];
    then
        break;
    fi
    if [ $i -lt 5 ]; then
        kill -3 $mcp_pids
        sleep 2
    else
        kill -9 $mcp_pids
        sleep 2
    fi
    let i=i+1
done




if pgrep isi_mcp > /dev/null;
then
    echo "mcp still running after 10 kill attempts!";
    exit 1
else
    echo "mcp disabled";
fi

if isi services isi_hdfs_d | grep enabled; then
    echo "disabling hdfs"
    isi services isi_hdfs_d disable
    touch /tmp/pkg_isi_hdfs_d
    echo "sleeping 10 seconds for services to settle"
    sleep 10
    if ps axw|grep isi_hdfs_d|grep -v grep; then
        echo "hdfs still running, killing"
        killall -9 isi_hdfs_d
    fi
fi

if isi services -a isi_papi_d | grep enabled; then
    echo "disabling isi_papi_d"
    isi services -a isi_papi_d disable
    touch /tmp/pkg_isi_papi_d
    echo "sleeping 10 seconds for services to settle"
    sleep 10
    if ps axw|grep isi_papi_d|grep -v grep; then
        echo "isi_papi_d still running, killing"
        killall -9 isi_papi_d
    fi
fi

exit 0
