fixed bug regarding the cleanup of old proxy configs

This commit is contained in:
Joachim Lusiardi 2017-01-22 10:00:43 +01:00
parent c0c94fa75a
commit 9ccb16d88d

View File

@ -131,9 +131,13 @@ def handle_container(id):
with open(target_path + '/proxy_{id}_{code}'.format(id=id,code=env_key), 'w') as file:
if substitutes['location'] == '':
del substitutes['location']
file.write(Template(non_location_template).substitute(substitutes))
logging.info(Template(non_location_template).safe_substitute(substitutes))
file.write(Template(non_location_template).safe_substitute(substitutes))
else:
file.write(Template(location_template).substitute(substitutes))
# make sure we have a name for the redirect
substitutes['name'] = substitutes['names'].split(' ')[0]
logging.info(Template(location_template).safe_substitute(substitutes))
file.write(Template(location_template).safe_substitute(substitutes))
def reload_nginx_configuration():
@ -221,9 +225,14 @@ if __name__ == '__main__':
ip = ''
if ip == '':
logging.info('removing %sproxy_%s', target_path, container_id)
if os.path.exists(target_path + 'proxy_' + container_id):
os.remove(target_path + 'proxy_' + container_id)
logging.info('removing data for container %s', container_id)
# since a container can expose multiple ports per PROXY_DATA it
# will generate multiple files. All names contain the container id.
# This will be used to delete all relevant files for a container
for filename in os.listdir(target_path):
if container_id in filename:
logging.info('removing file %s%s', target_path, container_id)
os.remove(target_path + filename)
else:
handle_container(container_id)