diff --git a/Dockerfile b/Dockerfile index 9c9d32e..49787cd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -98,4 +98,7 @@ EXPOSE 5555 # Mongodb EXPOSE 27017 +# Surveil +EXPOSE 8080 + CMD ["/usr/bin/supervisord"] diff --git a/requirements.txt b/requirements.txt index 09faf82..ef21ca6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ pecan>=0.5.0 pymongo>=2.7.2 +wsme \ No newline at end of file diff --git a/setup.cfg b/setup.cfg index 957b8ff..1478ec0 100644 --- a/setup.cfg +++ b/setup.cfg @@ -9,6 +9,10 @@ description-file = packages = surveil +[entry_points] +console_scripts = + surveil-api = surveil.cmd.api:main + [build_sphinx] source-dir = doc/source build-dir = doc/build diff --git a/surveil/api/config.py b/surveil/api/config.py index 1a016fd..a2b57ef 100644 --- a/surveil/api/config.py +++ b/surveil/api/config.py @@ -18,13 +18,13 @@ from surveil.api import hooks # Server Specific Configurations server = { - 'port': '8080', + 'port': 8080, 'host': '0.0.0.0' } app_hooks = [ hooks.DBHook( - pymongo.MongoClient('172.17.0.2', 27017) + pymongo.MongoClient('127.0.0.1', 27017) ) ] diff --git a/surveil/cmd/__init__.py b/surveil/cmd/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/surveil/cmd/api.py b/surveil/cmd/api.py new file mode 100644 index 0000000..b39914a --- /dev/null +++ b/surveil/cmd/api.py @@ -0,0 +1,55 @@ +# Copyright 2014 - Savoir-Faire Linux inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +"""Starter script for the Surveil API service.""" + +import os +from wsgiref import simple_server + +import pecan + +from surveil.api import app as api_app +from surveil.api import config as api_config + + +# TODO(aviau): Load conf from oslo +def get_pecan_config(): + # Set up the pecan configuration + filename = api_config.__file__.replace('.pyc', '.py') + return pecan.configuration.conf_from_file(filename) + + +def main(): + cfg = get_pecan_config() + + app = api_app.setup_app(cfg) + + # Create the WSGI server and start it + host, port = cfg.server.host, cfg.server.port + srv = simple_server.make_server(host, port, app) + + # TODO(aviau): Logging. don't print :o) + print ('Starting server in PID %s' % os.getpid()) + + if host == '0.0.0.0': + print ( + 'serving on 0.0.0.0:%(port)s, view at http://127.0.0.1:%(port)s' % + dict(port=port) + ) + else: + print ( + 'serving on http://%(host)s:%(port)s' % dict(host=host, port=port) + ) + + srv.serve_forever() \ No newline at end of file diff --git a/test-requirements.txt b/test-requirements.txt index 10bc845..28a0f59 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -4,5 +4,4 @@ sphinxcontrib-pecanwsme>=0.8 sphinxcontrib-httpdomain oslosphinx testrepository>=0.0.18 -mongomock -wsme \ No newline at end of file +mongomock \ No newline at end of file diff --git a/tools/docker/etc/supervisor/conf.d/supervisor.conf b/tools/docker/etc/supervisor/conf.d/supervisor.conf index e0ac96a..0c0dfbd 100644 --- a/tools/docker/etc/supervisor/conf.d/supervisor.conf +++ b/tools/docker/etc/supervisor/conf.d/supervisor.conf @@ -17,4 +17,4 @@ command=/bin/sh -c "service riemann start" command=/bin/sh -c "service mongodb start" [program:surveil] -command=/bin/sh -c "pecan serve /usr/local/lib/python3.4/dist-packages/surveil/api/config.py" +command=/bin/sh -c "sleep 20 && surveil-api"