We are usning pxeboot+nfs+dhcp to boot our machines. The hostname is assigned by dhcp (kernel-dhcp). So the hostname is correct direcly after the kernel has started the network. Your script checks /etc/hostname and sets hostname to localhost since /etc/hostname does not exist. (We use the same /etc to boot multiple machines). With the attached patch this works correctly. WARNING: i could not yet test if this breaks on a localy booting machine. patch: --- /etc/init.d/hostname.org 2004-01-14 15:10:43.433484680 +0100 +++ /etc/init.d/hostname 2004-01-14 15:13:48.000000000 +0100 @@ -19,7 +19,10 @@ checkconfig() { if [ ! -f /etc/hostname ] || [ -z "$(< /etc/hostname)" ] then - eerror "You need to set /etc/hostname to a valid hostname" + if [ -n"`/bin/hostname`" ] + then + eerror "You need to set /etc/hostname to a valid hostname" + fi return 1 fi } @@ -43,8 +46,13 @@ if checkconfig then myhost="$(< /etc/hostname)" + else + if [ -n"`/bin/hostname`" ] + then + myhost="`/bin/hostname`" + fi fi - + ebegin "Setting hostname to ${myhost}" /bin/hostname "${myhost}" retval=$?
I discovered a small typo: + if [ -n"`/bin/hostname`" ] + then + eerror "You need to set /etc/hostname to a valid hostname" + fi must read: + if [ -z"`/bin/hostname`" ] + then + eerror "You need to set /etc/hostname to a valid hostname" + fi
*** Bug 41888 has been marked as a duplicate of this bug. ***
the behavior in cvs is now: if /etc/hostname is setup, then that value will be used if /etc/hostname is not setup, and /bin/hostname returns "" or "(none)", then the hostname will be set to 'localhost', otherwise if /bin/hostname returns something, that value wont be screwed around with
Are you guys sure this bug is resolved? Below is the code from stage3-pentium4-2005.1-r1.tar.bz2:/etc/init.d/hostname Problem: Looks like hostname is set to ${myhost} no matter what on line 27. myhost is set on lines 10, 16, 21, and 23. But the last two reside within opposite parts of an if-else clause, so myhost will ALWAYS be set to one of those two values, ignoring the values set on lines 10 or 16. Fix: Lines 10-17 should be removed. Alternativly, insert at line 25 the following: local kernelhost=$(/bin/hostname 2>/dev/null) if [[ -n ${kernelhost} ]] && [[ ! ${myhost} == "(none)" ]] ; then myhost="${kernelhost}" fi if [ -z "${myhost}" ] ; then myhost="localhost" fi stage3-pentium4-2005.1-r1.tar.bz2:/etc/init.d/hostname: 09 start() { 10 local myhost=$(/bin/hostname 2>/dev/null) 11 local retval=0 12 13 # If the hostname is already set via the kernel, and /etc/hostname 14 # isn't setup, then we shouldn't go reseting the configuration #38172. 15 if [[ -z ${myhost} ]] || [[ ${myhost} == "(none)" ]] ; then 16 myhost="localhost" 17 fi 18 19 if [[ -f /etc/hostname ]] ; then 20 ewarn "You should stop using /etc/hostname and use /etc/conf.d/hostname" 21 myhost=$(</etc/hostname) 22 else 23 myhost=${HOSTNAME} 24 fi 25 26 ebegin "Setting hostname to ${myhost}" 27 /bin/hostname "${myhost}" 28 retval=$? 29 eend ${retval} "Failed to set the hostname" 30 31 if [[ ${retval} -eq 0 ]] ; then 32 # setup $HOSTNAME, ignore errors in case /etc is readonly. 33 echo "HOSTNAME=\"${myhost}\"" 2>/dev/null > /etc/env.d/01hostname 34 fi 35 36 return ${retval} 37 }