Exemplo n.º 1
0
def setup_upstart(**kwargs):
    """ Start upstart conf creation wizard
    """
    from realms.lib.util import upstart_script

    if in_virtualenv():
        app_dir = get_prefix()
        path = '/'.join(sys.executable.split('/')[:-1])
    else:
        # Assumed root install, not sure if this matters?
        app_dir = '/'
        path = None

    kwargs.update(dict(app_dir=app_dir, path=path))

    conf_file = '/etc/init/realms-wiki.conf'
    script = upstart_script(**kwargs)

    try:
        with open(conf_file, 'w') as f:
            f.write(script)
        green('Wrote file to %s' % conf_file)
    except IOError:
        with open('/tmp/realms-wiki.conf', 'w') as f:
            f.write(script)
        yellow("Wrote file to /tmp/realms-wiki.conf, to install type:")
        yellow("sudo mv /tmp/realms-wiki.conf /etc/init/realms-wiki.conf")

    click.echo()
    click.echo("Upstart usage:")
    green("sudo start realms-wiki")
    green("sudo stop realms-wiki")
    green("sudo restart realms-wiki")
    green("sudo status realms-wiki")
Exemplo n.º 2
0
def start_server():
    if is_running(get_pid()):
        yellow("Server is already running")
        return

    try:
        open(config.PIDFILE, 'w')
    except IOError:
        red("PID file not writeable (%s) " % config.PIDFILE)
        return

    flags = '--daemon --pid %s' % config.PIDFILE

    green("Server started. Port: %s" % config.PORT)

    config_path = config.get_path()
    if config_path:
        green("Using config: %s" % config_path)
    else:
        yellow("Using default configuration")

    prefix = ''
    if in_virtualenv():
        prefix = get_prefix() + "/bin/"

    Popen("%sgunicorn 'realms:create_app()' -b 0.0.0.0:%s -k gevent %s" %
          (prefix, config.PORT, flags),
          shell=True,
          executable='/bin/bash')
Exemplo n.º 3
0
def setup_upstart(**kwargs):
    """ Start upstart conf creation wizard
    """
    from realms.lib.util import upstart_script

    if in_virtualenv():
        app_dir = get_prefix()
        path = '/'.join(sys.executable.split('/')[:-1])
    else:
        # Assumed root install, not sure if this matters?
        app_dir = '/'
        path = None

    kwargs.update(dict(app_dir=app_dir, path=path))

    conf_file = '/etc/init/realms-wiki.conf'
    script = upstart_script(**kwargs)

    try:
        with open(conf_file, 'w') as f:
            f.write(script)
        green('Wrote file to %s' % conf_file)
    except IOError:
        with open('/tmp/realms-wiki.conf', 'w') as f:
            f.write(script)
        yellow("Wrote file to /tmp/realms-wiki.conf, to install type:")
        yellow("sudo mv /tmp/realms-wiki.conf /etc/init/realms-wiki.conf")

    click.echo()
    click.echo("Upstart usage:")
    green("sudo start realms-wiki")
    green("sudo stop realms-wiki")
    green("sudo restart realms-wiki")
    green("sudo status realms-wiki")
Exemplo n.º 4
0
def start_server():
    if is_running(get_pid()):
        yellow("Server is already running")
        return

    try:
        open(config.PIDFILE, 'w')
    except IOError:
        red("PID file not writeable (%s) " % config.PIDFILE)
        return

    flags = '--daemon --pid %s' % config.PIDFILE

    green("Server started. Port: %s" % config.PORT)

    config_path = config.get_path()
    if config_path:
        green("Using config: %s" % config_path)
    else:
        yellow("Using default configuration")

    prefix = ''
    if in_virtualenv():
        prefix = get_prefix() + "/bin/"

    Popen("%sgunicorn 'realms:create_app()' -b 0.0.0.0:%s -k gevent %s" %
          (prefix, config.PORT, flags), shell=True, executable='/bin/bash')
Exemplo n.º 5
0
def status():
    """ Get server status
    """
    pid = get_pid()
    if not is_running(pid):
        yellow("Server is not running")
    else:
        green("Server is running PID: %s" % pid)
Exemplo n.º 6
0
def status():
    """ Get server status
    """
    pid = get_pid()
    if not is_running(pid):
        yellow("Server is not running")
    else:
        green("Server is running PID: %s" % pid)
Exemplo n.º 7
0
def stop_server():
    pid = get_pid()
    if not is_running(pid):
        yellow("Server is not running")
    else:
        yellow("Shutting down server")
        call(['kill', pid])
        while is_running(pid):
            time.sleep(1)
Exemplo n.º 8
0
def stop_server():
    pid = get_pid()
    if not is_running(pid):
        yellow("Server is not running")
    else:
        yellow("Shutting down server")
        call(['kill', pid])
        while is_running(pid):
            time.sleep(1)
