Leveraging system hostname as part of a jail's hostname

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

Leveraging system hostname as part of a jail's hostname

Joseph Ward-2
Hi everyone,

I have several jails, configured via jail.conf, whose hostname I want to
make: $name.$system_hostname.

Is there a way to do this in jail.conf?   If I use:

host = inherit;

the hostnames of the jails all match the hostname of the system.  I
tried using:

host.hostname = $name;
host.domainname = inherit;

but the hostname ends up just being $name (expanded, of course).

Trying:

host = inherit;
host.hostname = $name;

ended up with simply $name as well, with the "inherit" ignored.

So, am I missing something? 


Thanks,

Joseph

_______________________________________________
[hidden email] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-jail
To unsubscribe, send any mail to "[hidden email]"
Reply | Threaded
Open this post in threaded view
|

Re: Leveraging system hostname as part of a jail's hostname

James Gritton-2
On 2018-06-19 20:41, Joseph Ward wrote:

> Hi everyone,
>
> I have several jails, configured via jail.conf, whose hostname I want
> to
> make: $name.$system_hostname.
>
> Is there a way to do this in jail.conf?   If I use:
>
> host = inherit;
>
> the hostnames of the jails all match the hostname of the system.  I
> tried using:
>
> host.hostname = $name;
> host.domainname = inherit;
>
> but the hostname ends up just being $name (expanded, of course).
>
> Trying:
>
> host = inherit;
> host.hostname = $name;
>
> ended up with simply $name as well, with the "inherit" ignored.
>
> So, am I missing something? 

You can't do it with a simple substitution in a parameter setting, since
there's no way in the config file to read the current hostname.  You
don't want "host = inherit", because that will cause all jails to use
the same hostname - if you change one, it changes all of them (and
changes the system hostname).

But you can do it in two steps, involving some fairly ugly hackery
around exec.poststart.  Something like:

foo
{
   exec.poststart = "jail -m name=foo host.hostname=$name.`hostname`";
   exec.poststart += "jexec foo sleep 600";
}

Unfortunately the second exec.poststart line is required as a
replacement for the typical "exec.start='sh /etc/rc'" because
exec.poststart runs after exec.start and that's to late to set the
hostname.  This is one of these cases that suggests the need for a
parameter run by the main host between jail creation and the running of
exec.start.

Another possible hack would be to do something with setting a file
inside the jail that's peeked at by the jail's rc.conf or rc.d/hostname.

Nothing pretty, I'm afraid.

- Jamie
_______________________________________________
[hidden email] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-jail
To unsubscribe, send any mail to "[hidden email]"
Reply | Threaded
Open this post in threaded view
|

Re: Leveraging system hostname as part of a jail's hostname

Joseph Ward-2
Thank you for getting back to me!

I tested your solution, and using exec.poststart works perfectly.  I
didn't even need the sleep, however, and was able to leave the

exec.start = "/bin/sh /etc/rc";

alone, and it worked perfectly.  As the jail is running, the

jail -m name=$name host.hostname=$name.`hostname`"

did work, so I tried the following jail.conf and everything works
perfectly.


exec.start = "/bin/sh /etc/rc";
exec.poststart = "jail -m name=$name host.hostname=$name.`hostname`";
exec.stop = "/bin/sh /etc/rc.shutdown";
exec.clean;
mount.devfs;
db {
  host.hostname = "db";
  path = "/usr/local/jails/db";
  interface = "lo1";
  ip4.addr = 127.0.1.2;
  mount.fstab = "/usr/local/jails/db.fstab";
}

ldap {
  host.hostname = "ldap";
  path = "/usr/local/jails/ldap";
  interface = "lo1";
  ip4.addr = 127.0.1.3;
  mount.fstab = "/usr/local/jails/ldap.fstab";
}


Thank you!

-Joseph


On 06/20/2018 12:52, James Gritton wrote:

