diff --git a/README.md b/README.md index e1e9da9..9fa7375 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ pip install -r requirements.txt python setup.py install python application.py ``` - +You may set BSFLASK_ENV environment variable to production, development or testing. ### Running Tests In the root directory, run the following command: diff --git a/src/application.py b/src/application.py index 1b2a3bf..68cc8bf 100644 --- a/src/application.py +++ b/src/application.py @@ -24,7 +24,7 @@ from src.models import db from src.views.errors import error_pages from src.views.scoreboard import scoreboard from src.resources.utilities import cache -import sys +import os import flask_bootstrap import flask @@ -43,8 +43,9 @@ def create_app(config_name): return app try: - print("Running with configuration: " + sys.argv[1]) - app = create_app(sys.argv[1]) + configuration = os.environ['BSFLASK_ENV'] + print("Running with configuration: " + configuration) + app = create_app(configuration) except (IndexError, KeyError): print("Using default configuration.") app = create_app('default') diff --git a/src/gconfig.py b/src/gconfig.py index 4ba4946..b5012cd 100644 --- a/src/gconfig.py +++ b/src/gconfig.py @@ -17,12 +17,24 @@ This the configuration file for the GUnicorn server. """ -from src.config import ProductionConfig import multiprocessing +import os + +# If BSFLASK_ENV is development or environment then gunicorn will bind to Config.APP_IP and Config.APP_PORT +# else it will create a unix socket benchmark_scoreboard.sock that may be used by Nginx +configuration = None +try: + configuration = os.environ['BSFLASK_ENV'] +except KeyError: + print("Environment key BSFLASK_ENV not defined.") + +if configuration is not None and configuration != 'production': + from src.config import Config + bind = "{ip}:{port}".format(ip=Config.BIND_IP, port=Config.BIND_PORT) +else: + bind = "unix:benchmark_scoreboard.sock" -bind = "{ip}:{port}".format(ip=ProductionConfig.BIND_IP, port=ProductionConfig.BIND_PORT) workers = multiprocessing.cpu_count() * 2 + 1 reload = False -#daemon = True -#user = "denis" -#group = "www-data" \ No newline at end of file +# Allow access to name and group. +umask = 0x007