-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
39 lines (30 loc) · 1007 Bytes
/
run.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
# coding=utf-8
import logging
import sys
import system.config as config
import system.util as util
from twisted.internet import reactor
from system.core import CoreFactory
logging.basicConfig(format="%(asctime)s | %(name)8s | %(levelname)8s | %(message)s", datefmt="%d %b %Y - %H:%M:%S",
level=(logging.DEBUG if "--debug" in sys.argv else logging.INFO))
logger = logging.getLogger("Init")
logger.info("Starting up...")
conf = config.conf()
networking = conf.get("networking")
if not networking:
logger.critical("Networking configuration is unavailable. The program will now terminate.")
exit(1)
factory = CoreFactory()
try:
reactor.listenTCP(networking["port"], factory)
logger.info("Now listening on port %s." % networking["port"])
reactor.run()
except Exception as e:
logger.error("Error starting up: %s" % e)
util.output_exception(logger)
finally:
try:
logger.info("Shutting down..")
factory.cleanup()
except:
pass