Run update-conf.sh when appropriate

This commit is contained in:
Disassembler 2020-04-10 13:02:15 +02:00
parent 8bc64a6493
commit 2d788eb704
No known key found for this signature in database
GPG Key ID: 524BD33A0EE29499

View File

@ -23,6 +23,7 @@ def register_app(app, host, login, password):
'visible': False, 'visible': False,
}) })
register_proxy(app) register_proxy(app)
update_app_config(app)
def unregister_app(app): def unregister_app(app):
unregister_proxy(app) unregister_proxy(app)
@ -54,6 +55,7 @@ def update_host(domain, port):
f.write(templates.NGINX_DEFAULT.format(port=port, domain=domain)) f.write(templates.NGINX_DEFAULT.format(port=port, domain=domain))
for app in config.get_apps().keys(): for app in config.get_apps().keys():
register_proxy(app) register_proxy(app)
update_app_config()
def reload_nginx(): def reload_nginx():
subprocess.run(['/usr/sbin/nginx', '-s', 'reload']) subprocess.run(['/usr/sbin/nginx', '-s', 'reload'])
@ -76,6 +78,7 @@ def update_common_settings(email, gmaps_api_key):
# Update common configuration values # Update common configuration values
config.set_common('email', email) config.set_common('email', email)
config.set_common('gmaps-api-key', gmaps_api_key) config.set_common('gmaps-api-key', gmaps_api_key)
update_app_config()
def update_password(oldpassword, newpassword): def update_password(oldpassword, newpassword):
# Update LUKS password and adminpwd for WSGI application # 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 # Add/remove the app to OpenRC default runlevel
App(app_name, False).set_autostart(enabled) 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): def is_app_started(app_name):
# Assume that the main container has always the same name as the app # Assume that the main container has always the same name as the app
return Container(app_name).get_state() == ContainerState.RUNNING return Container(app_name).get_state() == ContainerState.RUNNING