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')
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')
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")
def create_db(): """ Creates DB tables """ green("Creating all tables") with app.app_context(): green('DB_URI: %s' % app.config.get('DB_URI')) db.metadata.create_all(db.get_engine(app))
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)
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)
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)
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')
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)
def version(): """ Output version """ green(__version__)