Skip to content
Snippets Groups Projects
Commit 71c92ded authored by Francesco Siddi's avatar Francesco Siddi
Browse files

Manager: fix for server registration

parent 8be65799
No related branches found
No related tags found
No related merge requests found
Showing with 56 additions and 40 deletions
...@@ -36,6 +36,8 @@ VOLUME /data/config ...@@ -36,6 +36,8 @@ VOLUME /data/config
VOLUME /data/storage/shared VOLUME /data/storage/shared
VOLUME /data/storage/dashboard VOLUME /data/storage/dashboard
ENV IS_DOCKER True
EXPOSE 8888 EXPOSE 8888
ADD runserver.sh /runserver.sh ADD runserver.sh /runserver.sh
......
#!/usr/bin/env bash
. /data/venv/bin/activate && python /data/git/dashboard/manage.py $1 $2 $3
...@@ -4,5 +4,5 @@ ...@@ -4,5 +4,5 @@
if [ ! -d /data/git/dashboard/node_modules ]; then if [ ! -d /data/git/dashboard/node_modules ]; then
bash setup.sh bash setup.sh
fi fi
# Enable virtual evnvironment and start server # Enable virtual evnvironment and start dashboard
. /data/venv/bin/activate && cd /data/git/dashboard && python manage.py runserver . /data/venv/bin/activate && cd /data/git/dashboard && python manage.py runserver
...@@ -48,6 +48,8 @@ VOLUME /data/config ...@@ -48,6 +48,8 @@ VOLUME /data/config
VOLUME /data/storage/shared VOLUME /data/storage/shared
VOLUME /data/storage/dashboard VOLUME /data/storage/dashboard
ENV IS_DOCKER True
EXPOSE 8888 EXPOSE 8888
ADD 000-default.conf /etc/apache2/sites-available/000-default.conf ADD 000-default.conf /etc/apache2/sites-available/000-default.conf
......
#!/usr/bin/env bash
. /data/venv/bin/activate && python /data/git/dashboard/manage.py $1 $2 $3
...@@ -7,4 +7,8 @@ if [ ! -e /installed ]; then ...@@ -7,4 +7,8 @@ if [ ! -e /installed ]; then
touch /installed touch /installed
fi fi
# Enable virtual evnvironment and register manager
. /data/venv/bin/activate && cd /data/git/manager && python manage.py setup_register_manager
# Run development server
. /data/venv/bin/activate && cd /data/git/manager && python manage.py runserver . /data/venv/bin/activate && cd /data/git/manager && python manage.py runserver
...@@ -7,5 +7,8 @@ if [ ! -e /installed ]; then ...@@ -7,5 +7,8 @@ if [ ! -e /installed ]; then
touch /installed touch /installed
fi fi
# Enable virtual evnvironment and register manager
. /data/venv/bin/activate && cd /data/git/manager && python manage.py setup_register_manager
# Run Apache # Run Apache
/usr/sbin/apache2 -D FOREGROUND /usr/sbin/apache2 -D FOREGROUND
...@@ -10,11 +10,18 @@ app.config.update( ...@@ -10,11 +10,18 @@ app.config.update(
SECRET_KEY='A0Zr98j/3yX R~XHH!jmN]LWX/,?RT', SECRET_KEY='A0Zr98j/3yX R~XHH!jmN]LWX/,?RT',
) )
try: # Initial configuration
from application import config from application import config_base
app.config['FLAMENCO_SERVER'] = config.Config.FLAMENCO_SERVER app.config.from_object(config_base.Config)
except ImportError:
app.config['FLAMENCO_SERVER'] = 'localhost:9999' # If we are in a Docker container, override with some new defaults
if os.environ.get('IS_DOCKER'):
from application import config_docker
app.config.from_object(config_docker.Config)
# If a custom config file is specified, further override the config
if os.environ.get('FLAMENCO_DASHBOARD_CONFIG'):
app.config.from_envvar('FLAMENCO_DASHBOARD_CONFIG')
def check_connection(): def check_connection():
try: try:
......
class Config(object):
DEBUG=True
FLAMENCO_SERVER='localhost:9999'
PORT=8888
HOST='0.0.0.0'
class Config(object):
DEBUG = True
FLAMENCO_SERVER = 'localhost:9999'
PORT = 8888
HOST = '0.0.0.0'
class Config(object):
FLAMENCO_SERVER = 'flamenco_server:9999'
...@@ -99,6 +99,7 @@ def register_manager(host, name, has_virtual_workers): ...@@ -99,6 +99,7 @@ def register_manager(host, name, has_virtual_workers):
r = http_request(app.config['FLAMENCO_SERVER'], '/managers', 'post', params=params) r = http_request(app.config['FLAMENCO_SERVER'], '/managers', 'post', params=params)
# If we don't find one, we proceed to create it, using the server reponse # If we don't find one, we proceed to create it, using the server reponse
# TODO handle case when token exists on the manager, but not on the server
if not token: if not token:
token = Setting(name='token', value=r['token']) token = Setting(name='token', value=r['token'])
db.session.add(token) db.session.add(token)
......
...@@ -6,7 +6,7 @@ class Config(object): ...@@ -6,7 +6,7 @@ class Config(object):
DEBUG = True DEBUG = True
PORT = 7777 PORT = 7777
HOST = '0.0.0.0' # or 'localhost' HOST = '0.0.0.0' # or 'localhost'
HOSTNAME = 'My Manager' # or use socket.gethostname() NAME = 'My Manager' # or use socket.gethostname()
FLAMENCO_SERVER = 'localhost:9999' FLAMENCO_SERVER = 'localhost:9999'
DATABASE_URI = 'sqlite:///' + os.path.join(os.path.dirname(__file__), '../') DATABASE_URI = 'sqlite:///' + os.path.join(os.path.dirname(__file__), '../')
...@@ -20,7 +20,5 @@ class Config(object): ...@@ -20,7 +20,5 @@ class Config(object):
TMP_FOLDER = tempfile.gettempdir() TMP_FOLDER = tempfile.gettempdir()
THUMBNAIL_EXTENSIONS = set(['png']) THUMBNAIL_EXTENSIONS = set(['png'])
# Don't change this variable until the worker's code will have costant declaration of this path
# see controllers.py line 243 to understand
MANAGER_STORAGE = '{0}/static/storage'.format( MANAGER_STORAGE = '{0}/static/storage'.format(
os.path.join(os.path.dirname(__file__))) os.path.join(os.path.dirname(__file__)))
...@@ -76,38 +76,29 @@ def setup_db(): ...@@ -76,38 +76,29 @@ def setup_db():
@manager.command @manager.command
def runserver(): def setup_register_manager():
"""This command is meant for development. If no configuration is found,
we start the app listening from all hosts, from port 7777."""
setup_db()
try:
from application import config
PORT = config.Config.PORT
DEBUG = config.Config.DEBUG
HOST = config.Config.HOST
HOSTNAME = config.Config.HOSTNAME
VIRTUAL_WORKERS = config.Config.VIRTUAL_WORKERS
except ImportError:
DEBUG = False
PORT = 7777
HOST = '0.0.0.0'
VIRTUAL_WORKERS = False
HOSTNAME = socket.gethostname()
# Register the manager to the server # Register the manager to the server
if os.environ.get('WERKZEUG_RUN_MAIN') != 'true': if os.environ.get('WERKZEUG_RUN_MAIN') != 'true':
if VIRTUAL_WORKERS: if app.config['VIRTUAL_WORKERS']:
has_virtual_worker = 1 has_virtual_worker = 1
else: else:
has_virtual_worker = 0 has_virtual_worker = 0
full_host = "{0}:{1}".format(HOST, PORT) full_host = "http://{0}:{1}".format(
register_manager(full_host, HOSTNAME, has_virtual_worker) app.config['HOST'], app.config['PORT'])
register_manager(full_host, app.config['NAME'], has_virtual_worker)
@manager.command
def runserver():
"""This command is meant for development. If no configuration is found,
we start the app listening from all hosts, from port 7777."""
setup_db()
setup_register_manager()
app.run( app.run(
port=PORT, port=app.config['PORT'],
debug=DEBUG, debug=app.config['DEBUG'],
host=HOST, host=app.config['HOST'],
threaded=True) threaded=True)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment