[Users] HOWTO: Propagate VE0 (Host) Hostname into VE's ?
Michael Stauber
mstauber at blueonyx.it
Mon Jun 29 08:38:12 EDT 2009
Hi Robert,
> I'm looking for a way to propagate the hostname of the VE0 a VE is
> running on (aka "The Host") into the VE environments (e.g. VE100).
>
> Is there any "start/stopp" script that I can hook into that is
>
> A) executed on the HOST not within the VE
> and
> B) knows the "private dir" of the VE that is startet ?
>
> Or is there any other way to propage that hostname into VE's ?
If you have all VE's in /vz/private/, then you can of course "guess" that the
private directory of the VE is /vz/private/<VPSID>/
The VPSID can be determined from inside a VE by looking at
/proc/user_beancounters, which shows the VE at the beginning of the line where
the kmemsize is reported.
I haven't found a way to determine the hostname of the master node from inside
a VE. But if I had to have that info inside a VE, I'd probably set up a
cronjob for that - similar to this:
-------------------------------------------------------------------------------------------------
#!/usr/bin/perl
if ( -d "/vz/private") {
system("/usr/sbin/vzlist --no-header --output veid | awk '{print \$1}' >
/tmp/cronve-list");
open(G, "/tmp/cronve-list");
while ($line = <G>) {
chomp($line);
next if $line =~ /^\s*$/; # skip blank lines
if ($line =~ /^([0-9]\w*)/) {
$VPS_ID = $line;
}
if ($VPS_ID != 0) {
$master = `uname -n`;
system("/bin/echo $master > /vz/private/$VPS_ID/etc/master");
}
}
close (G);
system("/bin/rm -f /tmp/cronve-list");
}
-------------------------------------------------------------------------------------------------
It is a bit more complicated than needed as my source for it does other things
as well. This one here just stores the output of "uname -n" into the
/etc/master in all VE's.
--
With best regards
Michael Stauber
More information about the Users
mailing list