forked from clowwindy/PyWebGet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pywebget.py
executable file
·74 lines (59 loc) · 1.65 KB
/
pywebget.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
#!/usr/bin/env python
import os, sys
if os.name == 'posix':
reload(sys)
sys.setdefaultencoding('utf-8')
import threading
import signal
from core.controller import Controller
import core.utils
import core.version
import core.param_parser
from core import daemon
print core.version.DESCRIPTION
args = core.param_parser.parse_args()
if args.verbose:
import core.setting
core.setting.DEBUG = True
core.utils.init_log()
if os.name == 'posix':
if args.background:
daemon.start(args.pid_file, args.user)
if args.stop:
daemon.stop(args.pid_file)
if args.restart:
daemon.restart(args.pid_file, args.user)
core.setting.check_paths()
def sig_handler(signum, frame):
from core.utils import log
log("exiting")
global controller
controller.stop()
webui.app.stop()
log("exited")
core.utils.close_log()
sys.exit(0)
if os.name == 'posix':
signal.signal(signal.SIGQUIT, sig_handler)
signal.signal(signal.SIGTERM, sig_handler)
signal.signal(signal.SIGINT, sig_handler)
signal.signal(signal.SIGUSR1, sig_handler)
signal.signal(signal.SIGUSR2, sig_handler)
elif os.name == 'nt':
signal.signal(signal.SIGABRT, sig_handler)
signal.signal(signal.SIGTERM, sig_handler)
signal.signal(signal.SIGINT, sig_handler)
controller = Controller()
controller.init()
controller_thread = threading.Thread(target=controller.run, name='controller')
controller_thread.setDaemon(True)
controller_thread.start()
import webui.app
webui.app.set_controller(controller)
core.utils.log("started")
try:
webui.app.run()
finally:
# stop controller if webui is stopped
# controller.stop()
pass