Bug 883999 - hostname lost while zypper dup from 13.1 to Factory or zypper dup of Factory
Summary: hostname lost while zypper dup from 13.1 to Factory or zypper dup of Factory
Status: RESOLVED FIXED
Alias: None
Product: openSUSE Tumbleweed
Classification: openSUSE
Component: Basesystem (show other bugs)
Version: 13.2 Milestone 0
Hardware: x86-64 openSUSE 13.2
: P2 - High : Major (vote)
Target Milestone: ---
Assignee: Petr Gajdos
QA Contact: E-mail List
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-06-24 12:09 UTC by Lars Müller
Modified: 2014-10-02 11:56 UTC (History)
5 users (show)

See Also:
Found By: Development
Services Priority:
Business Priority:
Blocker: No
Marketing QA Status: ---
IT Deployment: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Lars Müller 2014-06-24 12:09:09 UTC
lmuelle@hip:~> LC_ALL=POSIX ls -l /etc/{hostname,HOSTNAME}
lrwxrwxrwx 1 root root  8 Jun 20 20:18 /etc/HOSTNAME -> hostname
-rw-r--r-- 1 root root 11 Jun 18 11:01 /etc/hostname
lmuelle@hip:~> cat /etc/hostname 
linux.site

There is no rpmsave while /etc/HOSTNAME before was set to hip.suse.de
Comment 1 Petr Gajdos 2014-06-24 14:59:09 UTC
So the /etc/HOSTNAME link should be marked as %config, correct?
Comment 2 Felix Miata 2014-06-26 02:31:54 UTC
On Factory installation last dup'd 5 weeks ago, HOSTNAME was replaced with symlink to hostname containing linux.site without regard to original content of HOSTNAME during today's zypper dup (4 bit host hs80e).
Comment 3 Petr Gajdos 2014-06-26 15:03:10 UTC
%pre
if [ "0$1" -ge "2" ]; then
  if [ -f /etc/HOSTNAME -a ! -h /etc/HOSTNAME ]; then
    if [ -f /etc/hostname ]; then
      mv /etc/hostname /etc/hostname.rpmsave
    fi
    mv /etc/HOSTNAME /etc/HOSTNAME.rpmsave
  fi
fi

%post
if [ -f /etc/HOSTNAME.rpmsave ]; then
  cp /etc/HOSTNAME.rpmsave /etc/hostname
fi

could work?
Comment 4 Petr Gajdos 2014-06-27 10:27:47 UTC
Standa Brabec pointed out that there can be various setups according to /etc/{HOSTNAME,hostname} on the original system before the update. I tested %pre/%post from comment 3 like this:

(1) There is /etc/HOSTNAME only.
--------------------------------
$ ls -l /etc | grep -i hostname
-rw-r--r--  1 root root         11 Jun 26 12:44 HOSTNAME
$ echo bleble > /etc/HOSTNAME
$ rpm -Uhv netcfg-11.5-0.noarch.rpm --force
$ ls -l /etc | grep -i hostname
lrwxrwxrwx  1 root root          8 Jun 27 09:50 HOSTNAME -> hostname
-rw-r--r--  1 root root          7 Jun 27 09:47 HOSTNAME.rpmsave
-rw-r--r--  1 root root          7 Jun 27 09:50 hostname
$ cat /etc/hostname
bleble

(2) There is /etc/HOSTNAME and /etc/hostname link to /etc/HOSTNAME.
-------------------------------------------------------------------
$  ls -l /etc | grep -i hostname
-rw-r--r--  1 root root          7 Jun 27 10:01 HOSTNAME
lrwxrwxrwx  1 root root         13 Jun 27 10:02 hostname -> /etc/HOSTNAME
$ echo bleble > /etc/HOSTNAME
$ rpm -Uhv netcfg-11.5-0.noarch.rpm --force
$ ls -l /etc | grep -i hostname
lrwxrwxrwx  1 root root          8 Jun 27 10:04 HOSTNAME -> hostname
-rw-r--r--  1 root root          7 Jun 27 10:02 HOSTNAME.rpmsave
-rw-r--r--  1 root root          7 Jun 27 10:04 hostname
-rw-r--r--  1 root root         11 Jun 27 09:13 hostname.rpmnew
lrwxrwxrwx  1 root root         13 Jun 27 10:02 hostname.rpmsave -> /etc/HOSTNAME
alef:/> cat /etc/hostname
bleble

