#!/bin/sh
source /OSM/script/os_load_base.sh
PATCH_START()
{
    #备份进程
	cp /OSM/bin/ccdb_server /OSM/bin/ccdb_server.bak
	tar zxf /OSM/bin/ccdb_server_DTS2023032104858.tgz -C /OSM/bin
	mv /OSM/bin/ccdb_server_DTS2023032104858 /OSM/bin/ccdb_server
	rm -f /OSM/bin/ccdb_server_DTS2023032104858.tgz
	chmod 550 /OSM/bin/ccdb_server
   
    daemon "/OSM/bin/ccdb_server" "/OSM/bin/cgroup_manage.sh -g ccdb"
    if [ $? -ne 0 ]; then
        OS_echo "hotpatch start ccdb_server fail by daemon in SPH052."
    fi
    return 
}
PATCH_END()
{
    return
}
PATCH_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
    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