Skip to content

Commit

Permalink
fix: clean file if no cnames are to be saved
Browse files Browse the repository at this point in the history
  • Loading branch information
Tbaile committed Mar 15, 2024
1 parent eb78101 commit 85cec12
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions imageroot/bin/reload_hosts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import json
import subprocess
import os

import agent
import network
Expand All @@ -30,9 +31,12 @@ if 'interface' in config and config['interface'] != '':

# save a new configuration file for dnsmasq, so that it can resolve the CNAMEs to the node fqdn
redis_client = agent.redis_connect(use_replica=True)
hosts = redis_client.smembers(f'{agent.resolve_agent_id("traefik@node")}/hosts')
# if there are hosts, write them to the file
with open("dnsmasq.d/01cnames.conf", "w") as file:
file.write("# This file is automatically generated by NethServer, manual changes will be lost.\n")
file.write('cname=')
for host in redis_client.smembers(f'{agent.resolve_agent_id("traefik@node")}/hosts'):
file.write(f'{host},')
file.write(f'{fqdn}\n')
file.write("# This file is automatically generated by NethServer, manual changes will be lost.\n")
if len(hosts) > 0:
file.write('cname=')
for host in hosts:
file.write(f'{host},')
file.write(f'{fqdn}\n')

0 comments on commit 85cec12

Please sign in to comment.