#!/usr/bin/python3

# WatchGhost, your invisible but loud monitoring pet
# Copyright © 2015 Kozea

import asyncio
import logging
import os

from tornado.options import options, parse_command_line, parse_config_file
from tornado.platform.asyncio import AsyncIOMainLoop
from watchghost import app, config, web  # noqa


AsyncIOMainLoop().install()

if __name__ == '__main__':
    parse_command_line()
else:
    parse_config_file(
        os.environ.get('WATCHGHOST_CONFIG', '/etc/watchghost.conf'))

log = logging.getLogger('watchghost')
log.setLevel(logging.DEBUG if options.debug else logging.ERROR)

config.read()

if __name__ == '__main__':
    log.debug('Listening to http://%s:%i' % (options.host, options.port))
    app.listen(options.port)

    asyncio.get_event_loop().run_forever()
