-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun_web_server.py
More file actions
71 lines (62 loc) · 2.08 KB
/
run_web_server.py
File metadata and controls
71 lines (62 loc) · 2.08 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
66
67
68
69
70
71
#!/usr/bin/env python3
import sys
import logging.config
import logging
from daemon.daemon3x import daemon
LOG_PATH = "tmp/web.log"
def log_exception(type, value, tb):
logging.exception("Uncaught exception: {0}".format(str(value)))
class ExampleServerDaemon(daemon):
def run(self):
try:
logging.config.dictConfig({
"version": 1,
"disable_existing_loggers": "False",
"formatters": {
"standard": {
"format": "%(asctime)s [%(levelname)s] %(name)s: %(message)s"
}
},
"handlers": {
"default": {
"level": "DEBUG",
"class": "logging.FileHandler",
"filename": LOG_PATH,
"formatter": "standard"
}
},
"loggers": {
"": {
"handlers": ["default"],
"level": "DEBUG",
"propagate": "True"
}
}
})
logger = logging.getLogger(__name__)
logger.info("Logging initialized. Creating application...")
sys.excepthook = log_exception
from web_ui import app
app.run(host='0.0.0.0')
except Exception as e:
with open('/tmp/error_file.txt', 'w') as f:
import traceback
f.write(traceback.format_exc())
f.write('\n')
f.write(e)
if __name__ == '__main__':
my_daemon = ExampleServerDaemon('/tmp/example_d.pid')
if len(sys.argv) == 2:
if 'start' == sys.argv[1]:
my_daemon.start()
elif 'stop' == sys.argv[1]:
my_daemon.stop()
elif 'restart' == sys.argv[1]:
my_daemon.restart()
else:
print("Unknown command")
sys.exit(2)
sys.exit(0)
else:
print("usage: %s start|stop|restart" % sys.argv[0])
sys.exit(2)