#!/bin/sh
source /OSM/script/os_load_base.sh

ccdb_patch_back_start=/OSM/bin/ccdb_server.bak

PATCH_START()
{
    return 
}
PATCH_END()
{
    return
}
PATCH_ROLLBACK()
{
    if [ -f ${ccdb_patch_back_start} ]; then
        OS_echo "bak is exist, need rollback."
        daemon -s /OSM/bin/ccdb_server
        if [ $? -ne 0 ]; then
            OS_echo "hotpatch stop ccdb_server fail by daemon in SPH052."
        fi
        #check status
        i=4;
        while ((i--)); 
        do
        { 
            sleep 0.25;
            red=$(ps -ww -eo pid,cmd | grep "/OSM/bin/ccdb_server" | grep -v grep | awk '{print $1}')
            if [ "$red" = "" ]; then
                OS_echo "hotpatch kill ccdb_server success by daemon in SPH052."
                return 
            fi
        }; 
        done
    fi
    return
}
PATCH_ROLLEND()
{
    return
}
L_CMD=$1
case $L_CMD in
    "start") PATCH_START
               ;;
    "end") PATCH_END
               ;;
    "rollstart") PATCH_ROLLBACK
               ;;
    "rollend") PATCH_ROLLEND
               ;;
    *)
        OS_echo "unsupported option."
esac
exit 0