forked from aploium/zmirror
-
Notifications
You must be signed in to change notification settings - Fork 1
/
wsgi.py
73 lines (59 loc) · 3.08 KB
/
wsgi.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
#!/usr/bin/env python3
# coding=utf-8
import sys
import os
sys.path.insert(0, os.path.dirname(__file__))
if os.path.dirname(__file__) != '':
os.chdir(os.path.dirname(__file__))
from zmirror.zmirror import app as application
__author__ = 'Aploium <i@z.codes>'
def main():
from zmirror.zmirror import warnprint, errprint, infoprint
from zmirror import cfg
if cfg.my_host_port is None:
cfg.my_host_port = 80
infoprint("zmirror is running! Listening: {}:{} ThisDomain: {} Target: {}".format(
cfg.built_in_server_host, cfg.my_host_port, cfg.my_host_name, cfg.target_domain
))
warnprint("You may directly running zmirror, which is NOT recommend for PRODUCTION environment.\n"
"Please deploy it using Apache,You can find a deploy tutorial here:\n"
"https://github.com/aploium/zmirror/wiki/%E9%83%A8%E7%BD%B2%E6%94%AF%E6%8C%81HTTPS%E5%92%8CHTTP2.0%E7%9A%84%E9%95%9C%E5%83%8F")
if cfg.built_in_server_host == '127.0.0.1':
warnprint(
"Only listening to 127.0.0.1, which means you CANNOT access this zmirror "
"instance from Internet, if you really want to access this instance directly from Internet, "
"please append this line to the `config.py` \n----------\n"
"built_in_server_host = '0.0.0.0'\n"
"----------"
)
try:
application.run(
port=cfg.my_host_port,
# 如果配置文件中开启了多进程, 那么就关掉多线程, 否则默认启用多线程
threaded="processes" not in cfg.built_in_server_extra_params,
# 如果你想直接用本程序给外网访问, 请在 config.py 末尾加两行配置
# !!警告!! 无论如何都不要修改 config_default.py, 否则程序将无法通过 git pull 来升级
#
# built_in_server_host='0.0.0.0'
# built_in_server_debug=False
#
# ps:字母在行首, 行首不要有空格
# !!警告!! 无论如何都不要修改本文件, 否则程序将无法通过 git pull 来升级
debug=cfg.built_in_server_debug, # 默认是开启debug模式的
# 默认只允许本机访问, 如果你希望让外网访问, 请根据上面的注释修改配置文件
host=cfg.built_in_server_host,
**cfg.built_in_server_extra_params # extra params
)
except OSError as e:
if e.errno in (98, 10013): # Address already in use, 98 for linux, 10013 for win
errprint("Port {port} was occupied by other program, please close it.\n"
"You can see which process is using your port by the following command:\n"
" Linux: netstat -apn |grep \":{port}\"\n"
" Windows: netstat -ano |find \":{port}\"\n\n"
"Or change zmirror\'s port: change(add, if not exist) the `my_host_port` setting in `config.py`\n"
"eg: my_host_port=81".format(port=cfg.my_host_port))
exit()
else:
raise
if __name__ == '__main__':
main()