diff --git a/app.py b/app.py index 3b67766356588f915692c2e4a54922b6d95f791a..80e8c73dfa2c8ee75dcc2f0483c9b9b161fcedfe 100644 --- a/app.py +++ b/app.py @@ -9,7 +9,6 @@ import js2py from flask_sqlalchemy import SQLAlchemy from flask_migrate import Migrate import config -# import settings import warnings warnings.filterwarnings('ignore') @@ -22,25 +21,36 @@ from utils.web import * import sys import codecs from classes.cms import CMS,logger +from models import * import json sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach()) -app = Flask(__name__,static_folder='static',static_url_path='/static') - -# app.config["JSON_AS_ASCII"] = False # jsonify返回的中文正常显示 -app.config.from_object(config) # 单独的配置文件里写了,这里就不用弄json中文显示了 -# new_conf = get_conf(settings) -# print(new_conf) -print('自定义播放解析地址:',app.config.get('PLAY_URL')) -print('当前操作系统',sys.platform) -app.logger.name="drLogger" + +def create_flask_app(config): + app = Flask(__name__, static_folder='static', static_url_path='/static') + # app.config["JSON_AS_ASCII"] = False # jsonify返回的中文正常显示 + app.config.from_object(config) # 单独的配置文件里写了,这里就不用弄json中文显示了 + # new_conf = get_conf(settings) + # print(new_conf) + print('自定义播放解析地址:', app.config.get('PLAY_URL')) + print('当前操作系统', sys.platform) + app.logger.name = "drLogger" + rule_list = getRuleLists() + logger.info(rule_list) + logger.info(f'局域网: {getHost(1, 5705)}/index\n本地: {getHost(0, 5705)}/index') + return app + +app = create_flask_app(config) + db = SQLAlchemy(app) migrate = Migrate(app, db) -rule_list = getRuleLists() -logger.info(rule_list) -logger.info(f'局域网: {getHost(1, 5705)}/index\n本地: {getHost(0, 5705)}/index') -from models import * -from gevent.pywsgi import WSGIServer +now_python_ver = ".".join([str(i) for i in sys.version_info[:3]]) +if sys.version_info < (3,9): + from gevent.pywsgi import WSGIServer + print(f'当前python版本{now_python_ver}为3.9.0及以下,支持gevent') +else: + print(f'当前python版本{now_python_ver}为3.9.0及以上,不支持gevent') + # from geventwebsocket.handler import WebSocketHandler RuleClass = rule_classes.init(db) @@ -80,7 +90,7 @@ def forbidden(): # put application's code here @app.route('/index') def index(): # put application's code here # logger.info("进入了首页") - sup_port = app.config.get('SUP_PORT',9001) + sup_port = app.config.get('SUP_PORT', 9001) manager0 = ':'.join(getHost(0).split(':')[0:2]) + f':{sup_port}' manager1 = ':'.join(getHost(1).split(':')[0:2]) + f':{sup_port}' manager2 = ':'.join(getHost(2).split(':')[0:2]) + f':{sup_port}' @@ -506,8 +516,12 @@ def database(): if __name__ == '__main__': # app.run(host="0.0.0.0", port=5705) # app.run(debug=True, host='0.0.0.0', port=5705) - # server = WSGIServer(('0.0.0.0', 5705), app, handler_class=WebSocketHandler,log=app.logger) - server = WSGIServer(('0.0.0.0', 5705), app,log=logger) - # server = WSGIServer(('0.0.0.0', 5705), app, handler_class=WebSocketHandler,log=None) - server.serve_forever() - # WSGIServer(('0.0.0.0', 5705), app,log=None).serve_forever() \ No newline at end of file + http_port = int(app.config.get('HTTP_PORT', 5705)) + http_host = app.config.get('HTTP_HOST', '0.0.0.0') + if sys.version_info < (3, 9): + # server = WSGIServer(('0.0.0.0', 5705), app, handler_class=WebSocketHandler,log=app.logger) + # server = WSGIServer(('0.0.0.0', 5705), app, handler_class=WebSocketHandler,log=None) + server = WSGIServer((http_host, http_port), app,log=logger) + server.serve_forever() + else: + app.run(debug=True, host=http_host, port=http_port) \ No newline at end of file diff --git a/app.sh b/app.sh index 720f024f4668c8b92f6e6965db16cab85dd9efad..5039b612b3300ba315fa555fd6414822b878ef47 100644 --- a/app.sh +++ b/app.sh @@ -1,2 +1,32 @@ +#!/bin/bash kill -9 $(cat supervisord.pid) # 杀掉进程 -supervisord -c manager.conf \ No newline at end of file +msg='flask或0 ubuntu下自动识别gevent或普通启动flask\nsflask或1 ubuntu下gunicorn启动flask\ntermux或2 termux下自动识别gevent或普通启动flask\nstermux或3 termux下gunicorn启动flask\n' +case "$1" in + flask) + supervisord -c ./super/flask.conf + ;; + 0) + supervisord -c ./super/flask.conf + ;; + sflask) + supervisord -c ./super/sflask.conf + ;; + 1) + supervisord -c ./super/sflask.conf + ;; + termux) + supervisord -c ./super/termux.conf + ;; + 2) + supervisord -c ./super/termux.conf + ;; + stermux) + supervisord -c ./super/stermux.conf + ;; + 3) + supervisord -c ./super/stermux.conf + ;; + *) + echo -e $msg + ;; +esac \ No newline at end of file diff --git a/commands.txt b/commands.txt index d20de45f10744b23434ddcb5cbfb0717adad2e9b..e32a8d43e2776653ec8022f5aa1b504d75619465 100644 --- a/commands.txt +++ b/commands.txt @@ -1,3 +1,5 @@ +. ./app.sh +source ./app.sh . <(cat app.sh) # supervisord -c manager.conf flask db init diff --git a/config.py b/config.py index 9b7b62e6d962fe250ff00ba54bd6e7520f3320f1..4648ecc5dc7e5462d10dc5f57c5c94316a1150f8 100644 --- a/config.py +++ b/config.py @@ -19,6 +19,8 @@ SQLALCHEMY_ECHO = False # 打印sql语句 JSON_AS_ASCII = False # jsonify返回的中文正常显示 PLAY_URL = 'http://cms.nokia.press' # 匹配远程解析服务器链接 远程接口主页地址,后面不能有/ PLAY_URL = PLAY_URL.rstrip('/') +HTTP_HOST = '0.0.0.0' +HTTP_PORT = '5705' PLAY_DISABLE = False # 全局禁用播放解析 LAZYPARSE_MODE = 1 # 播放解析模式(0 本地 1 局域网 2远程 仅在全局禁用为False的时候生效) WALL_PAPER_ENABLE = True # 启用自定义壁纸 diff --git "a/js/\346\250\241\346\235\277.js" "b/js/\346\250\241\346\235\277.js" index 7e2a24329e65edae8a61a5480138c4651e9116a2..ac1aaec8c96a2d10e884adc483142fd84f9d9943 100644 --- "a/js/\346\250\241\346\235\277.js" +++ "b/js/\346\250\241\346\235\277.js" @@ -26,7 +26,7 @@ var muban = { class_parse:'.navbar-items li:gt(2):lt(8);a&&Text;a&&href;/(\\d+).html', play_parse:true, lazy:'', - limit:10, + limit:6, 推荐:'.tab-list.active;a.module-poster-item.module-item;.module-poster-item-title&&Text;.lazyload&&data-original;.module-item-note&&Text;a&&href', double:true, // 推荐内容是否双层定位 一级:'body a.module-poster-item.module-item;a&&title;.lazyload&&data-original;.module-item-note&&Text;a&&href', @@ -47,7 +47,7 @@ var muban = { class_parse:'.myui-header__menu li.hidden-sm:gt(0):lt(5);a&&Text;a&&href;/(\\d+).html', play_parse:true, lazy:'', - limit:10, + limit:6, 推荐:'ul.myui-vodlist.clearfix;li;a&&title;a&&data-original;.pic-text&&Text;a&&href', double:true, // 推荐内容是否双层定位 一级:'.myui-vodlist li;a&&title;a&&data-original;.pic-text&&Text;a&&href', @@ -68,7 +68,7 @@ var muban = { class_parse:'.stui-header__menu li:gt(0):lt(7);a&&Text;a&&href;/(\\d+).html', play_parse:true, lazy:'', - limit:10, + limit:6, 推荐:'ul.stui-vodlist.clearfix;li;a&&title;.lazyload&&data-original;.pic-text&&Text;a&&href', double:true, // 推荐内容是否双层定位 一级:'.stui-vodlist li;a&&title;a&&data-original;.pic-text&&Text;a&&href', diff --git a/requirements.txt b/requirements.txt index 5e2985d86f44bb498a47d319540b94eac4cc97f8..dbe593b47a42c2b77d4f7b6ae00693e8eb30d7bc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,6 +6,7 @@ flask-sqlalchemy requests netifaces gevent ; python_version < '3.9' -supervisor ; sys_platform != 'win32' and python_version < '3.9' +gunicorn ; python_version >= '3.6' +supervisor ; sys_platform != 'win32' func_timeout easydict \ No newline at end of file diff --git a/manager.conf b/super/flask.conf similarity index 100% rename from manager.conf rename to super/flask.conf diff --git a/super/sflask.conf b/super/sflask.conf new file mode 100644 index 0000000000000000000000000000000000000000..906bc0a1c28d6ee8a8ecfa838c300c475b63b325 --- /dev/null +++ b/super/sflask.conf @@ -0,0 +1,26 @@ + [inet_http_server] ; inet (TCP) server disabled by default + port=*:9001 ; (ip_address:port specifier, *:port for all iface) + username=user ; (default is no username (open server)) + password=123 ; (default is no password (open server)) + +[supervisord] +;nodaemon=true +logfile=logs/supervisord.log +logfile_maxbytes=50MB +[supervisorctl] +[program:flask_dr_py] +command=gunicorn -w 4 -b 0.0.0.0:5705 app:app ; 被监控的进程路径 +directory=/root/sd/pywork/dr_py ; 执行前要不要先cd到目录去,一般不用 +user=root ;执行者角色 +priority=1 ;数字越高,优先级越高 +;numprocs=1 ; 启动几个进程 +startsecs=0 +autostart=true ; 随着supervisord的启动而启动 +autorestart=true ; 自动重启。。当然要选上了 +startretries=10 ; 启动失败时的最多重试次数 +exitcodes=0 ; 正常退出代码(是说退出代码是这个时就不再重启了吗?待确定) +stopsignal=KILL ; 用来杀死进程的信号 +stopwaitsecs=10 ; 发送SIGKILL前的等待时间 +redirect_stderr=true ; 重定向stderr到stdout +;stopasgroup=true ;用于停止进程组,即停止所有通过“uwsgi.ini”配置启动的进程。 +;killasgroup=true ;用于关闭进程组,即关闭所有通过“uwsgi.ini”配置启动的进程。 \ No newline at end of file diff --git a/super/stermux.conf b/super/stermux.conf new file mode 100644 index 0000000000000000000000000000000000000000..bcc8272c29674d7d25da4a02aac776349dd02af5 --- /dev/null +++ b/super/stermux.conf @@ -0,0 +1,26 @@ + [inet_http_server] ; inet (TCP) server disabled by default + port=*:9001 ; (ip_address:port specifier, *:port for all iface) + username=user ; (default is no username (open server)) + password=123 ; (default is no password (open server)) + +[supervisord] +;nodaemon=true +logfile=logs/supervisord.log +logfile_maxbytes=50MB +[supervisorctl] +[program:flask_dr_py] +command=gunicorn -w 4 -b 0.0.0.0:5705 app:app; 被监控的进程路径 +directory=/sdcard/Download/pywork/dr_py ; 执行前要不要先cd到目录去,一般不用 +user=u0_a414 ;执行者角色 +priority=1 ;数字越高,优先级越高 +;numprocs=1 ; 启动几个进程 +startsecs=0 +autostart=true ; 随着supervisord的启动而启动 +autorestart=true ; 自动重启。。当然要选上了 +startretries=10 ; 启动失败时的最多重试次数 +exitcodes=0 ; 正常退出代码(是说退出代码是这个时就不再重启了吗?待确定) +stopsignal=KILL ; 用来杀死进程的信号 +stopwaitsecs=10 ; 发送SIGKILL前的等待时间 +redirect_stderr=true ; 重定向stderr到stdout +;stopasgroup=true ;用于停止进程组,即停止所有通过“uwsgi.ini”配置启动的进程。 +;killasgroup=true ;用于关闭进程组,即关闭所有通过“uwsgi.ini”配置启动的进程。 \ No newline at end of file diff --git a/super/termux.conf b/super/termux.conf new file mode 100644 index 0000000000000000000000000000000000000000..8f1a13b0f5664db4164e9ac0105d2e577de51279 --- /dev/null +++ b/super/termux.conf @@ -0,0 +1,26 @@ + [inet_http_server] ; inet (TCP) server disabled by default + port=*:9001 ; (ip_address:port specifier, *:port for all iface) + username=user ; (default is no username (open server)) + password=123 ; (default is no password (open server)) + +[supervisord] +;nodaemon=true +logfile=logs/supervisord.log +logfile_maxbytes=50MB +[supervisorctl] +[program:flask_dr_py] +command=python3 app.py ; 被监控的进程路径 +directory=/sdcard/Download/pywork/dr_py ; 执行前要不要先cd到目录去,一般不用 +user=u0_a414 ;执行者角色 +priority=1 ;数字越高,优先级越高 +;numprocs=1 ; 启动几个进程 +startsecs=0 +autostart=true ; 随着supervisord的启动而启动 +autorestart=true ; 自动重启。。当然要选上了 +startretries=10 ; 启动失败时的最多重试次数 +exitcodes=0 ; 正常退出代码(是说退出代码是这个时就不再重启了吗?待确定) +stopsignal=KILL ; 用来杀死进程的信号 +stopwaitsecs=10 ; 发送SIGKILL前的等待时间 +redirect_stderr=true ; 重定向stderr到stdout +;stopasgroup=true ;用于停止进程组,即停止所有通过“uwsgi.ini”配置启动的进程。 +;killasgroup=true ;用于关闭进程组,即关闭所有通过“uwsgi.ini”配置启动的进程。 \ No newline at end of file diff --git a/utils/log.py b/utils/log.py index 1e1d9cb735bcf014743c4630ab62798ee69d67eb..18e47c05085b8316aca8d3cb09b3f80a968737e1 100644 --- a/utils/log.py +++ b/utils/log.py @@ -11,7 +11,7 @@ import sys dirname, filename = os.path.split(os.path.abspath(sys.argv[0])) LOG_ROOT = dirname -# print(LOG_ROOT) +print(LOG_ROOT) # logging.basicConfig( # # level=logging.INFO, # 控制台打印的日志级别 @@ -43,7 +43,10 @@ def get_logger(log_filename, level=logging.DEBUG, when='D', back_count=0): # 设置日志输出的最低等级,低于当前等级则会被忽略 logger.setLevel(level) # 创建日志输出路径 - log_path = os.path.join(LOG_ROOT, "logs") + # log_path = os.path.join(LOG_ROOT, "logs") + base_path = os.path.dirname(os.path.abspath(os.path.dirname(__file__))) # 上级目录 + log_path = os.path.join(base_path, f'logs') + if not os.path.exists(log_path): os.mkdir(log_path) log_file_path = os.path.join(log_path, log_filename)