Skip to content

Commit

Permalink
Added CLI to launch web server.
Browse files Browse the repository at this point in the history
  • Loading branch information
rtnpro committed May 29, 2016
1 parent e596ff2 commit 0bf6067
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
14 changes: 13 additions & 1 deletion ircb/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import click

from ircb.bouncer import runserver
from ircb.config import settings
from ircb.web.app import runserver as webserver


@click.group(name='run')
Expand All @@ -26,11 +26,23 @@ def run_server(host, port, mode):

@click.command(name='stores')
def run_stores():
"""Run ircb stores"""
import ircb.stores
import ircb.stores.base
ircb.stores.initialize()
ircb.stores.base.dispatcher.run_forever()


@click.option('--host', '-h', default='0.0.0.0',
help='Host, defaults to 0.0.0.0')
@click.option('--port', '-p', default=10000,
help='Port, defaults to 10000')
@click.command(name='web')
def run_web(host, port):
"""Run ircb web server"""
webserver(host, port)


run_cli.add_command(run_server)
run_cli.add_command(run_stores)
run_cli.add_command(run_web)
10 changes: 7 additions & 3 deletions ircb/web/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def index(request):


@asyncio.coroutine
def init(loop):
def init(loop, host='0.0.0.0', port=10000):
from ircb.storeclient import initialize
initialize()
load_config()
Expand Down Expand Up @@ -50,10 +50,14 @@ def init(loop):
app.make_handler(logger=logger, access_log=logger), '0.0.0.0', 10001)
return srv

if __name__ == '__main__':

def runserver(host='0.0.0.0', port=10000):
loop = asyncio.get_event_loop()
loop.run_until_complete(init(loop))
loop.run_until_complete(init(loop, host=host, port=port))
try:
loop.run_forever()
except KeyboardInterrupt:
pass

if __name__ == '__main__':
runserver()

0 comments on commit 0bf6067

Please sign in to comment.