(3) There is /etc/HOSTNAME and /etc/hostname, both regular files.
-----------------------------------------------------------------
Unlikely, /etc/HOSTNAME and /etc/hostname can differ but that would mean conflict between them.
$  ls -l /etc | grep -i hostname
-rw-r--r--  1 root root         16 Jun 27 10:09 HOSTNAME
-rw-r--r--  1 root root         16 Jun 27 10:09 hostname
$ echo bleble.HOSTNAME > /etc/HOSTNAME
$ echo bleble.hostname > /etc/hostname
$ rpm -Uhv netcfg-11.5-0.noarch.rpm --force
$ ls -l /etc | grep -i hostname
lrwxrwxrwx  1 root root          8 Jun 27 10:11 HOSTNAME -> hostname
-rw-r--r--  1 root root         16 Jun 27 10:09 HOSTNAME.rpmsave
-rw-r--r--  1 root root         16 Jun 27 10:11 hostname
-rw-r--r--  1 root root         11 Jun 27 09:13 hostname.rpmnew
-rw-r--r--  1 root root         16 Jun 27 10:09 hostname.rpmsave
$ cat /etc/hostname
bleble.HOSTNAME

(4) There is /etc/hostname and /etc/HOSTNAME, link to /etc/hostname.
--------------------------------------------------------------------
$ ls -l /etc | grep -i hostname
lrwxrwxrwx  1 root root         13 Jun 27 10:18 HOSTNAME -> /etc/hostname
-rw-r--r--  1 root root         11 Jun 26 12:44 hostname
$ echo bleble > /etc/hostname
$ ls -l /etc | grep -i hostname
lrwxrwxrwx  1 root root          8 Jun 27 10:21 HOSTNAME -> hostname
lrwxrwxrwx  1 root root         13 Jun 27 10:18 HOSTNAME.rpmsave -> /etc/hostname
-rw-r--r--  1 root root          7 Jun 27 10:19 hostname
-rw-r--r--  1 root root         11 Jun 27 09:13 hostname.rpmnew
$ cat /etc/hostname
bleble

Does that serve our purpose? Or is there another scenario which would fail?
Comment 5 Petr Gajdos 2014-06-27 10:30:13 UTC
Standa Brabec suggested yesterday:

%pre
if [ "0$1" -ge "2" ]; then
  if [ -f /etc/HOSTNAME -a ! -h /etc/HOSTNAME ]; then
    mv /etc/HOSTNAME /etc/HOSTNAME.rpmsave
  fi
  if [ -h /etc/hostname ]; then
    rm /etc/hostname
  fi
  if [ -f /etc/hostname ]; then
    touch /etc/hostname.stamp
  fi
fi

%post
if [ -f /etc/HOSTNAME.rpmsave ]; then
  if [ -f /etc/hostname.stamp ]; then
    rm /etc/hostname.stamp
    if cmp -s /etc/hostname /etc/HOSTNAME.rpmsave; then
      rm /etc/HOSTNAME.rpmsave
    else
      echo "/etc/hostname and /etc/HOSTNAME conflicted before installation" >&2
      echo "/etc/hostname saved into /etc/hostname.rpmsave" >&2
      mv /etc/hostname /etc/hostname.rpmsave
      mv /etc/HOSTNAME.rpmsave /etc/hostname
    fi
  else
    mv /etc/hostname /etc/hostname.rpmnew
    mv /etc/HOSTNAME.rpmsave /etc/hostname
  fi
else
  # should not happen
  rm /etc/hostname.stamp
fi
Comment 7 Felix Miata 2014-06-27 10:57:24 UTC
1: cf. Bug 872264

2: I don't see the following covered by the proposal:
-rw-r--r-- 2 root root    13 Dec  23  2013 HOSTNAME
-rw-r--r-- 2 root root    13 Dec  23  2013 hostname

3: Why not a hard link of hostname to existing HOSTNAME?

