cloud-init should not write comment in /etc/hostname

Bug #1052664 reported by Ben Howard
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
cloud-init (Ubuntu)
Fix Released
Medium
Unassigned

Bug Description

On the desktop builds, the default desktop environment does not respond favorably to having a comment in /etc/hostname -- it inserts "# Created by cloud-init\n" in the bash line.

ubuntu@# cat /etc/hostname
# Created by cloud-init

ubuntu@# Created by cloud-init
ip-10-196-141-203:~$ ls
examples.desktop
ubuntu@# Created by cloud-init
ip-10-196-141-203:~$ ls
examples.desktop
ubuntu@# Created by cloud-init
ip-10-196-141-203:~$ ubuntu-bug cloud-init

Related branches

Revision history for this message
Scott Moser (smoser) wrote :

This *should* be ok, as per 'man hostname':
       -F, --file filename
              Read the host name from the specified file. Comments (lines
              starting with a `#') are ignored.

summary: - 12.10 cloud-init injects comment into /etc/HOSTNAME
+ 12.10 cloud-init injects comment into /etc/hostname
description: updated
Revision history for this message
Scott Moser (smoser) wrote :

and, in fact, that *is* ok:
$ cat /etc/hostname; echo ; echo ==
# Created by cloud-init
domU-12-31-39-02-10-6D
==

$ sudo hostname --file /etc/hostname; echo $?; echo "hostname=$(hostname)"; echo ===
0
hostname=domU-12-31-39-02-10-6D
===
$ sudo hostname -b -F /etc/hostname; echo $?; echo "hostname=$(hostname)"; echo ===
0
hostname=domU-12-31-39-02-10-6D
===
$ sudo hostname -F /etc/hostname; echo $?; echo "hostname=$(hostname)"; echo ===
0
hostname=domU-12-31-39-02-10-6D
===

So something else must be reading that and setting the hostname.

cloud-init log shows:
2012-09-19 14:41:37,523 - util.py[DEBUG]: Writing to /var/lib/cloud/instances/i-7289b008/sem/config-set_hostname - wb: [420] 19 bytes
2012-09-19 14:41:37,531 - helpers.py[DEBUG]: Running config-set_hostname using lock (<FileLock using file '/var/lib/cloud/instances/i-7289b008/sem/config-set_hostname'>)
2012-09-19 14:41:37,531 - cc_set_hostname.py[DEBUG]: Setting hostname to domU-12-31-39-02-10-6D
2012-09-19 14:41:37,531 - util.py[DEBUG]: Writing to /etc/hostname - wb: [420] 46 bytes
2012-09-19 14:41:37,536 - debian.py[DEBUG]: Setting hostname to domU-12-31-39-02-10-6D
2012-09-19 14:41:37,536 - util.py[DEBUG]: Running command ['hostname', 'domU-12-31-39-02-10-6D'] with allowed return codes [0] (shell=False, capture=True)

so it sure looks like *it* is calling hostname corectly.

Revision history for this message
Ben Howard (darkmuggle-deactivatedaccount) wrote :

Regression is between 20120918 and 20120919 Server build, but is on the 20120918 Desktop build.

ubuntu@domU-12-31-39-0C-74-7A:~$ cat /etc/cloud/build.info
build_name: server
serial: 20120918
ubuntu@domU-12-31-39-0C-74-7A:~$ ls
ubuntu@domU-12-31-39-0C-74-7A:~$ cat /etc/hostname

Revision history for this message
Ben Howard (darkmuggle-deactivatedaccount) wrote :

ben@padfoot:/tmp$ diff 20120918.manifest 20120919.manifest
5c5
< apport 2.5.2-0ubuntu1
---
> apport 2.5.2-0ubuntu2
44c44
< debianutils 4.3.2
---
> debianutils 4.3.4
90c90
< iptables 1.4.12-2ubuntu1
---
> iptables 1.4.12-2ubuntu2
208c208
< libpipeline1:amd64 1.2.1-1
---
> libpipeline1:amd64 1.2.2-1
217c217
< libreadline6:amd64 6.2-8
---
> libreadline6:amd64 6.2-9
253,259c253,259
< linux-headers-3.5.0-14 3.5.0-14.19
< linux-headers-3.5.0-14-generic 3.5.0-14.19
< linux-headers-generic 3.5.0.14.14
< linux-headers-virtual 3.5.0.14.14
< linux-image-3.5.0-14-generic 3.5.0-14.19
< linux-image-virtual 3.5.0.14.14
< linux-virtual 3.5.0.14.14
---
> linux-headers-3.5.0-15 3.5.0-15.20
> linux-headers-3.5.0-15-generic 3.5.0-15.20
> linux-headers-generic 3.5.0.15.15
> linux-headers-virtual 3.5.0.15.15
> linux-image-3.5.0-15-generic 3.5.0-15.20
> linux-image-virtual 3.5.0.15.15
> linux-virtual 3.5.0.15.15
270c270
< man-db 2.6.2-1
---
> man-db 2.6.3-1
335c335
< python-serial 2.5-2.1build1
---
> python-serial 2.5-3
347c347
< python3-apport 2.5.2-0ubuntu1
---
> python3-apport 2.5.2-0ubuntu2
354,355c354,355
< python3-problem-report 2.5.2-0ubuntu1
< python3-software-properties 0.92.5
---
> python3-problem-report 2.5.2-0ubuntu2
> python3-software-properties 0.92.6
359c359
< readline-common 6.2-8
---
> readline-common 6.2-9
366c366
< software-properties-common 0.92.5
---
> software-properties-common 0.92.6

Scott Moser (smoser)
summary: - 12.10 cloud-init injects comment into /etc/hostname
+ hostname intermittently contains comment from cloud-init
Revision history for this message
Scott Moser (smoser) wrote : Re: hostname intermittently contains comment from cloud-init

This seems racey. Ben and I both report having sen this on server build of 20120919, but only intermittently.
To add to the oddness, on 20120919 desktop (where it seems to reproduce more frequently), I moved /bin/hostname to /bin/hostname.real, then:
$ cat /bin/hostname
#!/bin/sh

if [ $# -ne 0 ]; then
   {
   echo "== pid=$$ ppid=$PPID JOB=$UPSTART_JOB: $* =="
   cat /proc/$PPID/cmdline
   echo
   } >/run/hostname.log 2>&1
fi
exec /bin/hostname.real "$@"
$ cat /run/hostname.log
== pid=212 ppid=1 JOB=hostname: -b -F /etc/hostname ==
/sbin/init

so during boot the only thing that called /bin/hostname was the upstart job 'hostname'.
However, just running 'sudo hostname -b -F /etc/hostname' behaves correctly.

Revision history for this message
Scott Moser (smoser) wrote :

also:
$ sudo cat /var/log/upstart/hostname.log
hostname: the specified hostname is invalid

Revision history for this message
Scott Moser (smoser) wrote :

reported bug 1053048.
For cloud-init, and my own sanity, i'm going to remove the comment from this file.
Also, it seems that fedora/rh also do things like:

<gholms> HOSTNAME="$(cat /etc/hostname)"
<gholms> hostname "$HOSTNAME"

summary: - hostname intermittently contains comment from cloud-init
+ cloud-init should not write comment in /etc/hostname
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package cloud-init - 0.7.0~bzr659-0ubuntu1

---------------
cloud-init (0.7.0~bzr659-0ubuntu1) quantal; urgency=low

  * New upstream snapshot.
    * add signal handlers to more cleanly exit
    * add logging fallback in case logging fails
    * documentation fix for landscape config (LP: #1042764)
    * do not write a comment in /etc/hostname (LP: #1052664)
    * fix incorrect ubuntu mirrors for 'ports' arches [Robbie Basak]
    * fix generation of hostname based on ip address in datasource
      (LP: #1050962) [Andy Grimm]
    * remove 'start networking' from cloud-init-nonet and replace it
      with container specific fixes (LP: #1031065)
    * fix landscape configuration so client will run (LP: #1042758)
    * enable all available datasources (adding AltCloud and None)
    * fix bug where user data scripts re-ran on upgrade from 10.04 versions
      (LP: #1049146)
 -- Scott Moser <email address hidden> Wed, 19 Sep 2012 22:08:51 -0400

Changed in cloud-init (Ubuntu):
status: Confirmed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.