#!/bin/bash 

#usage
function usage()
{
    echo "USAGE: pva-pp-preUninstall" 1>&2
}

function stop_sve
{
    vzlist 1

    if [ $? -eq 0 ]; then
        vzctl stop $PP_VEID
        vzctl destroy $PP_VEID
    fi

    rm -rf $PP_VE_PRIVATE
}

###################### Include common files #######################

. ${0/%pva-pp-*/pva-pp-functions.sh} || { echo "Failed to load hint functions"; exit -1;}

############################### Go  ##############################

echo "------------------------------------------------------------------------------------------------"
date "+%b %e %T PVA Power Panel preuninstall configuration : start"

# parse options
eval set -- $* --
while true ; do
    case "$1" in
        --help)		usage; exit 0 ;;
        --)		shift ; break ;;
        *) 		shift ;;
    esac
done

stop_sve || abort $? "Failed to stop Service Container"

# if PP is uninstalled on slave we should call pva-cp-preuninstall
preuninstall || abort $? "PVA Power Panel preuninstall configuration failed"

date "+%b %e %T PVA Power Panel preuninstall configuration : stop"
echo "------------------------------------------------------------------------------------------------"

exit 0

