diagnose.py
2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import shlex
import subprocess
import re
import time
import os
import threading
import commands
#config
check_mediaserver_period_seconds = 900
if_failed_next_check_period_seconds = 120
mediaserver_last_status = 1
def check_mediaserver():
res = False
global mediaserver_last_status
rtspserver_cmd_str = './rtsp_decode_encode_test_app --url0=./jiaotong4.264 --serverport=18554'
rtspserver_cmd = shlex.split(rtspserver_cmd_str)
play_cmd_str = 'python try_play.py'
p1 = subprocess.Popen(rtspserver_cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
time.sleep(5)
(status, output) = commands.getstatusoutput(play_cmd_str)
if(status == 0):
res = True
else:
res = False
os.system('kill -9 `ps aux|grep rtsp_decode_encode_test_app| grep -v grep | awk \'{print $2}\'`')
p1.wait()
# os.system('kill -9 {}'.format(p1.pid))
return res
if __name__ == '__main__':
last_check_media = time.time();
try_count = 0;
checkperiod = check_mediaserver_period_seconds
while True:
now = time.time();
if(now-last_check_media> checkperiod):
last_check_media = now;
if(check_mediaserver()):
print('mediaserver is working');
checkperiod = check_mediaserver_period_seconds
try_count =0
mediaserver_last_status = 1
else:
try_count=try_count+1
checkperiod = if_failed_next_check_period_seconds
if(try_count >= 3):
print('maybe mediaserver has some problem, restart!')
os.system('kill -9 `ps aux|grep MediaServer| grep -v grep | awk \'{print $2}\'`')
checkperiod = check_mediaserver_period_seconds
try_count =0
mediaserver_last_status = 0
else:
print('dianose working tick, now-last_check_media:{}, try_count:{}, mediaserver_last_status:{}'.format(now-last_check_media, try_count, mediaserver_last_status))
time.sleep(1)