标签:拷贝 run monitor openssl chm ack 最新 监控 chmod
#Version=V1.1_20200706
#!/bin/sh
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/mnt/APP/Libraries/GeneralLibs/xdja/
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/mnt/APP/Libraries/GeneralLibs/libevent
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/mnt/APP/Libraries/GeneralLibs/mqtt
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/mnt/APP/Libraries/GeneralLibs/libsqlite3
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/mnt/APP/Libraries/GeneralLibs/openssl
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/mnt/APP/Libraries/MsgAdapterLibs
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/mnt/APP/Libraries/RSULibs
TryTime_mama=0 #重启次数记录
TryTime_ChildV2X=0 #重启次数记录
TryTime_ChildGNSS=0 #重启次数记录
TryTime_ChildLed=0 #重启次数记录
TryTime_ChildSupervision=0 #重启次数记录
psMonitCount_ChildV2X=0 #ps监控进程次数
psMonitCount_ChildGNSS=0 #ps监控进程次数
psMonitCount_ChildLed=0 #ps监控进程次数
psMonitCount_mama=0 #ps监控进程次数
psMonitCount_ChildSupervision=0 #ps监控进程次数
monitor_app_mama="mama"
monitor_app_ChildV2X="ChildV2X"
monitor_app_ChildGNSS="ChildGNSS"
#monitor_app_ChildGNSS="v2xrsu"
monitor_app_ChildLed="ChildLed"
monitor_app_ChildSupervision="ChildSupervision"
#monitor_app="V2X_APP_LTEV_TEST1" #需要监听的APP
#monitor_app1="V2X_APP_LTEV_TEST2" #需要监听的APP
restartFlag_mama=0 #重启标志
restartFlag_ChildV2X=0 #重启标志
restartFlag_ChildGNSS=0 #重启标志
restartFlag_ChildLed=0 #重启标志
restartFlag_ChildSupervision=0 #重启标志
SysTime=`date "+%Y-%m-%d %H:%M:%S"` #获取系统时间
timeStamp=`date -d "$SysTime" +%s` #获取UTC时间戳
timeStamp=$(expr $timeStamp + 3600) #程序初次启动比较时间 当前时间加一小时
l_timeStamp=0
App_path="/mnt/APP/V2XAPP/" #APP具体路径,用于重启使用
App_Old_path="/mnt/APP/V2XAPP_BK/" #上个版本程序保存路径
Errorlog_Path="/mnt/RWD/RollbackLog/rollError.log" #错误日志路径
Max_Count=0+1+1 #最大重启次数,到达后还未启动成功则进行回滚
Re_intervarl=2 #检测时间间隔
wait_time=2 #启动APP后,等待APP启动的额外等待时间,实际等待时间为wait_time+Re_intervarl
#判断是否存在log文件不存在则创建
if [ ! -f "$Errorlog_Path" ];then
touch $Errorlog_Path
fi
#判断程序正常运行60分钟 将此程序复制到备份目录下
FunStaProCopy()
{
SysTime=`date "+%Y-%m-%d %H:%M:%S"`
l_timeStamp=`date -d "$SysTime" +%s`
if [ $l_timeStamp -gt $timeStamp ];then #到达一小时时间
timeStamp=`date -d "$SysTime" +%s`
timeStamp=$(expr $timeStamp + 3600)
if [ $restartFlag_mama = 0 ];then #判断mama进程是否有重启行为
SysHtime=$l_SysHtime
cd $Apppath
cp $Apppath$monitor_app_mama $App_Old_path #将稳定程序拷贝到回滚目录
restartFlag_mama=0
#echo "save backup program mama $SysTime" >>$Errorlog_Path
else
restartFlag_mama=0
echo " Time is up flag error clear flag mama $SysTime" >>$Errorlog_Path
fi
if [ $restartFlag_ChildV2X = 0 ];then #判断ChildV2X进程是否有重启行为
SysHtime=$l_SysHtime
cd $Apppath
cp $Apppath$monitor_app_ChildV2X $App_Old_path #将稳定程序拷贝到回滚目录
restartFlag_ChildV2X=0
#echo "save backup program ChildV2X $SysTime" >>$Errorlog_Path
else
restartFlag_ChildV2X=0
echo " Time is up flag error clear flag ChildV2X $SysTime" >>$Errorlog_Path
fi
if [ $restartFlag_ChildGNSS = 0 ];then #判断ChildGNSS进程是否有重启行为
SysHtime=$l_SysHtime
cd $Apppath
cp $Apppath$monitor_app_ChildGNSS $App_Old_path #将稳定程序拷贝到回滚目录
restartFlag_ChildGNSS=0
#echo "save backup program ChildGNSS $SysTime" >>$Errorlog_Path
else
restartFlag_ChildGNSS=0
echo " Time is up flag error clear flag ChildGNSS $SysTime" >>$Errorlog_Path
fi
if [ $restartFlag_ChildLed = 0 ];then #判断ChildLed进程是否有重启行为
SysHtime=$l_SysHtime
cd $Apppath
cp $Apppath$monitor_app_ChildLed $App_Old_path #将稳定程序拷贝到回滚目录
restartFlag_ChildLed=0
#echo "save backup program ChildLed $SysTime" >>$Errorlog_Path
else
restartFlag_ChildLed=0
echo " Time is up flag error clear flag ChildLed $SysTime" >>$Errorlog_Path
fi
if [ $restartFlag_ChildSupervision = 0 ];then #判断ChildSupervision进程是否有重启行为
SysHtime=$l_SysHtime
cd $Apppath
cp $Apppath$monitor_app_ChildSupervision? $App_Old_path #将稳定程序拷贝到回滚目录
restartFlag_ChildSupervision=0
#echo "save backup program ChildSupervision $SysTime" >>$Errorlog_Path
else
restartFlag_ChildSupervision=0
echo " Time is up flag error clear flag ChildSupervision $SysTime" >>$Errorlog_Path
fi
fi
}
FunRollProcess_mama()
{
AppName=$1 #外部传入参数 进程名
Apppath=$2 #外部传入参数 进程运行路径
AppNameOld=$3 #外部传入参数 备份目录文件名
pid_TimeSys=$(ps |grep $AppName|grep -v "grep"|awk ‘{print $1}‘) #获取进程ID
if [ "$pid_TimeSys" = "" ];then #判断进程是否正在运行 如未运行进行次数加一
psMonitCount_mama=`expr $psMonitCount_mama+1`
else
psMonitCount_mama=0
TryTime_mama=0
fi
if [ "$psMonitCount_mama" = "$Max_Count" ];then #通过两次判断进程运行状态 判断当前进程是否运行
pid_TimeSyskill=$(ps |grep ChildLed|grep -v "grep"|awk ‘{print $1}‘) #获取进程ID
if [ "$pid_TimeSyskill" = "" ];then #判断进程是否正在运行 如未运行进行次数加一
echo "dont find ChildLed">>$Errorlog_Path
else
echo "kill the Led $pid_TimeSyskill">>$Errorlog_Path
kill $pid_TimeSyskill
fi
pid_TimeSyskill=$(ps |grep ChildGNSS|grep -v "grep"|awk ‘{print $1}‘) #获取进程ID
if [ "$pid_TimeSyskill" = "" ];then #判断进程是否正在运行 如未运行进行次数加一
echo "dont find ChildGNSS">>$Errorlog_Path
else
echo "kill the GNSS $pid_TimeSyskill">>$Errorlog_Path
kill $pid_TimeSyskill
fi
pid_TimeSyskill=$(ps |grep ChildV2X|grep -v "grep"|awk ‘{print $1}‘) #获取进程ID
if [ "$pid_TimeSyskill" = "" ];then #判断进程是否正在运行 如未运行进行次数加一
echo "dont find ChildV2X">>$Errorlog_Path
else
echo "kill the V2X $pid_TimeSyskill">>$Errorlog_Path
kill $pid_TimeSyskill
fi
pid_TimeSyskill=$(ps |grep ChildSupervisio|grep -v "grep"|awk ‘{print $1}‘) #获取进程ID
if [ "$pid_TimeSyskill" = "" ];then #判断进程是否正在运行 如未运行进行次数加一
echo "dont find ChildSupervisio">>$Errorlog_Path
else
echo "kill the Supervisio $pid_TimeSyskill">>$Errorlog_Path
kill $pid_TimeSyskill
fi
psMonitCount_mama=0
if [ "$TryTime_mama" = "$Max_Count" ];then #重启次数是否达到上限
cd $App_Old_path
cp $AppOldPath$AppNameOld $Apppath 2>>$Errorlog_Path #old程序从回滚目录下复制到正常目录
cd $Apppath
mv $AppNameOld $AppName
chmod 777 $AppName
./$AppName & 2>>$Errorlog_Path
TryTime_mama=0
SysTime=`date "+%Y-%m-%d %H:%M:%S"`
echo "Start Old Version $AppName $SysTime...." >>$Errorlog_Path
sleep $wait_time
else
cd $Apppath #没有达到重启上限值,继续重启最新程序
./$AppName &2>>$Errorlog_Path
TryTime_mama=`expr $TryTime_mama+1`
restartFlag_mama=1
SysTime=`date "+%Y-%m-%d %H:%M:%S"`
echo "Start $AppName $SysTime...." >>$Errorlog_Path
fi
fi
}
FunRollProcess_ChildV2X()
{
AppName=$1 #外部传入参数 进程名
Apppath=$2 #外部传入参数 进程运行路径
AppNameOld=$3 #外部传入参数 备份目录文件名
pid_TimeSys=$(ps|grep $AppName|grep -v "grep"|awk ‘{print $1}‘) #获取进程ID
if [ "$pid_TimeSys" = "" ];then
psMonitCount_ChildV2X=`expr $psMonitCount_ChildV2X+1`
else
TryTime_ChildV2X=0
fi
if [ "$psMonitCount_ChildV2X" = "$Max_Count" ];then #判断当前进程是否运行
psMonitCount_ChildV2X=0
if [ "$TryTime_ChildV2X" = "$Max_Count" ];then #重启次数是否达到上限
cd $App_Old_path
cp $AppOldPath$AppNameOld $Apppath 2>>$Errorlog_Path #old程序从回滚目录下复制到正常目录
cd $Apppath
mv $AppNameOld $AppName
chmod 777 $AppName
./$AppName & 2>>$Errorlog_Path
TryTime_ChildV2X=0
SysTime=`date "+%Y-%m-%d %H:%M:%S"`
echo "Start Old Version $AppName $SysTime...." >>$Errorlog_Path
sleep $wait_time
else
cd $Apppath #没有达到重启上限值,继续重启最新程序
echo "appname $AppName"
./$AppName &2>>$Errorlog_Path
TryTime_ChildV2X=`expr $TryTime_ChildV2X+1`
restartFlag_ChildV2X=1
SysTime=`date "+%Y-%m-%d %H:%M:%S"`
echo "Start $AppName $SysTime...." >>$Errorlog_Path
fi
fi
}
FunRollProcess_ChildGNSS()
{
AppName=$1 #外部传入参数 进程名
Apppath=$2 #外部传入参数 进程运行路径
AppNameOld=$3 #外部传入参数 备份目录文件名
pid_TimeSys=$(ps|grep $AppName|grep -v "grep"|awk ‘{print $1}‘) #获取进程ID
if [ "$pid_TimeSys" = "" ];then
psMonitCount_ChildGNSS=`expr $psMonitCount_ChildGNSS+1`
else
TryTime_ChildGNSS=0
fi
if [ "$psMonitCount_ChildGNSS" = "$Max_Count" ];then #判断当前进程是否运行
psMonitCount_ChildGNSS=0
if [ "$TryTime_ChildGNSS" = "$Max_Count" ];then #重启次数是否达到上限
cd $App_Old_path
cp $AppOldPath$AppNameOld $Apppath 2>>$Errorlog_Path #old程序从回滚目录下复制到正常目录
cd $Apppath
mv $AppNameOld $AppName
chmod 777 $AppName
./$AppName & 2>>$Errorlog_Path
TryTime_ChildGNSS=0
SysTime=`date "+%Y-%m-%d %H:%M:%S"`
echo "Start Old Version $AppName $SysTime...." >>$Errorlog_Path
sleep $wait_time
else
cd $Apppath #没有达到重启上限值,继续重启最新程序
echo "appname $AppName"
./$AppName &2>>$Errorlog_Path
TryTime_ChildGNSS=`expr $TryTime_ChildGNSS+1`
restartFlag_ChildGNSS=1
SysTime=`date "+%Y-%m-%d %H:%M:%S"`
echo "Start $AppName $SysTime...." >>$Errorlog_Path
fi
fi
}
FunRollProcess_ChildLed()
{
AppName=$1 #外部传入参数 进程名
Apppath=$2 #外部传入参数 进程运行路径
AppNameOld=$3 #外部传入参数 备份目录文件名
pid_TimeSys=$(ps|grep $AppName|grep -v "grep"|awk ‘{print $1}‘) #获取进程ID
if [ "$pid_TimeSys" = "" ];then
psMonitCount_ChildLed=`expr $psMonitCount_ChildLed+1`
else
TryTime_ChildLed=0
fi
if [ "$psMonitCount_ChildLed" = "$Max_Count" ];then #判断当前进程是否运行
psMonitCount_ChildLed=0
if [ "$TryTime_ChildLed" = "$Max_Count" ];then #重启次数是否达到上限
cd $App_Old_path
cp $AppOldPath$AppNameOld $Apppath 2>>$Errorlog_Path #old程序从回滚目录下复制到正常目录
cd $Apppath
mv $AppNameOld $AppName
chmod 777 $AppName
./$AppName & 2>>$Errorlog_Path
TryTime_ChildLed=0
SysTime=`date "+%Y-%m-%d %H:%M:%S"`
echo "Start Old Version $AppName $SysTime...." >>$Errorlog_Path
sleep $wait_time
else
cd $Apppath #没有达到重启上限值,继续重启最新程序
echo "appname $AppName"
./$AppName &2>>$Errorlog_Path
TryTime_ChildLed=`expr $TryTime_ChildLed+1`
restartFlag_ChildLed=1
SysTime=`date "+%Y-%m-%d %H:%M:%S"`
echo "Start $AppName $SysTime...." >>$Errorlog_Path
fi
fi
}
FunRollProcess_ChildSupervision()
{
AppName=$1 #外部传入参数 进程名
Apppath=$2 #外部传入参数 进程运行路径
AppNameOld=$3 #外部传入参数 备份目录文件名
pid_TimeSys=$(ps|grep ChildSupervisio |grep -v "grep"|awk ‘{print $1}‘) #获取进程ID
if [ "$pid_TimeSys" = "" ];then
psMonitCount_ChildSupervision=`expr $psMonitCount_ChildSupervision+1`
else
TryTime_ChildSupervision=0
fi
if [ "$psMonitCount_ChildSupervision" = "$Max_Count" ];then #判断当前进程是否运行
psMonitCount_ChildSupervision=0
if [ "$TryTime_ChildSupervision" = "$Max_Count" ];then #重启次数是否达到上限
cd $App_Old_path
cp $AppOldPath$AppNameOld $Apppath 2>>$Errorlog_Path #old程序从回滚目录下复制到正常目录
cd $Apppath
mv $AppNameOld $AppName
chmod 777 $AppName
./$AppName? & 2>>$Errorlog_Path
TryTime_ChildSupervision=0
SysTime=`date "+%Y-%m-%d %H:%M:%S"`
echo "Start Old Version $AppName $SysTime...." >>$Errorlog_Path
sleep $wait_time
else
cd $Apppath #没有达到重启上限值,继续重启最新程序
echo "appname $AppName"
./$AppName &2>>$Errorlog_Path
TryTime_ChildSupervision=`expr $TryTime_ChildSupervision+1`
restartFlag_ChildSupervision=1
SysTime=`date "+%Y-%m-%d %H:%M:%S"`
echo "Start $AppName $SysTime...." >>$Errorlog_Path
fi
fi
}
while :
do
#监控进程函数
FunRollProcess_ChildGNSS $monitor_app_ChildGNSS $App_path $monitor_app_ChildGNSS
FunRollProcess_ChildLed $monitor_app_ChildLed $App_path $monitor_app_ChildLed
FunRollProcess_ChildSupervision $monitor_app_ChildSupervision $App_path $monitor_app_ChildSupervision
FunRollProcess_ChildV2X $monitor_app_ChildV2X $App_path $monitor_app_ChildV2X
FunRollProcess_mama $monitor_app_mama $App_path $monitor_app_mama
#进程备份程序
FunStaProCopy
#echo "APPRollback is running $SysTime...." >>$Errorlog_Path
sleep $Re_intervarl
done
标签:拷贝 run monitor openssl chm ack 最新 监控 chmod
原文地址:https://www.cnblogs.com/d-h-/p/14291142.html