Browse Source

修改了启动方式

keep-around/37ce0a323abd2c9d471e0491c0eeaac42249b953
hjdhnx 2 years ago
parent
commit
1836b14e6b
11 changed files with 158 additions and 28 deletions
  1. +35
    -21
      app.py
  2. +31
    -1
      app.sh
  3. +2
    -0
      commands.txt
  4. +2
    -0
      config.py
  5. +3
    -3
      js/模板.js
  6. +2
    -1
      requirements.txt
  7. +0
    -0
      super/flask.conf
  8. +26
    -0
      super/sflask.conf
  9. +26
    -0
      super/stermux.conf
  10. +26
    -0
      super/termux.conf
  11. +5
    -2
      utils/log.py

+ 35
- 21
app.py View File

@ -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()
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)

+ 31
- 1
app.sh View File

@ -1,2 +1,32 @@
#!/bin/bash
kill -9 $(cat supervisord.pid) # 杀掉进程
supervisord -c manager.conf
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

+ 2
- 0
commands.txt View File

@ -1,3 +1,5 @@
. ./app.sh
source ./app.sh
. <(cat app.sh)
# supervisord -c manager.conf
flask db init


+ 2
- 0
config.py View File

@ -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 # 启用自定义壁纸


+ 3
- 3
js/模板.js View File

@ -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',


+ 2
- 1
requirements.txt View File

@ -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

manager.conf → super/flask.conf View File


+ 26
- 0
super/sflask.conf View File

@ -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”配置启动的进程。

+ 26
- 0
super/stermux.conf View File

@ -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”配置启动的进程。

+ 26
- 0
super/termux.conf View File

@ -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”配置启动的进程。

+ 5
- 2
utils/log.py View File

@ -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)


Loading…
Cancel
Save