-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathsentinel.py
49 lines (37 loc) · 1008 Bytes
/
sentinel.py
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
# encoding=utf-8
"""哨兵进程
错误码说明
错误码 | 说明
------| -------
0 | 正常退出
1 | 异常退出,一般是程序错误
https://blog.csdn.net/halfclear/article/details/72783900
"""
import sys
import os
import time
def get_current_time(format='%Y-%m-%d %H:%M:%S'):
return time.strftime(format)
def print_log(*args):
print(get_current_time(), *args)
def has_xnote_reboot_file():
return os.path.exists("xnote-reboot.txt")
def main():
args = sys.argv[1:]
args.insert(0, sys.executable)
cmd = " ".join(args)
print_log("command:", cmd)
while True:
# exit_code = subprocess.call(args, shell = True)
exit_code = os.system(cmd)
print_log("exit_code:", exit_code)
# Mac返回 52480
# 有可能是框架原因导致重启失败,所以这里再使用reboot文件来检查下
if exit_code in (205, 52480) or has_xnote_reboot_file():
print_log("restart ...")
print_log("-" * 50)
print_log("-" * 50)
else:
return
if __name__ == '__main__':
main()