#!/bin/bash
# Copyright 2016-2022 VMware, Inc.
# All rights reserved. -- VMware Confidential

ifApplmgmtUnderVmon=`service-control --status applmgmt | grep Stopped`
if [ $? -eq 0 ] ; then
    previous=`pgrep -f '/usr/bin/python /usr/lib/applmgmt/base/bin/vherdrunner /usr/lib/applmgmt/transport/bin/serve'`
    if [ $? -eq 0 ] ; then
        echo "Killing previous instance of applmgmt."
        kill -9 $previous
    fi
    # moving applmgmt under systemctl until vmon brings it up.
    echo "$(date): Starting applmgmt under systemctl."
    systemctl unmask applmgmt
    systemctl start applmgmt
fi
