由于history-server服务器会经常出现自己挂掉的情况,用python写了一个自动重启的脚本,放在系统里用crontab定时,再也不用担心任务挂了,服务器也挂掉了。
思路很简单,就是用ps指令检测进程,如果没有history-server,就把服务器拉起来。
import sys
import commands
import os
command = "ps -ef|grep spark-2.1-history-server/sbin/../conf/"
log = "-Dspark.history.fs.logDirectory=afs://tianqi.afs.baidu.com:9902/user/ubs-traffic-antispam/antispam/spark-history-log"
historyCommand = "sh /home/work/spark-2.1-history-server/sbin/start-history-server.sh"
ans = 0
result = os.popen(command)
res = result.read()
for line in res.splitlines():
if log in line:
ans =1
if ans is not 1:
ret = os.system(historyCommand)
sys.exit(0)
最后再crontab -e 写一个定时就好了。