-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·47 lines (40 loc) · 1.24 KB
/
main.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
#!/usr/bin/env python3
# This is tha main core of multi launcher script
from concurrent.futures import thread
from time import sleep
import core.listeners as listeners
import logging
import logging.handlers
import os
import sys
import config.common_conf as settings
def init_logger() -> None:
handler = logging.StreamHandler(sys.stdout)
if settings.LOG_ON_FILE:
handler = logging.handlers.BaseRotatingHandler(os.environ.get("LOGFILE", settings.LOGFILE))
formatter = logging.Formatter(settings.LOGGING_FORMATTER)
handler.setFormatter(formatter)
root = logging.getLogger()
root.setLevel(os.environ.get("LOGLEVEL", settings.LOG_LEVEL))
root.addHandler(handler)
def main():
global listener
listener = listeners.init_listener()
listener.run()
continue_process = True
while continue_process:
try:
init_logger()
exit(main())
except KeyboardInterrupt as e:
logging.info("Exiting..")
listener.close()
continue_process = False
except Exception:
logging.exception("Exception in main()")
if settings.ON_ERROR== 'retry':
sleep(2000)
logging.info("Trying to run service again..")
continue
else:
exit(1)