Modularize proxy registration
This commit is contained in:
parent
9f02c98d1b
commit
5facbb1b35
@ -221,22 +221,21 @@ class VMMgr:
|
||||
app = os.environ['LXC_NAME']
|
||||
tools.update_hosts_lease(None, app)
|
||||
|
||||
def register_proxy(self, app):
|
||||
def register_proxy(self, app, reload_nginx=True):
|
||||
# Rebuild nginx configuration using IP of referenced app container and reload nginx
|
||||
if not validator.is_valid_app(app, self.conf):
|
||||
raise validator.InvalidValueException('app', app)
|
||||
self.update_proxy_conf(app, tools.get_container_ip(app))
|
||||
tools.reload_nginx()
|
||||
|
||||
def update_proxy_conf(self, app, ip):
|
||||
ip = tools.get_container_ip(app)
|
||||
with open(os.path.join(NGINX_DIR, '{}.conf'.format(app)), 'w') as f:
|
||||
f.write(NGINX_TEMPLATE.format(app=app, host=self.conf['apps'][app]['host'], ip=ip, domain=self.domain, port=self.port))
|
||||
if reload_nginx:
|
||||
tools.reload_nginx()
|
||||
|
||||
def unregister_proxy(self, app):
|
||||
# Remove nginx configuration to prevent proxy mismatch when the container IP is reassigned to another container
|
||||
if not validator.is_valid_app(app, self.conf):
|
||||
raise validator.InvalidValueException('app', app)
|
||||
self.update_proxy_conf(app, tools.NULL_IP)
|
||||
os.unlink(os.path.join(NGINX_DIR, '{}.conf'.format(app)))
|
||||
tools.reload_nginx()
|
||||
|
||||
def update_host(self, domain, port, restart_nginx=True):
|
||||
@ -255,9 +254,10 @@ class VMMgr:
|
||||
# Rebuild nginx config for the portal app
|
||||
with open(os.path.join(NGINX_DIR, 'default.conf'), 'w') as f:
|
||||
f.write(NGINX_DEFAULT_TEMPLATE.format(port=self.port))
|
||||
# Unregister nginx proxy for apps (will be repopulated on app restart)
|
||||
# Re-register nginx proxy for running apps
|
||||
for app in self.conf['apps']:
|
||||
self.update_proxy_conf(app, tools.NULL_IP)
|
||||
if tools.is_service_started(app):
|
||||
self.register_proxy(app, False)
|
||||
# Restart nginx to properly bind the new listen port
|
||||
if restart_nginx:
|
||||
tools.restart_nginx()
|
||||
|
Loading…
Reference in New Issue
Block a user