> On 2018-06-19 20:41, Joseph Ward wrote:
>> Hi everyone,
>>
>> I have several jails, configured via jail.conf, whose hostname I want to
>> make: $name.$system_hostname.
>>
>> Is there a way to do this in jail.conf?   If I use:
>>
>> host = inherit;
>>
>> the hostnames of the jails all match the hostname of the system.  I
>> tried using:
>>
>> host.hostname = $name;
>> host.domainname = inherit;
>>
>> but the hostname ends up just being $name (expanded, of course).
>>
>> Trying:
>>
>> host = inherit;
>> host.hostname = $name;
>>
>> ended up with simply $name as well, with the "inherit" ignored.
>>
>> So, am I missing something? 
>
> You can't do it with a simple substitution in a parameter setting,
> since there's no way in the config file to read the current hostname. 
> You don't want "host = inherit", because that will cause all jails to
> use the same hostname - if you change one, it changes all of them (and
> changes the system hostname).
>
> But you can do it in two steps, involving some fairly ugly hackery
> around exec.poststart.  Something like:
>
> foo
> {
>   exec.poststart = "jail -m name=foo host.hostname=$name.`hostname`";
>   exec.poststart += "jexec foo sleep 600";
> }
>
> Unfortunately the second exec.poststart line is required as a
> replacement for the typical "exec.start='sh /etc/rc'" because
> exec.poststart runs after exec.start and that's to late to set the
> hostname.  This is one of these cases that suggests the need for a
> parameter run by the main host between jail creation and the running
> of exec.start.
>
> Another possible hack would be to do something with setting a file
> inside the jail that's peeked at by the jail's rc.conf or rc.d/hostname.
>
> Nothing pretty, I'm afraid.
>
> - Jamie

_______________________________________________
[hidden email] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-jail
To unsubscribe, send any mail to "[hidden email]"
Reply | Threaded
Open this post in threaded view
|

Re: Leveraging system hostname as part of a jail's hostname

Erich Dollansky-8
In reply to this post by Joseph Ward-2
Hi,

I use a script that generates the configuration file when the jail is
created.

This should work for you too.

Erich


 On Tue, 19 Jun 2018 22:41:15 -0400
Joseph Ward <[hidden email]> wrote:

> Hi everyone,
>
> I have several jails, configured via jail.conf, whose hostname I want
> to make: $name.$system_hostname.
>
> Is there a way to do this in jail.conf?   If I use:
>
> host = inherit;
>
> the hostnames of the jails all match the hostname of the system.  I
> tried using:
>
> host.hostname = $name;
> host.domainname = inherit;
>
> but the hostname ends up just being $name (expanded, of course).
>
> Trying:
>
> host = inherit;
> host.hostname = $name;
>
> ended up with simply $name as well, with the "inherit" ignored.
>
> So, am I missing something? 
>
>
> Thanks,
>
> Joseph
>
> _______________________________________________
> [hidden email] mailing list
> https://lists.freebsd.org/mailman/listinfo/freebsd-jail
> To unsubscribe, send any mail to
> "[hidden email]"

_______________________________________________
[hidden email] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-jail
To unsubscribe, send any mail to "[hidden email]"
Reply | Threaded
Open this post in threaded view
|

Re: Leveraging system hostname as part of a jail's hostname

Joseph Ward-2
Thanks for the suggestion, but my case is a bit wacky.  I'm actually
creating the jails on a build box, packaging them, and deploying them to
a bunch of different host machines, so ideally the change would be
handled across all machines without any changes.  Fortunately, the
suggestion in the other sub-thread worked well.  (In a previous
iteration I'd had the deploy script make the change on each machine, but
that's a lot less clean than just having a single jail.conf that worked
for all).


-Joseph


On 06/20/2018 20:57, Erich Dollansky wrote:

> Hi,
>
> I use a script that generates the configuration file when the jail is
> created.
>
> This should work for you too.
>
> Erich
>
>
>  On Tue, 19 Jun 2018 22:41:15 -0400
> Joseph Ward <[hidden email]> wrote:
>
>> Hi everyone,
>>
>> I have several jails, configured via jail.conf, whose hostname I want
>> to make: $name.$system_hostname.
>>
>> Is there a way to do this in jail.conf?   If I use:
>>
>> host = inherit;
>>
>> the hostnames of the jails all match the hostname of the system.  I
>> tried using:
>>
>> host.hostname = $name;
>> host.domainname = inherit;
>>
>> but the hostname ends up just being $name (expanded, of course).
>>
>> Trying:
>>
>> host = inherit;
>> host.hostname = $name;
>>
>> ended up with simply $name as well, with the "inherit" ignored.
>>
>> So, am I missing something? 
>>
>>
>> Thanks,
>>
>> Joseph
>>
>> _______________________________________________
>> [hidden email] mailing list
>> https://lists.freebsd.org/mailman/listinfo/freebsd-jail
>> To unsubscribe, send any mail to
>> "[hidden email]"

_______________________________________________
[hidden email] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-jail
To unsubscribe, send any mail to "[hidden email]"