4: One of my pet peeves routinely violated by zypper and yast activity is any file whose content before touching is identical to that after touching and my finding the original timestamp has not survived along with the original content. This very irritating behavior happens constantly to /etc/fstab and various files in /etc/sysconfig/ among others, mostly in the /etc/ tree. Would the renaming of /etc/HOSTNAME to /etc/hostname be another as a result of the proposal?
Comment 8 Stanislav Brabec 2014-06-27 16:40:02 UTC
2. The script in the comment 5 should handle it:

%pre
    mv /etc/HOSTNAME /etc/HOSTNAME.rpmsave

%post
      rm /etc/HOSTNAME.rpmsave

(After installation, /etc/HOSTNAME will be a symlink.

3. Maybe it is possible as well. But some editors will break the hard link.

4. Time stamp of /etc/HOSTNAME should survive in /etc/hostname.
Comment 9 Felix Miata 2014-07-03 07:07:35 UTC
In order to not have a current timestamp polluting either HOSTNAME or hostname, before doing upgrades  I set a hard link from HOSTNAME to hostname, then set HOSTNAME immutable. This halts the upgrade process until I tell it to ignore its inability to create a new HOSTNAME with a current timestamp.
Comment 10 Petr Gajdos 2014-07-21 07:23:58 UTC
Guys,

The change /etc/HOSTNAME -> /etc/hostname + symlink /etc/HOSTNAME do not come from netcfg package, so discussion if it should be hardlink and why we don't maintain timestamps do not belong to this bug, at least to my understanding. See bug 858908 for the reference.
Comment 11 Petr Gajdos 2014-07-21 07:25:34 UTC
(In reply to comment #10)
> The change /etc/HOSTNAME -> /etc/hostname + symlink /etc/HOSTNAME do not come

not come == not initiated by
Comment 12 Petr Gajdos 2014-07-21 08:24:21 UTC
(In reply to comment #7)
> 2: I don't see the following covered by the proposal:
> -rw-r--r-- 2 root root    13 Dec  23  2013 HOSTNAME
> -rw-r--r-- 2 root root    13 Dec  23  2013 hostname

What exactly do you think by 'not covered'? That the hardlink hierarchy is not maintained during the update?
Comment 13 Felix Miata 2014-07-21 08:55:24 UTC
(In reply to comment #12)
> What exactly do you think by 'not covered'? That the hardlink hierarchy is not
> maintained during the update?

Yes. Given the extent to which various unchanged config files in the /etc tree get new timestamps when various package updates occur, it would not surprise me, hence the question. What bothers me more is absent using a hardlink between the two, HOSTNAME gets a new create date when hostname gets "created" via mv to HOSTNAME. If it was up to me, the update process would hard link instead of moving, creating a soft link, and leaving behind litter in the form of an .rpmsave or .rpmnew. Better still would be to do no more than a rename, period, dispensing with the HOSTNAME that is pointlessly unique among major distros to openSUSE/SLEx.
Comment 14 Petr Gajdos 2014-07-24 11:30:00 UTC
Is that better?

%pre
if [ "0$1" -ge "2" ]; then
  if [ -f /etc/HOSTNAME -a ! -L /etc/HOSTNAME ]; then
    if [ -f /etc/hostname ]; then
      mv /etc/hostname /etc/hostname.rpmsave
    fi
    ln -f /etc/HOSTNAME /etc/HOSTNAME.rpmsave
    rm /etc/HOSTNAME
  fi
fi

%post
if [ -f /etc/HOSTNAME.rpmsave -a ! -L /etc/HOSTNAME.rpmsave ]; then
  cp -a /etc/HOSTNAME.rpmsave /etc/hostname
fi

As far as I tested (similarly like summarized in comment 4): 

before update:
==============
 # | /etc/HOSTNAME | /etc/hostname | probability
---|--------------------------------------------
1. |    regular    |      -        |  very high
2. |      -        |   regular     |  very low
3. |    regular    |   symlink     |    high
4. |    symlink    |   regular     |  very low
5. |    regular    |   regular     |  very low
6. |    hardlink   |   hardlink    |    high

after update:
=============
1.
lrwxrwxrwx  1 root root          8 Jul 24 09:21 HOSTNAME -> hostname
-rw-r--r--  1 root root          7 Jul 24 09:19 HOSTNAME.rpmsave
-rw-r--r--  1 root root          7 Jul 24 09:19 hostname
hostname and HOSTNAME.rpmsave have content and timestamp of original HOSTNAME

2.
lrwxrwxrwx  1 root root          8 Jul 23 13:25 HOSTNAME -> hostname
-rw-r--r--  1 root root          7 Jul 23 13:24 hostname
-rw-r--r--  1 root root         11 Jul 23 13:09 hostname.rpmnew
hostname untouched

3.
lrwxrwxrwx  1 root root          8 Jul 24 09:39 HOSTNAME -> hostname
-rw-r--r--  1 root root          7 Jul 24 09:38 HOSTNAME.rpmsave
-rw-r--r--  1 root root          7 Jul 24 09:38 hostname
-rw-r--r--  1 root root         11 Jul 24 08:51 hostname.rpmnew
lrwxrwxrwx  1 root root         13 Jul 24 09:38 hostname.rpmsave -> /etc/HOSTNAME
hostname carries the content and timestamp of original HOSTNAME

4.
lrwxrwxrwx  1 root root          8 Jul 24 08:55 HOSTNAME -> hostname
lrwxrwxrwx  1 root root         13 Jul 24 08:54 HOSTNAME.rpmsave -> /etc/hostname
-rw-r--r--  1 root root          7 Jul 24 08:54 hostname
-rw-r--r--  1 root root         11 Jul 24 08:51 hostname.rpmnew
hostname carries the content and timestamp of original HOSTNAME

5.
lrwxrwxrwx  1 root root          8 Jul 24 09:46 HOSTNAME -> hostname
-rw-r--r--  1 root root         16 Jul 24 09:44 HOSTNAME.rpmsave
-rw-r--r--  1 root root         16 Jul 24 09:44 hostname
-rw-r--r--  1 root root         11 Jul 24 08:51 hostname.rpmnew
-rw-r--r--  1 root root         16 Jul 24 09:45 hostname.rpmsave
*.rpmsave carry contents and timestamps of respective originals
hostname carries contents and timestamp of original HOSTNAME

6.
lrwxrwxrwx  1 root root          8 Jul 24 09:54 HOSTNAME -> hostname
-rw-r--r--  2 root root          7 Jul 24 09:53 HOSTNAME.rpmsave
-rw-r--r--  1 root root          7 Jul 24 09:53 hostname
-rw-r--r--  1 root root         11 Jul 24 08:51 hostname.rpmnew
-rw-r--r--  2 root root          7 Jul 24 09:53 hostname.rpmsave
hostname and *rpmsave carry content and timestamp of original
file
Comment 15 Petr Gajdos 2014-07-24 12:12:54 UTC
Needinfo provided personally.
Comment 16 Petr Gajdos 2014-07-25 07:19:06 UTC
*** Bug 887039 has been marked as a duplicate of this bug. ***
Comment 17 Petr Gajdos 2014-07-25 10:55:51 UTC
Package submitted. Please test. If you meet any other problem which I can resolve on netcfg side, please let me know.
Comment 18 Bernhard Wiedemann 2014-07-25 11:00:16 UTC
This is an autogenerated message for OBS integration:
This bug (883999) was mentioned in
https://build.opensuse.org/request/show/242350 Factory / netcfg
Comment 20 Felix Miata 2014-07-29 01:12:33 UTC
Last 2-3 systems upgraded with HOSTNAME and hostname hard linked survived intact, but I just did host g5eas where HOSTNAME and hostname were hard linked to start with, and afterward HOSTNAME was a currently timestamped symlink to hostname. When I deleted the symlink and recreated the hard link, I wound up with 3 links total, the third to hostname.rpmsave, which I've now deleted.
Comment 21 Felix Miata 2014-08-06 03:40:59 UTC
Ditto, sort of, comment 20 on host gx62b which was last dup'd 24 July. This time there were HOSTNAME.rpmsave and hostname.rpmsave preserved as hard links (to each other?), with timestamp of hostname preserved and with no hard links, while HOSTNAME was a current timestamped symlink to hostname.
Comment 22 Felix Miata 2014-08-17 06:30:12 UTC
netcfg-11.5-23.1 refuses to install when hostname exists as immutable hard link to HOSTNAME