#!/bin/sh
source /OSM/script/os_load_base.sh
PATCH_START()
{
    daemon -s /OSM/bin/ccdb_server
    if [ $? -ne 0 ]; then
        OS_echo "hotpatch stop ccdb_server fail by daemon in sph105."
    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 sph105."
            return 
        fi
    }; 
    done
    return 
}
PATCH_END()
{
    return
}
PATCH_ROLLBACK()
{
    chmod 755 /OSM/bin/ccdb_server
    chmod 755 /usr/local/lib/libcls_mon_client.so
    chmod 550 /OSM/script/ccdb.sh
    chmod 550 /OSM/script/ccdb_mdadm_admin.sh
    chmod 550 /OSM/script/ccdb_check_system_disk_io_delay.sh
    
    #回滚进程SO
    mv /usr/local/lib/libcls_mon_client.so.bak /usr/local/lib/libcls_mon_client.so
    chmod 755 /usr/local/lib/libcls_mon_client.so
    
    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 sph105."
    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