Skip to content

Commit

Permalink
Merge pull request #292 from antonlacon/hostnames
Browse files Browse the repository at this point in the history
hostname.py: use network-base.service for /etc/hosts editing
  • Loading branch information
CvH authored May 9, 2023
2 parents 47655f3 + 9498f75 commit 458469c
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions resources/lib/hostname.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ def get_hostname():


def set_hostname(hostname):
with open(config.HOSTNAME, 'w') as output:
output.write(hostname)
with open('/proc/sys/kernel/hostname', 'w') as output:
output.write(hostname)
with open('/etc/hosts', 'w') as output:
if os.path.isfile(config.HOSTS_CONF):
with open(config.HOSTS_CONF) as input:
output.write(input.read())
output.write(f'127.0.0.1 localhost {hostname}\n')
output.write(f'::1 localhost ip6-localhost ip6-loopback {hostname}\n')
# network-base.service handles user created persistent settings
if os.path.isfile(config.HOSTNAME):
with open(config.HOSTNAME, 'r') as input:
current_hostname = input.read().strip()
if current_hostname != hostname:
with open(config.HOSTNAME, 'w') as output:
output.write(hostname)
os_tools.execute('systemctl restart network-base')

0 comments on commit 458469c

Please sign in to comment.