summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTollef Fog Heen <tfheen@fastly.com>2014-04-07 10:53:52 +0200
committerTollef Fog Heen <tfheen@err.no>2014-04-07 10:53:52 +0200
commita2198ae35b2ed0332580f11829a860ce9d31100d (patch)
tree08869e99fdc2010574f889ec9f96619605cfefb4
parent6bf7f64162ce4099a6ba70e25a529b599a749fee (diff)
downloadvmdebootstrap-a2198ae35b2ed0332580f11829a860ce9d31100d.tar.gz
Ignore failure to set host name
At least minbase does not end up with an /etc/hosts file, so ignore IOErrors for the hosts file.
-rwxr-xr-xvmdebootstrap17
1 files changed, 10 insertions, 7 deletions
diff --git a/vmdebootstrap b/vmdebootstrap
index 3344a59..a9f9e9b 100755
--- a/vmdebootstrap
+++ b/vmdebootstrap
@@ -292,13 +292,16 @@ class VmDebootstrap(cliapp.Application):
f.write('%s\n' % hostname)
etc_hosts = os.path.join(rootdir, 'etc', 'hosts')
- with open(etc_hosts, 'r') as f:
- data = f.read()
- with open(etc_hosts, 'w') as f:
- for line in data.splitlines():
- if line.startswith('127.0.0.1'):
- line += ' %s' % hostname
- f.write('%s\n' % line)
+ try:
+ with open(etc_hosts, 'r') as f:
+ data = f.read()
+ with open(etc_hosts, 'w') as f:
+ for line in data.splitlines():
+ if line.startswith('127.0.0.1'):
+ line += ' %s' % hostname
+ f.write('%s\n' % line)
+ except IOError, e:
+ pass
def create_fstab(self, rootdir, rootdev, roottype, bootdev, boottype):
def fsuuid(device):