Skip to main content

自动重启sz_driver脚本

#!/bin/bash

#########################################################################
# 使用方法:
# chmod +x /home/shuncom/services/scripts/sz_driver_mon.sh
# 00 03 * * 05 /bin/bash /home/shuncom/services/scripts/sz_driver_mon.sh
#########################################################################

sleep 30

set -i
source ~/.bashrc

# 当前时间
current_time="`date +%Y%m%d%H%M%S`"

# sz_driver的pid
sz_driver_pid="`pidof sz_driver`"

# 日志文件路径
sz_driver_mon_log="/home/shuncom/services/log/sz_server/${current_time}-sz_driver-mon.log"

# 判断sz_driver是否启动,没有启动时退出脚本并写入日志
if [ -z "${sz_driver_pid}" ]; then
  echo -e "${current_time} sz_driver not start" >> ${sz_driver_mon_log}
  exit 1
fi

# 重启驱动
/bin/sh /home/shuncom/services/scripts/driver stop  >/dev/null 2>&1
sleep 10
/bin/sh /home/shuncom/services/scripts/driver start >/dev/null 2>&1
sleep 10
/bin/sh /home/shuncom/services/scripts/driver status | grep 'is running' >/dev/null 2>&1
# 如果重启失败,退出脚本,写入日志
if [ $? -ne 0 ]; then
  echo -e "${current_time} sz_driver restart failed" >> ${sz_driver_mon_log}
  exit 1
fi
# 如果重启成功,退出脚本,写入日志
echo -e "${current_time} sz_driver restart success" >> ${sz_driver_mon_log}
exit 1