Esempio n. 1
0
def keep_time_consistent():
    need_start = False
    logger.info("时间校验服务启动")
    ntp_interval = s.get_conf_int("NTP_INTERVAL", default=64)
    ntp_host = s.get_conf_str("NTP_HOST", default="ntp.aliyun.com")
    ntp_port = s.get_conf_int("NTP_PORT", default=123)
    while True:
        if not check_time_consistent(ntp_host, ntp_port):
            break
        time.sleep(ntp_interval)
Esempio n. 2
0
    def __init__(self):
        super().__init__(
            import_name=s.get_conf_str("SERVER_NAME", "v2ray_subscribe"))

        self._init_service()
Esempio n. 3
0
        self._register_error_handler(None, Exception, error_handler)


app = ServiceCentre()
app.wsgi_app = WsgiApp(app.wsgi_app)
app.auto_find_instance_path()


@app.route("/favicon.ico")
def favicon():
    return ""


if __name__ == "__main__":
    app.run(
        s.get_conf_str("HOST", default="0.0.0.0"),
        port=s.get_conf_int("PORT", default=5000),
        threaded=True,
        debug=s.get_conf_bool("LOG_DEBUG", default=False),
    )

    # http_server = WSGIServer(
    #     (
    #         g.get_conf_str("HOST", default="0.0.0.0"),
    #         g.get_conf_int("PORT", default=5000),
    #     ),
    #     app,
    # )
    # http_server.serve_forever()
Esempio n. 4
0
from sqlalchemy import *
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.pool import SingletonThreadPool

from conf import s

base = declarative_base()

engine = create_engine(
    s.get_conf_str("DB_URL",
                   default="sqlite:///gateway.vdb?check_same_thread=false"),
    poolclass=SingletonThreadPool,
    pool_size=128,
    pool_recycle=3600,
    # pool_use_lifo=True,
    pool_pre_ping=True,
    # max_overflow=-1,
)

base.metadata.create_all(engine)

s.init_db(engine)
Esempio n. 5
0
import logging
import logging.handlers
import os
import platform
import socket
import sys

from conf import s

LOG_DEBUG = s.get_conf_bool("LOG_DEBUG", default=False)
SERVER_NAME = s.get_conf_str("SERVER_NAME", default="service")
LOG_PATH = s.get_conf_str("LOG_PATH", default="./service.log")

sys.path.append("../")

# 如果日志路径为空,根据系统来分别设置默认路径
if LOG_PATH == "":
    if platform.system() == "Windows":
        LOG_PATH = "C:/ProgramData/log"
    elif platform.system() == "Linux":
        LOG_PATH = "/home/log"
    # TODO 对于java平台的默认日志路径的处理
    else:
        sys.exit(-1)

log_config = {
    "debug": LOG_DEBUG,
    "log_path": LOG_PATH if LOG_PATH.endswith(".log") else "{}.log".format(LOG_PATH),
}

# print("日志输出路径", log_config["log_path"])