示例#1
0
def start_redis(**kwargs):
    from app.utils import read_config_yaml, is_debug

    _config = read_config_yaml()
    debug = is_debug()

    redis_port = _config['redis']['listen_port']
    os.system('redis-server --port %s 1>/dev/null 2>/dev/null' % redis_port)
示例#2
0
def start_process_watcher():
    from .mq_events import WatcherEvents
    from .watcher import Watcher
    from app.tools.mq_proxy import WS_TAG, MessageQueueProxy
    from app.utils import is_debug, read_config_yaml

    logger.set_debug(is_debug())
    _config = read_config_yaml()
    router_port = _config['broker']['listen_port']

    proxy = MessageQueueProxy(WS_TAG.MPW, router_port=router_port)
    proxy.register(WatcherEvents)

    logger.info("This is Minecraft Process Watcher.")
    proxy.listen(background=True)

    # start event loop
    watcher = Watcher()
    watcher.launch_loop()
示例#3
0
def start_chaussette():
    from app import app as _app
    from app import logger, proxy
    from app.utils import read_config_yaml, is_debug
    from app.mq_events import WebsocketEventHandler
    from app.controller.global_config import GlobalConfig
    from app.controller.init_main_db import init_database

    from chaussette.backend import _backends
    from chaussette.backend._eventlet import Server as eventlet_server
    from chaussette.server import make_server

    _config = read_config_yaml()
    debug = is_debug()

    # variables
    host = _config['server']['host']
    port = int(_config['server']['listen_port'])
    use_reloader = _config['server']['use_reloader']
    circusd_end_port = _config['circus']['end_port']
    redis_port = _config['redis']['listen_port']
    zmq_port = _config['broker']['listen_port']

    logger.set_debug(debug)
    _app.config["_circusd_end_port"] = circusd_end_port
    _app.config["_zmq_port"] = zmq_port
    _app.config["_debug"] = debug

    logger.info("This is Main Server (%s)" % os.getpid())

    def init_directory():
        gc = GlobalConfig.getInstance()
        dirs = [
            gc.get("base_dir"),
            gc.get("uploads_dir"),
            gc.get("files_dir"),
            gc.get("servers_dir"),
            gc.get("lib_bin_dir"),
            gc.get("sqlite_dir"),
            # it's totally useless to store a directory's name into database
            # why not just name it?
            # 2017-2-7
        ]

        for item in dirs:
            if not os.path.isdir(item):
                os.makedirs(item)

    def init_mq_proxy():
        proxy.register(WebsocketEventHandler)
        proxy.listen(background=True)

    def wrap_socketio_server():
        import socketio
        from websocket_server.ws_conn import WSConnections

        mgr = socketio.RedisManager("redis://localhost:%s/0" % redis_port)
        sio = socketio.Server(client_manager=mgr, async_mode='eventlet')

        #init
        ws = WSConnections.getInstance(sio)
        ws.init_events()
        app = socketio.Middleware(sio, _app)

        return app

    def _make_server():
        try:
            # instill eventlet_server instance to `_backends` dict to bypass the restriction!
            _backends['eventlet'] = eventlet_server

            app = wrap_socketio_server()
            httpd = make_server(app, host=host, port=port, backend='eventlet')

            httpd.serve_forever()
        except KeyboardInterrupt:
            sys.exit(0)

    # init directories
    init_directory()

    # init message queue proxy
    init_mq_proxy()

    # init database
    init_database(logger=logger)

    if use_reloader:
        try:
            from werkzeug.serving import run_with_reloader
        except ImportError:
            logger.info("Reloader requires Werkzeug: "
                        "'pip install werkzeug'")
            sys.exit(0)
        run_with_reloader(_make_server)
    else:
        _make_server()
示例#4
0
__author__ = "Nigshoxiz"
from urllib.error import HTTPError
from urllib.request import urlopen, Request
import os, ssl, json, inspect, random, string, copy, time, traceback, threading, shutil
from app.utils import is_debug
# add logger
from ob_logger import Logger
logger = Logger("dlMC", debug=is_debug())


class AbruptException(Exception):
    def __init__(self):
        Exception.__init__(self)

    def __str__(self):
        return "Just an exception!"


class DownloaderPool(object):

    instance = None

    def __init__(self):
        self.pool = {}

        pass

    @staticmethod
    def getInstance():
        if DownloaderPool.instance == None:
            DownloaderPool.instance = DownloaderPool()
示例#5
0
__author__ = "Nigshoxiz"

from ob_logger import Logger
from app.utils import is_debug

logger = Logger("MsgQ", debug=is_debug())


class PRIVILEGES:
    NONE = 0x0000
    INST_OWNER = 0x0001
    ROOT_USER = 0x0100


from .server import start_zeromq_broker
示例#6
0
from .manager import FTPManager
from .mq_events import FTPAccountEventHandler
from app.tools.mq_proxy import MessageQueueProxy, WS_TAG
from app.utils import is_debug, read_config_yaml
from ob_logger import Logger

logger = Logger("FTM", debug=is_debug())


def start_FTP_manager():

    _config = read_config_yaml()
    zmq_port = _config['broker']['listen_port']
    port = _config['ftp']['listen_port']

    proxy = MessageQueueProxy(WS_TAG.FTM, router_port=zmq_port)
    proxy.register(FTPAccountEventHandler)
    proxy.listen(background=True)

    manager = FTPManager()
    manager.set_port(port)

    logger.info("This is FTP Manager, listening port %s" % port)
    manager.launch(background=False)