From 0ddeae9770d6af1448fd6fd72b218fff1f5f7113 Mon Sep 17 00:00:00 2001 From: ofreax Date: Sat, 31 Oct 2015 21:38:03 +0100 Subject: [PATCH] v0.1.3 --- image/tool/my_init | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/image/tool/my_init b/image/tool/my_init index 169ab6aa..c194461f 100755 --- a/image/tool/my_init +++ b/image/tool/my_init @@ -64,9 +64,16 @@ def xstr(s): return str(s) def set_env_hostname_to_etc_hosts(): - if "HOSTNAME" in os.environ and socket.gethostname() and os.environ["HOSTNAME"] != socket.gethostname(): - with open("/etc/hosts", "a") as myfile: - myfile.write("127.0.0.1 "+os.environ["HOSTNAME"]+"\n") + + if "HOSTNAME" in os.environ: + with open('/etc/hostname', 'r') as f: + etc_hostname = f.readline().rstrip() + + ip_address = socket.gethostbyname(etc_hostname) + + if os.environ["HOSTNAME"] != etc_hostname: + with open("/etc/hosts", "a") as myfile: + myfile.write(ip_address+" "+os.environ["HOSTNAME"]+"\n") def python_dict_to_bash_envvar(name, python_dict):