-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathweb-server-run.py
81 lines (66 loc) · 2.13 KB
/
web-server-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
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
72
73
74
75
76
77
78
79
80
# -- coding: utf-8 --
import os
import sys
import signal
import time
import subprocess
import node
from tornado import ioloop
from tornado.options import options
from web.common.init import *
from web.common.loader import load_url_handlers
from web.logger import logger
from web.settings import *
class iApplication(web.Application):
def __init__(self):
settings = {
'static': os.path.join(os.path.dirname(__file__), "web/static"),
'template_path': os.path.join(os.path.dirname(__file__), "web/templates"),
}
handlers = [
(r"^/$", MainHandler),
(r"^/signin", MainHandler),
(r"^/static/(.*)", web.StaticFileHandler, dict(path=settings['static'])),
]
apps = load_url_handlers()
handlers.extend(apps)
# custom http error handler
handlers.append((r"/.*", PageNotFound))
web.Application.__init__(self, handlers, **settings)
class MainHandler(WiseHandler):
def get(self):
self.render("pages-signin.html")
class Watcher:
def __init__(self):
self.child = os.fork()
if self.child == 0:
return
else:
self.watch()
def watch(self):
try:
os.wait()
except (KeyboardInterrupt, SystemExit):
# I put the capital B in KeyBoardInterrupt so I can
# tell when the Watcher gets the SIGINT
print "Server exit at %s." % time.ctime()
self.kill()
sys.exit()
def kill(self):
try:
os.kill(self.child, signal.SIGKILL)
except OSError:
pass
if __name__ == '__main__':
port = SERVER_API_PORT
options.parse_command_line()
# subprocess.Popen('ps -ef|grep celery|grep -v grep|cut -c 9-15|xargs kill -9', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
node.main()
app = iApplication()
app.listen(port, xheaders=True)
logger.info("Start server on %d OK." % port)
try:
ioloop = ioloop.IOLoop.instance()
ioloop.start()
except (KeyboardInterrupt, SystemExit):
ioloop.close()