Exemplo n.º 9
0
def dev(port):
    """ Run development server
    """
    green("Starting development server")

    config_path = config.get_path()
    if config_path:
        green("Using config: %s" % config_path)
    else:
        yellow("Using default configuration")

    create_app().run(host="0.0.0.0", port=port, debug=True)
Exemplo n.º 10
0
def dev(port, host):
    """ Run development server
    """
    green("Starting development server")

    config_path = config.get_path()
    if config_path:
        green("Using config: %s" % config_path)
    else:
        yellow("Using default configuration")

    app.run(host=host, port=port, debug=True)
Exemplo n.º 11
0
def setup(ctx, **kw):
    """ Start setup wizard
    """

    try:
        os.mkdir('/etc/realms-wiki')
    except OSError:
        pass

    conf = {}

    for k, v in kw.items():
        conf[k.upper()] = v

    conf_path = config.update(conf)

    if conf['CACHE_TYPE'] == 'redis':
        prompt_and_invoke(ctx, setup_redis)
    elif conf['CACHE_TYPE'] == 'memcached':
        prompt_and_invoke(ctx, setup_memcached)

    if conf['SEARCH_TYPE'] == 'elasticsearch':
        prompt_and_invoke(ctx, setup_elasticsearch)
    elif conf['SEARCH_TYPE'] == 'whoosh':
        install_whoosh()

    green('Config saved to %s' % conf_path)

    if not conf_path.startswith('/etc/realms-wiki'):
        yellow('Note: You can move file to /etc/realms-wiki/realms-wiki.json')
        click.echo()

    yellow('Type "realms-wiki start" to start server')
    yellow('Type "realms-wiki dev" to start server in development mode')
    yellow('Full usage: realms-wiki --help')
Exemplo n.º 12
0
def setup(ctx, **kw):
    """ Start setup wizard
    """

    try:
        os.mkdir('/etc/realms-wiki')
    except OSError:
        pass

    conf = {}

    for k, v in kw.items():
        conf[k.upper()] = v

    conf_path = config.update(conf)

    if conf['CACHE_TYPE'] == 'redis':
        prompt_and_invoke(ctx, setup_redis)
    elif conf['CACHE_TYPE'] == 'memcached':
        prompt_and_invoke(ctx, setup_memcached)

    if conf['SEARCH_TYPE'] == 'elasticsearch':
        prompt_and_invoke(ctx, setup_elasticsearch)
    elif conf['SEARCH_TYPE'] == 'whoosh':
        install_whoosh()

    green('Config saved to %s' % conf_path)

    if not conf_path.startswith('/etc/realms-wiki'):
        yellow('Note: You can move file to /etc/realms-wiki/realms-wiki.json')
        click.echo()

    yellow('Type "realms-wiki start" to start server')
    yellow('Type "realms-wiki dev" to start server in development mode')
    yellow('Full usage: realms-wiki --help')
Exemplo n.º 13
0
def start_server():
    if is_running(get_pid()):
        yellow("Server is already running")
        return

    flags = '--daemon --pid %s' % config.PIDFILE

    green("Server started. Port: %s" % config.PORT)

    config_path = config.get_path()
    if config_path:
        green("Using config: %s" % config_path)
    else:
        yellow("Using default configuration")

    Popen("gunicorn 'realms:create_app()' -b 0.0.0.0:%s -k gevent %s" %
          (config.PORT, flags), shell=True, executable='/bin/bash')
Exemplo n.º 14
0
def start_server():
    if is_running(get_pid()):
        yellow("Server is already running")
        return

    flags = '--daemon --pid %s' % config.PIDFILE

    green("Server started. Port: %s" % config.PORT)

    config_path = config.get_path()
    if config_path:
        green("Using config: %s" % config_path)
    else:
        yellow("Using default configuration")

    Popen("gunicorn 'realms:create_app()' -b 0.0.0.0:%s -k gevent %s" %
          (config.PORT, flags), shell=True, executable='/bin/bash')
Exemplo n.º 15
0
def create_user(username, email, password):
    """ Create a new user
    """
    show_pass = not password

    if not password:
        password = random_string(12)

    if User.get_by_username(username):
        red("Username %s already exists" % username)
        return

    if User.get_by_email(email):
        red("Email %s already exists" % email)
        return

    User.create(username, email, password)
    green("User %s created" % username)

    if show_pass:
        yellow("Password: %s" % password)
Exemplo n.º 16
0
def drop_db():
    """ Drops DB tables
    """
    yellow("Dropping all tables")
    with app.app_context():
        db.metadata.drop_all(db.get_engine(app))
Exemplo n.º 17
0
def clear_cache():
    """ Clears cache
    """
    yellow("Clearing the cache")
    with app.app_context():
        cache.clear()
Exemplo n.º 18
0
def clear_cache():
    """ Clears cache
    """
    yellow("Clearing the cache")
    with app.app_context():
        cache.clear()
Exemplo n.º 19
0
def drop_db():
    """ Drops DB tables
    """
    yellow("Dropping all tables")
    with app.app_context():
        db.metadata.drop_all(db.get_engine(app))