#!/bin/bash

source /OSM/script/os_load_base.sh
HP_NAME=DeviceManagerHotPatchSPH018_DTS2021042707FCVXP1H00.tgz
CONFLICTREBOOT_ROOT=/startup_disk/conf/conf_local/conflictReboot

function restartProcess()
{
    echo "start"
	# to kill daemon
	kill -9 `ps -wwef | grep startDeamonISM.sh | grep -v "grep" | awk '{print $2}'` 
	kill -9 `ps -wwef | grep startISM.sh | grep -v "grep" | awk '{print $2}'`
	if [ -f $CONFLICTREBOOT_ROOT/rebooting ]; then 
		rm -rf $CONFLICTREBOOT_ROOT/rebooting
	fi
	# to stop devicemanager
	sh /OSM/coffer_data/ISM/runtime/scripts/stopISM.sh
	setsid sh /ISM/startDeamonISM.sh &
	echo "end"
    return 0
}

function PATCH_START()
{
    return 
}
function PATCH_END()
{

    restartProcess
    return
}
function PATCH_ROLLSTART()
{
    return
}
function PATCH_ROLLEND()
{
	#删除补丁文件
	OS_echo "delete hpname."
	
	if [ -f /ISM/$HP_NAME ];then
		OS_echo "delete hpname111111."
		rm -rf /ISM/$HP_NAME
	fi
	OS_echo "delete hpname22222."
	# to kill daemon
	kill -9 `ps -wwef | grep startDeamonISM.sh | grep -v "grep" | awk '{print $2}'` 
	kill -9 `ps -wwef | grep startISM.sh | grep -v "grep" | awk '{print $2}'`
	if [ -f $CONFLICTREBOOT_ROOT/rebooting ]; then 
		rm -rf $CONFLICTREBOOT_ROOT/rebooting
	fi
	# to stop devicemanager
	sh /OSM/coffer_data/ISM/runtime/scripts/stopISM.sh
	setsid sh /ISM/startDeamonISM.sh &
	echo "end"
    return
}
#start：打补丁前需要执行的操作，脚本的执行时间点在替换文件前
#end：打补丁后需要执行的操作，脚本的执行时间点在替换文件后
#rollstart：回滚补丁时需要执行的操作，脚本的执行时间点在文件被恢复之前。
#rollend：回滚补丁时需要执行的操作，脚本的执行时间点在文件被恢复之后。
#PATCH_CLOSE_SWITCH:先读取性能统计开关的状态，将其值保存到switch中,并关闭性能统计开关
#PATCH_OPEN_SWITCH:如果用户之前是打开状态，将其开关打开
OS_echo "OMM_ALARM: command is ($1)."
L_CMD=$1
case $L_CMD in
        "start") 
                PATCH_START
                ;;
        "end") 
                PATCH_END
                ;;
        "rollstart") 
                PATCH_ROLLSTART
                ;;
        "rollend") 
                PATCH_ROLLEND
                ;;
        *)
                OS_echo "unsupported option."
esac
exit 0