This repository has been archived by the owner on Jan 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
msiotcd.py
executable file
·56 lines (45 loc) · 1.6 KB
/
msiotcd.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
50
51
52
53
54
55
56
#!/usr/bin/env python3
# ========================================================================
# msiotcd.py
#
# Description: Daemon to keep msiotc.py running.
#
# Author: Sam Yang, Jim Ing
# Date: 2020-02-21
# ========================================================================
import logging, subprocess, sys, time
from logging.handlers import RotatingFileHandler
import config as cfg
# ------------------------------------------------------------------------
# Initialization
# ------------------------------------------------------------------------
logId = 'msiotcd'
logFile = cfg.logsPath + '/' + logId + '.log'
logging.basicConfig(
handlers=[RotatingFileHandler(logFile, maxBytes=100000000, backupCount=50)], # 100 MB * 50 = 5 GB
format='[%(asctime)s.%(msecs)03d] %(levelname)s %(message)s',
level=logging.DEBUG,
datefmt='%Y-%m-%d %H:%M:%S')
# ------------------------------------------------------------------------
# Main
# ------------------------------------------------------------------------
try:
# Start the process first time
logging.info('Started')
process = subprocess.Popen(['./msiotc.py'])
while True:
# Check the state of the process
status = process.poll()
if status != None:
# Terminated, restart process
process = subprocess.Popen(['./msiotc.py']) # TODO
logging.info('Termination code: %d' % (status))
logging.info('Restarted')
else:
# Still running
time.sleep(1)
# Exit cleanly
except KeyboardInterrupt:
print("\n" + "Stopped")
finally:
sys.exit(0)