[pve-devel] [PATCH pve-container 1/2] Setup::ArchLinux: put fqdn in /etc/hostname
Wolfgang Bumiller
w.bumiller at proxmox.com
Fri Nov 27 12:24:02 CET 2015
That's what 'hostnamectl set-hostname' does after all.
---
Note: this is a copy of Base's set_hostname with the s/\..*$// regex removed.
src/PVE/LXC/Setup/ArchLinux.pm | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/src/PVE/LXC/Setup/ArchLinux.pm b/src/PVE/LXC/Setup/ArchLinux.pm
index 352d21a..4d28265 100644
--- a/src/PVE/LXC/Setup/ArchLinux.pm
+++ b/src/PVE/LXC/Setup/ArchLinux.pm
@@ -46,6 +46,33 @@ sub setup_init {
# Nothing to do
}
+sub set_hostname {
+ my ($self, $conf) = @_;
+
+ # We use the fqdn in /etc/hostname with systemd
+ my $hostname = $conf->{hostname} || 'localhost';
+
+ my $hostname_fn = "/etc/hostname";
+ my $oldname = $self->ct_file_read_firstline($hostname_fn) || 'localhost';
+
+ my $hosts_fn = "/etc/hosts";
+ my $etc_hosts_data = '';
+
+ if ($self->ct_file_exists($hosts_fn)) {
+ $etc_hosts_data = $self->ct_file_get_contents($hosts_fn);
+ }
+
+ my ($ipv4, $ipv6) = PVE::LXC::get_primary_ips($conf);
+ my $hostip = $ipv4 || $ipv6;
+
+ my ($searchdomains) = $self->lookup_dns_conf($conf);
+ $etc_hosts_data = PVE::LXC::Setup::Base::update_etc_hosts($etc_hosts_data, $hostip, $oldname,
+ $hostname, $searchdomains);
+
+ $self->ct_file_set_contents($hostname_fn, "$hostname\n");
+ $self->ct_file_set_contents($hosts_fn, $etc_hosts_data);
+}
+
sub setup_network {
my ($self, $conf) = @_;
--
2.1.4
More information about the pve-devel
mailing list