rfc: /etc/hostname on gentoo

classic Classic list List threaded Threaded
56 messages Options
123
Reply | Threaded
Open this post in threaded view
|

rfc: /etc/hostname on gentoo

William Hubbs
All,

it looks like app-emulation/docker expects /etc/hostname to exist.

On Gentoo, this file does not exist, so I'm wondering how we can make it
exist?

I know in OpenRC I can read it and use the value there as the hostname
instead of /etc/conf.d/hostname if it exists,but I'm not sure whether
OpenRC should populate /etc/hostname if it does not exist or whether
something else should do that.

Thoughts?

William


signature.asc (188 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: rfc: /etc/hostname on gentoo

M. J. Everitt
On 22/08/16 16:58, William Hubbs wrote:

> All,
>
> it looks like app-emulation/docker expects /etc/hostname to exist.
>
> On Gentoo, this file does not exist, so I'm wondering how we can make it
> exist?
>
> I know in OpenRC I can read it and use the value there as the hostname
> instead of /etc/conf.d/hostname if it exists,but I'm not sure whether
> OpenRC should populate /etc/hostname if it does not exist or whether
> something else should do that.
>
> Thoughts?
>
> William
>
Sym-link it perhaps? Making another file could make synchronisation, etc
a headache....


signature.asc (919 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: rfc: /etc/hostname on gentoo

Rich Freeman
On Mon, Aug 22, 2016 at 12:11 PM, M. J. Everitt <[hidden email]> wrote:

> On 22/08/16 16:58, William Hubbs wrote:
>>
>> it looks like app-emulation/docker expects /etc/hostname to exist.
>>
>> On Gentoo, this file does not exist, so I'm wondering how we can make it
>> exist?
>>
>> I know in OpenRC I can read it and use the value there as the hostname
>> instead of /etc/conf.d/hostname if it exists,but I'm not sure whether
>> OpenRC should populate /etc/hostname if it does not exist or whether
>> something else should do that.
>>
> Sym-link it perhaps? Making another file could make synchronisation, etc
> a headache....
>

Systemd has generally been going the route of symlinking files like
these to files in /run.  That might be an approach that would work for
openrc as well.  It also eliminates giving write-access to /etc to
things like dhcpd.

--
Rich

Reply | Threaded
Open this post in threaded view
|

Re: rfc: /etc/hostname on gentoo

William Hubbs
On Mon, Aug 22, 2016 at 12:39:03PM -0400, Rich Freeman wrote:

> On Mon, Aug 22, 2016 at 12:11 PM, M. J. Everitt <[hidden email]> wrote:
> > On 22/08/16 16:58, William Hubbs wrote:
> >>
> >> it looks like app-emulation/docker expects /etc/hostname to exist.
> >>
> >> On Gentoo, this file does not exist, so I'm wondering how we can make it
> >> exist?
> >>
> >> I know in OpenRC I can read it and use the value there as the hostname
> >> instead of /etc/conf.d/hostname if it exists,but I'm not sure whether
> >> OpenRC should populate /etc/hostname if it does not exist or whether
> >> something else should do that.
> >>
> > Sym-link it perhaps? Making another file could make synchronisation, etc
> > a headache....
> >
>
> Systemd has generally been going the route of symlinking files like
> these to files in /run.  That might be an approach that would work for
> openrc as well.  It also eliminates giving write-access to /etc to
> things like dhcpd.
I'm not sure about putting this in /run for a couple of reasons:

The contents of this file is a setting, like /etc/conf.d/hostname, which
will be set by the user.

The other reason is, I don't know enough about containers to know if
they will have a separate /run from the host.

William

signature.asc (188 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: rfc: /etc/hostname on gentoo

Michael Orlitzky
In reply to this post by William Hubbs
On 08/22/2016 11:58 AM, William Hubbs wrote:
> All,
>
> it looks like app-emulation/docker expects /etc/hostname to exist.
>

Isn't there some kind of portable operating system standard that says
how to do these things?



Reply | Threaded
Open this post in threaded view
|

Re: rfc: /etc/hostname on gentoo

Rich Freeman
In reply to this post by William Hubbs
On Mon, Aug 22, 2016 at 1:03 PM, William Hubbs <[hidden email]> wrote:
>
> I'm not sure about putting this in /run for a couple of reasons:
>
> The contents of this file is a setting, like /etc/conf.d/hostname, which
> will be set by the user.

There is no reason a script can't populate /run with the right thing.
For example, with systemd you can set up a static networking config
with a static DNS, and it will populate a resolv.conf in /run with
whatever it parsed out of your networkd configuration.  Or you can
tell it to use dhcp in which case it populates /run with whatever the
dhcp server gives it.

The idea is that only one tool has to worry about where to get the
right network settings from, and everything else can just read them in
whatever format they prefer from wherever it is preferred.

However, it isn't the only way to accomplish this goal.  You could
just keep writing to /etc.  That does break in situations where you
want /etc to be read-only, etc.

>
> The other reason is, I don't know enough about containers to know if
> they will have a separate /run from the host.
>

Typically containers will have their own /run.  Containers were one of
the big reasons to not store hostnames in /etc, since then you can
share a single image across many containers, with a static /etc, and
the dynamic stuff all goes in /run.  Containers are also one of the
reasons for ditching /etc/mtab.

--
Rich

Reply | Threaded
Open this post in threaded view
|

Re: rfc: /etc/hostname on gentoo

Matthew Thode (prometheanfire)
In reply to this post by William Hubbs
On 08/22/2016 10:58 AM, William Hubbs wrote:

> All,
>
> it looks like app-emulation/docker expects /etc/hostname to exist.
>
> On Gentoo, this file does not exist, so I'm wondering how we can make it
> exist?
>
> I know in OpenRC I can read it and use the value there as the hostname
> instead of /etc/conf.d/hostname if it exists,but I'm not sure whether
> OpenRC should populate /etc/hostname if it does not exist or whether
> something else should do that.
>
> Thoughts?
>
> William
>
I'd like us to populate the file in some way (symlink to /run or
otherwise).  Just keep in mind that the format is different than
/etc/conf.d/hostname when considering your options.

--
-- Matthew Thode (prometheanfire)


signature.asc (817 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: rfc: /etc/hostname on gentoo

Sven Vermeulen
In reply to this post by Michael Orlitzky
On Mon, Aug 22, 2016 at 01:28:50PM -0400, Michael Orlitzky wrote:
> On 08/22/2016 11:58 AM, William Hubbs wrote:
> > All,
> >
> > it looks like app-emulation/docker expects /etc/hostname to exist.
> >
>
> Isn't there some kind of portable operating system standard that says
> how to do these things?

Yes, wouldn't the Docker project be happy to take on a patch that uses
gethostname() or so?

Wkr,
        Sven Vermeulen

Reply | Threaded
Open this post in threaded view
|

Re: rfc: /etc/hostname on gentoo

Matthew Thode (prometheanfire)
In reply to this post by William Hubbs
On 08/22/2016 10:58 AM, William Hubbs wrote:

> All,
>
> it looks like app-emulation/docker expects /etc/hostname to exist.
>
> On Gentoo, this file does not exist, so I'm wondering how we can make it
> exist?
>
> I know in OpenRC I can read it and use the value there as the hostname
> instead of /etc/conf.d/hostname if it exists,but I'm not sure whether
> OpenRC should populate /etc/hostname if it does not exist or whether
> something else should do that.
>
> Thoughts?
>
> William
>
Secondarily I'd like /etc/hostname to be seen as a source of truth.
Having to write wrapper scripts to fix /etc/hostname issues can suck
(cloud-init and glean).

--
-- Matthew Thode (prometheanfire)


signature.asc (817 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: rfc: /etc/hostname on gentoo

Rich Freeman
In reply to this post by Sven Vermeulen
On Mon, Aug 22, 2016 at 1:51 PM, Sven Vermeulen <[hidden email]> wrote:
>
> Yes, wouldn't the Docker project be happy to take on a patch that uses
> gethostname() or so?
>

This might be another option: symlink to /proc/sys/kernel/hostname

I'm not sure if somebody can find a flaw in this.  It appears to use
the UTS namespace hostname inside containers, which is what you'd
want.

--
Rich

Reply | Threaded
Open this post in threaded view
|

Re: rfc: /etc/hostname on gentoo

Dirkjan Ochtman-3
In reply to this post by William Hubbs
On Mon, Aug 22, 2016 at 5:58 PM, William Hubbs <[hidden email]> wrote:
> On Gentoo, this file does not exist, so I'm wondering how we can make it
> exist?

Not sure if/how related, but when I have:

djc@enrai ~ $ cat /etc/conf.d/hostname
# Set to the hostname of this machine
hostname="enrai"

Apache 2 tells me:

AH00558: apache2: Could not reliably determine the server's fully
qualified domain name, using 127.0.0.1. Set the 'ServerName' directive
globally to suppress this message                        [ ok ]

I've set dns_domain and dns_search in /etc/conf.d/net, and domain is
set in /etc/resolv.conf.

The Handbook also has a non-fully-qualified hostname set in
/etc/conf.d/hostname, and I didn't get this Apache warning on the
previous server I ran this stuff on.

Cheers,

Dirkjan

Reply | Threaded
Open this post in threaded view
|

Re: rfc: /etc/hostname on gentoo

Hans de Graaff-2
In reply to this post by William Hubbs
On Mon, 2016-08-22 at 10:58 -0500, William Hubbs wrote:
> All,
>
> it looks like app-emulation/docker expects /etc/hostname to exist.

Is there a bug for this? docker seems to work fine for me on a system
without this file present.

Hans

signature.asc (220 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: rfc: /etc/hostname on gentoo

William Hubbs
On Mon, Aug 22, 2016 at 09:28:44PM +0200, Hans de Graaff wrote:
> On Mon, 2016-08-22 at 10:58 -0500, William Hubbs wrote:
> > All,
> >
> > it looks like app-emulation/docker expects /etc/hostname to exist.
>
> Is there a bug for this? docker seems to work fine for me on a system
> without this file present.

Let me take a look on my end more and I'll clarify this.

Thanks,

William

signature.asc (188 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: rfc: /etc/hostname on gentoo

William Hubbs
In reply to this post by Hans de Graaff-2
On Mon, Aug 22, 2016 at 09:28:44PM +0200, Hans de Graaff wrote:
> On Mon, 2016-08-22 at 10:58 -0500, William Hubbs wrote:
> > All,
> >
> > it looks like app-emulation/docker expects /etc/hostname to exist.
>
> Is there a bug for this? docker seems to work fine for me on a system
> without this file present.

Ok, now for the clarification.

Someone here at the office was wanting a cross-platform way to find out
the hostname of the host the container is running on inside the
container. We made another suggestion for that, so forget about the
docker angle on this for now.

But, /etc/hostname is a multi-distro standard for where the hostname is
located, so I would like to make openrc prefer it over the setting in
/etc/conf.d/hostname if it exists.A

I suppose whether we populate it by default might be a separate
question.

William


signature.asc (188 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: rfc: /etc/hostname on gentoo

Daniel Campbell (zlg)
On 08/22/2016 03:09 PM, William Hubbs wrote:

> On Mon, Aug 22, 2016 at 09:28:44PM +0200, Hans de Graaff wrote:
>> On Mon, 2016-08-22 at 10:58 -0500, William Hubbs wrote:
>>> All,
>>>
>>> it looks like app-emulation/docker expects /etc/hostname to exist.
>>
>> Is there a bug for this? docker seems to work fine for me on a system
>> without this file present.
>
> Ok, now for the clarification.
>
> Someone here at the office was wanting a cross-platform way to find out
> the hostname of the host the container is running on inside the
> container. We made another suggestion for that, so forget about the
> docker angle on this for now.
>
> But, /etc/hostname is a multi-distro standard for where the hostname is
> located, so I would like to make openrc prefer it over the setting in
> /etc/conf.d/hostname if it exists.A
>
> I suppose whether we populate it by default might be a separate
> question.
>
> William
>
Changing the way one configures the hostname because one or a few
packages A) need this knowledge, and B) hardcode /etc/hostname is not
worth changing the canonical way to update it and getting people to
change their habits.

It makes a bit more sense to rely on previous configuration
(/etc/conf.d/hostname) and write a tiny 'script' that populates
/etc/hostname. bash could do it (naively) in two lines:

source /etc/conf.d/hostname
echo "$hostname" > /etc/hostname

The 'multi-distro standard' is du jour at best and imo not a compelling
reason to follow.

--
Daniel Campbell - Gentoo Developer
OpenPGP Key: 0x1EA055D6 @ hkp://keys.gnupg.net
fpr: AE03 9064 AE00 053C 270C  1DE4 6F7A 9091 1EA0 55D6


signature.asc (817 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: rfc: /etc/hostname on gentoo

Christian Kniep
Hey y’all,

just to elaborate on the problem and clear up the fuzz I made.

I am facing to be distro-agnostic, thus I do not know in advance if I am running on DockerForMac (which uses Alpine Linux), some weird Ubuntu vagrant setup of mine or a fleet of gentoo hosts.
Docker Service schedules the service as it pleases (oversimplification). For services I fancy using global services in which the described services is started on each node of the SWAM cluster.

A demo of how this looks like (fast-forward to minute 28): https://www.youtube.com/watch?v=g-YNST-COdI

I have four nodes in my cluster:

###
docker node ls
ID                           HOSTNAME                     STATUS  AVAILABILITY  MANAGER STATUS
4iffi5tt5jlk03ub7nd7cf5r2    gentoo1  Ready   Active
5m0x0vqtjugkwi13gkaa4ijk2    gentoo2  Ready   Active
6eu0fiz0ch8e7pnbbzh8pj545    gentoo3  Ready   Active        Leader
ckrxwdppbehyz806o7gxgashl *  gentoo4  Ready   Active        Reachable
$
###

If I use an environment variable like this:

###
$ docker service create --name nginx --mode=global -e SERVICE_HOSTNAME=$(hostname -f)  nginx
###

Each of the tasks (a container to-be-run on one of the nodes) will now find an environment variable SERVICE_HOSTNAME, but it will a) be the same among all containers and b) it will show the hostname from which the service was created.

Therefore environment variables are not going to get me far.

On docker host with non-gentoo I can just run this (e.g. on my DockerForMac):

###
$ docker service create --mount type=bind,source=/etc/hostname,target=/etc/docker-hostname:ro --name nginx  nginx
###

By doing so I am able to determine on which host I am running on each tasks without much hassle.

###
$ docker exec -ti 56e8b2eaecc3 cat /etc/docker-hostname
###

I am using this for a zookeeper service which should reuse the same MYID when restarted on a given node.
Otherwise I would end up with a restarting container on a given node, which would get himself a new MYID and after a couple of restarts I am out of the range of MYID (up to 255).

Cheers and again, sorry for the misunderstanding
Christian


> On 23 Aug 2016, at 08:39, Daniel Campbell <[hidden email]> wrote:
>
> On 08/22/2016 03:09 PM, William Hubbs wrote:
>> On Mon, Aug 22, 2016 at 09:28:44PM +0200, Hans de Graaff wrote:
>>> On Mon, 2016-08-22 at 10:58 -0500, William Hubbs wrote:
>>>> All,
>>>>
>>>> it looks like app-emulation/docker expects /etc/hostname to exist.
>>>
>>> Is there a bug for this? docker seems to work fine for me on a system
>>> without this file present.
>>
>> Ok, now for the clarification.
>>
>> Someone here at the office was wanting a cross-platform way to find out
>> the hostname of the host the container is running on inside the
>> container. We made another suggestion for that, so forget about the
>> docker angle on this for now.
>>
>> But, /etc/hostname is a multi-distro standard for where the hostname is
>> located, so I would like to make openrc prefer it over the setting in
>> /etc/conf.d/hostname if it exists.A
>>
>> I suppose whether we populate it by default might be a separate
>> question.
>>
>> William
>>
> Changing the way one configures the hostname because one or a few
> packages A) need this knowledge, and B) hardcode /etc/hostname is not
> worth changing the canonical way to update it and getting people to
> change their habits.
>
> It makes a bit more sense to rely on previous configuration
> (/etc/conf.d/hostname) and write a tiny 'script' that populates
> /etc/hostname. bash could do it (naively) in two lines:
>
> source /etc/conf.d/hostname
> echo "$hostname" > /etc/hostname
>
> The 'multi-distro standard' is du jour at best and imo not a compelling
> reason to follow.
>
> --
> Daniel Campbell - Gentoo Developer
> OpenPGP Key: 0x1EA055D6 @ hkp://keys.gnupg.net
> fpr: AE03 9064 AE00 053C 270C  1DE4 6F7A 9091 1EA0 55D6
>


smime.p7s (3K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: rfc: /etc/hostname on gentoo

Rich Freeman
In reply to this post by Daniel Campbell (zlg)
On Tue, Aug 23, 2016 at 2:39 AM, Daniel Campbell <[hidden email]> wrote:
>
> It makes a bit more sense to rely on previous configuration
> (/etc/conf.d/hostname) and write a tiny 'script' that populates
> /etc/hostname. bash could do it (naively) in two lines:
>
> source /etc/conf.d/hostname
> echo "$hostname" > /etc/hostname
>

Seems to me that symlinking /proc/sys/kernel/hostname would be
simpler.  Also, more reliable, because there are other ways the
hostname could be set other than from /etc/conf.d/hostname.  The
hostname can also change.

--
Rich

Reply | Threaded
Open this post in threaded view
|

Re: rfc: /etc/hostname on gentoo

Michael Orlitzky
In reply to this post by William Hubbs
On 08/22/2016 06:09 PM, William Hubbs wrote:

>
> Someone here at the office was wanting a cross-platform way to find out
> the hostname of the host the container is running on inside the
> container. We made another suggestion for that, so forget about the
> docker angle on this for now.
>
> But, /etc/hostname is a multi-distro standard for where the hostname is
> located, so I would like to make openrc prefer it over the setting in
> /etc/conf.d/hostname if it exists.A
>

What for? As far as I know, /etc/hostname is an arbitrary path that has
been used to configure the hostname in the past. Whatever, you gotta
configure it somewhere. But in OpenRC, there's a standard place for init
script configuration and we already use it. Switching just one service
to prefer another path is going to confuse everyone: "I changed my
hostname in /etc/conf.d/hostname and NOTHING HAPPENED!?!?"

Populating /etc/hostname will only encourage people to read it from
there rather than the proper way.


Reply | Threaded
Open this post in threaded view
|

Re: rfc: /etc/hostname on gentoo

Christian Kniep
In reply to this post by Rich Freeman

Hey Rich,

nice idea, but unfortunately this provides the hostname of the container itself.

$ docker run -ti -v /proc/sys/kernel/hostname:/etc/docker-hostname:ro nginx bash
root@bea048d42fc3:/# cat /etc/docker-hostname
bea048d42fc3
root@bea048d42fc3:/#

Without digging deep into it I reckon that the proc (and the sys) filesystems are treated differently, to be sure that each container is in a distinct /proc filesystem.

Cheers Christian




On 23 August 2016 at 12:01:49, Rich Freeman ([hidden email]) wrote:

On Tue, Aug 23, 2016 at 2:39 AM, Daniel Campbell <[hidden email]> wrote:
>
> It makes a bit more sense to rely on previous configuration
> (/etc/conf.d/hostname) and write a tiny 'script' that populates
> /etc/hostname. bash could do it (naively) in two lines:
>
> source /etc/conf.d/hostname
> echo "$hostname" > /etc/hostname
>

Seems to me that symlinking /proc/sys/kernel/hostname would be
simpler. Also, more reliable, because there are other ways the
hostname could be set other than from /etc/conf.d/hostname. The
hostname can also change.

--
Rich

Reply | Threaded
Open this post in threaded view
|

Re: rfc: /etc/hostname on gentoo

Michael Orlitzky
In reply to this post by Christian Kniep
My mental model is wrong so I'm probably about to say something stupid.
I'm not familiar with the way docker works so bear with me...


On 08/23/2016 03:01 AM, Christian Kniep wrote:
>
> ###
> $ docker service create --name nginx --mode=global -e SERVICE_HOSTNAME=$(hostname -f)  nginx
> ###

This looks like it would set the SERVICE_HOSTNAME environment variable
inside the container to the hostname that you're running the command on.


> Each of the tasks (a container to-be-run on one of the nodes) will
> now find an environment variable SERVICE_HOSTNAME, but it will a) be
> the same among all containers and b) it will show the hostname from
> which the service was created.
>

Cool, I'm not confused yet.


> On docker host with non-gentoo I can just run this (e.g. on my DockerForMac):
>
> $ docker service create --mount type=bind,source=/etc/hostname,target=/etc/docker-hostname:ro --name nginx  nginx

Doesn't this mount the /etc/hostname file, from the host that you run
the command on, to the /etc/docker-hostname file within the container?
If so, it would have the same problem as the environment variable, so
it's got to be doing something else.

...Is it the other way around? Does it mount /etc/hostname from the
container somewhere on the outside?


> By doing so I am able to determine on which host I am running on
> each tasks without much hassle.
>
> $ docker exec -ti 56e8b2eaecc3 cat /etc/docker-hostname
>

If this runs *inside* the container, then instead of using "cat" on a
file, why not just run "hostname"? That should give you the hostname of
the machine it ran on. For example,

  docker exec -ti 56e8b2eaecc3 hostname

But, if that runs outside the container, then... I need a better
understanding of what's going on before I start throwing out ideas.


123