Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 152955 - HOSTNAME not available in environment
Summary: HOSTNAME not available in environment
Status: RESOLVED WONTFIX
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] baselayout (show other bugs)
Hardware: All Linux
: High normal
Assignee: Gentoo's Team for Core System packages
URL: http://forums.gentoo.org/viewtopic-p-...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-10-27 03:11 UTC by Hans Rakers
Modified: 2006-10-30 03:39 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Hans Rakers 2006-10-27 03:11:43 UTC
Running baselayout-1.12.5-r2

IMO a bit too much "crud" was removed from /etc/init.d/hostname in the following revision:

http://sources.gentoo.org/viewcvs.py/baselayout/branches/baselayout-1_12/init.d/hostname?r1=1781&r2=1954

This change results in HOSTNAME not being available in the environment. I temporarily worked around the issue by manually creating a /etc/env.d/01hostname on all my Gentoo boxes that need it.

AFAIK a whole bunch of scripts and apps expect HOSTNAME to be available in the env. Would be neat if something could be re-added to the init scripts to autocreate 01hostname again.
Comment 1 Roy Marples (RETIRED) gentoo-dev 2006-10-27 03:27:22 UTC
If your shell is bash then it sets HOSTNAME correctly.
Otherwise you should be using the hostname program in /usr/bin

Which particular scripts or apps are giving you a problem?
Comment 2 Hans Rakers 2006-10-27 04:18:02 UTC
Shell is bash. 

fe1 ~ # ls -al /bin/sh
lrwxrwxrwx 1 root root 4 Sep 27 14:20 /bin/sh -> bash

bash-3.1_p17  USE="nls -afs -bashlogger -vanilla"

But AFAIK bash doesn't just automagically set HOSTNAME, you need to tell it to do so in /etc/profile. HOSTNAME does appear in 'set' but not in 'env'. Previous behaviour was that HOSTNAME was exported to the env, but since the above mentioned change it doesn't get exported anymore.

We use HOSTNAME in one of our webapps for logging (accessed by PHP through $_ENV['HOSTNAME']), and for adding X-Served-By headers to apache responses in a webfarm env. using mod_headers.
But since its pretty standard to have HOSTNAME in the env. i would assume there are more scripts and apps out there that depend on this, and to be honest i don't see any reason why not to have it (all the other distro's i work with on  a daily basis do so aswell, being Slackware, CentOS and Debian)
Comment 3 Roy Marples (RETIRED) gentoo-dev 2006-10-27 04:46:04 UTC
(In reply to comment #2)
> Shell is bash. 
> 
> fe1 ~ # ls -al /bin/sh
> lrwxrwxrwx 1 root root 4 Sep 27 14:20 /bin/sh -> bash
> 
> bash-3.1_p17  USE="nls -afs -bashlogger -vanilla"
> 
> But AFAIK bash doesn't just automagically set HOSTNAME

bash does set the HOSTNAME, check the man pages
However, it does not export it to daemons by default so if that is required then you can do this

export HOSTNAME

in each init script that requires it. That should also work in conf.d too, which means it's fully under your control.

> We use HOSTNAME in one of our webapps for logging (accessed by PHP through
> $_ENV['HOSTNAME'])

Great! What happens if the hostname changes?

> But since its pretty standard to have HOSTNAME in the env. i would assume there
> are more scripts and apps out there that depend on this, and to be honest i
> don't see any reason why not to have it

Having it set caused a few issues, as it couldn't be magically unset. And to be honest, it's been unset for a while now and my servers haven't noticed it not being there any longer.
Comment 4 Hans Rakers 2006-10-27 05:29:05 UTC
(In reply to comment #3)
> > We use HOSTNAME in one of our webapps for logging (accessed by PHP through
> > $_ENV['HOSTNAME'])
> 
> Great! What happens if the hostname changes?

It doesn't. Its not my idea of fun to go around changing hostnames all the time, and when it does change its probably because the machine is going to get a different task, and i'll probably at least reboot it. And this is totally besides the point.

> Having it set caused a few issues, as it couldn't be magically unset. And to be
> honest, it's been unset for a while now and my servers haven't noticed it not
> being there any longer.

I'd like to know what problems those were, since this is a totally standard env var.

ATM, I personally don't see a valid reason why Gentoo should deviate from a path that has been standard across a whole bunch of distros like Slackware, Debian, CentOS/RHEL/Fedora, Mandriva etc. for years.
Comment 5 SpanKY gentoo-dev 2006-10-27 10:57:57 UTC
why dont you try adding HOSTNAME to /etc/conf.d/env_whitelist
Comment 6 Hans Rakers 2006-10-30 00:34:30 UTC
(In reply to comment #5)
> why dont you try adding HOSTNAME to /etc/conf.d/env_whitelist
> 

It is already in env_whitelist, but that won't matter much when the var doesn't get exported during init anymore. /etc/init.d/hostname used to create a /etc/env.d/01hostname on the fly during boot, but that was removed in revision http://sources.gentoo.org/viewcvs.py/baselayout/branches/baselayout-1_12/init.d/hostname?r1=1781&r2=1954
Comment 7 Roy Marples (RETIRED) gentoo-dev 2006-10-30 03:10:47 UTC
Or you could write some simple php to get the hostname which works on any *NIX.

$SERVER_NAME = $_SERVER["SERVER_NAME"];
$IP = gethostbyname ($SERVER_NAME);
$server = gethostbyaddr($IP);
echo "<br>Server IP: $IP";
echo "<br>Server Name: $server";
Comment 8 Hans Rakers 2006-10-30 03:15:33 UTC
(In reply to comment #7)
> Or you could write some simple php to get the hostname which works on any *NIX.
> 
> < snap >

Yea that'll perform really well, a gethostbyname on every hit...
Comment 9 Roy Marples (RETIRED) gentoo-dev 2006-10-30 03:39:42 UTC
(In reply to comment #8)
> Yea that'll perform really well, a gethostbyname on every hit...

So cache it then.
Or do what I said and put "export HOSTNAME" in /etc/conf.d/apache2.

Look, HOSTNAME env var is not a POSIX shell standard and afaik only some Linux based systems set it so it was kind of silly to rely on it.