From 2d788eb704982e0eef88ccb218417cc6ad9c442e Mon Sep 17 00:00:00 2001 From: Disassembler Date: Fri, 10 Apr 2020 13:02:15 +0200 Subject: [PATCH] Run update-conf.sh when appropriate --- usr/lib/python3.8/vmmgr/vmmgr.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/usr/lib/python3.8/vmmgr/vmmgr.py b/usr/lib/python3.8/vmmgr/vmmgr.py index 7bd15af..6719779 100644 --- a/usr/lib/python3.8/vmmgr/vmmgr.py +++ b/usr/lib/python3.8/vmmgr/vmmgr.py @@ -23,6 +23,7 @@ def register_app(app, host, login, password): 'visible': False, }) register_proxy(app) + update_app_config(app) def unregister_app(app): unregister_proxy(app) @@ -54,6 +55,7 @@ def update_host(domain, port): f.write(templates.NGINX_DEFAULT.format(port=port, domain=domain)) for app in config.get_apps().keys(): register_proxy(app) + update_app_config() def reload_nginx(): subprocess.run(['/usr/sbin/nginx', '-s', 'reload']) @@ -76,6 +78,7 @@ def update_common_settings(email, gmaps_api_key): # Update common configuration values config.set_common('email', email) config.set_common('gmaps-api-key', gmaps_api_key) + update_app_config() def update_password(oldpassword, newpassword): # Update LUKS password and adminpwd for WSGI application @@ -156,6 +159,29 @@ def update_app_autostart(app_name, enabled): # Add/remove the app to OpenRC default runlevel App(app_name, False).set_autostart(enabled) +def update_app_config(app_name=None): + # Set environment variables and run scripts to update relevant application configuration files + common = config.get_common() + host = config.get_host() + apps = config.get_apps() + env = os.environ.copy() + env['LAYERS_DIR'] = spoc_config.LAYERS_DIR + env['VOLUMES_DIR'] = spoc_config.VOLUMES_DIR + env['APPS_DIR'] = spoc_config.APPS_DIR + env['LOG_DIR'] = spoc_config.LOG_DIR + env['DOMAIN'] = host['domain'] + env['PORT'] = host['port'] + env['EMAIL'] = common['email'] + env['GMAPS_API_KEY'] = common['gmaps-api-key'] + app_names = [app_name] if app_name else repo_local.get_apps() + for app_name in app_names: + install_dir = os.path.join(spoc_config.APPS_DIR, app_name, 'install') + script_path = os.path.join(install_dir, 'update-conf.sh') + if os.path.exists(script_path): + app_env = env.copy() + app_env['HOST'] = apps[app_name]['host'] + subprocess.run(script_path, cwd=install_dir, env=app_env) + def is_app_started(app_name): # Assume that the main container has always the same name as the app return Container(app_name).get_state() == ContainerState.RUNNING