]>
git.proxmox.com Git - pve-container.git/blob - src/PVE/LXCSetup/Redhat.pm
1 package PVE
::LXCSetup
::Redhat
;
10 use PVE
::LXCSetup
::Base
;
12 use base
qw(PVE::LXCSetup::Base);
15 my ($class, $conf, $rootdir) = @_;
17 my $release = PVE
::Tools
::file_read_firstline
("$rootdir/etc/redhat-release");
18 die "unable to read version info\n" if !defined($release);
22 if ($release =~ m/release\s+(\d\.\d)\s/) {
23 if ($1 >= 6 && $1 < 7) {
28 die "unsupported redhat release '$release'\n" if !$version;
30 my $self = { conf
=> $conf, rootdir
=> $rootdir, version
=> $version };
32 $conf->{'lxc.include'} = "/usr/share/lxc/config/centos.common.conf";
34 return bless $self, $class;
37 my $tty_conf = <<__EOD__;
40 # This service maintains a getty on the specified device.
42 # Do not edit this file directly. If you want to change the behaviour,
43 # please create a file tty.override and put your changes there.
45 stop on runlevel [S016]
49 exec /sbin/mingetty \$TTY
50 usage 'tty TTY=/dev/ttyX - where X is console id'
53 my $start_ttys_conf = <<__EOD__;
55 # This service starts the configured number of gettys.
57 # Do not edit this file directly. If you want to change the behaviour,
58 # please create a file start-ttys.override and put your changes there.
60 start on stopped rc RUNLEVEL=[2345]
62 env ACTIVE_CONSOLES=/dev/tty[1-6]
67 for tty in \$(echo \$ACTIVE_CONSOLES) ; do
68 [ "\$RUNLEVEL" = "5" -a "\$tty" = "\$X_TTY" ] && continue
69 initctl start tty TTY=\$tty
75 my ($self, $conf) = @_;
77 my $rootdir = $self->{rootdir
};
79 if ($self->{version
} < 7) {
80 # re-create emissing files for tty
82 mkpath
"$rootdir/etc/init";
84 my $filename = "$rootdir/etc/init/tty.conf";
85 PVE
::Tools
::file_set_contents
($filename, $tty_conf)
89 $filename = "$rootdir/etc/init/start-ttys.conf";
90 PVE
::Tools
::file_set_contents
($filename, $start_ttys_conf)
94 $filename = "$rootdir/etc/rc.d/rc.sysinit";
95 my $data = PVE
::Tools
::file_get_contents
($filename);
96 $data =~ s!^(/sbin/start_udev.*)$!#$1!gm;
97 PVE
::Tools
::file_set_contents
($filename, $data);
99 # edit /etc/securetty (enable login on console)
100 $filename = "$rootdir/etc/securetty";
101 $data = PVE
::Tools
::file_get_contents
($filename);
102 chomp $data; $data .= "\n";
103 foreach my $dev (qw(console tty1 tty2 tty3 tty4)) {
104 if ($data !~ m!^lxc/$dev\s*$!m) {
105 $data .= "lxc/$dev\n";
108 PVE
::Tools
::file_set_contents
($filename, $data);
114 my ($self, $conf) = @_;
116 my $rootdir = $self->{rootdir
};
120 my $ttycount = defined($conf->{'lxc.tty'}) ?
$conf->{'lxc.tty'} : 4;
126 my ($self, $conf) = @_;
128 my $hostname = $conf->{'lxc.utsname'} || 'localhost';
130 $hostname =~ s/\..*$//;
132 my $rootdir = $self->{rootdir
};
134 my $hostname_fn = "$rootdir/etc/hostname";
135 my $sysconfig_network = "$rootdir/etc/sysconfig/network";
138 if (-f
$hostname_fn) {
139 $oldname = PVE
::Tools
::file_read_firstline
($hostname_fn) || 'localhost';
141 my $data = PVE
::Tools
::file_get_contents
($sysconfig_network);
142 if ($data =~ m/^HOSTNAME=\s*(\S+)\s*$/m) {
147 my $hosts_fn = "$rootdir/etc/hosts";
148 my $etc_hosts_data = '';
150 $etc_hosts_data = PVE
::Tools
::file_get_contents
($hosts_fn);
153 my ($ipv4, $ipv6) = PVE
::LXC
::get_primary_ips
($conf);
154 my $hostip = $ipv4 || $ipv6;
156 my ($searchdomains) = PVE
::LXCSetup
::Base
::lookup_dns_conf
($conf);
158 $etc_hosts_data = PVE
::LXCSetup
::Base
::update_etc_hosts
($etc_hosts_data, $hostip, $oldname,
159 $hostname, $searchdomains);
161 if (-f
$hostname_fn) {
162 PVE
::Tools
::file_set_contents
($hostname_fn, "$hostname\n");
164 my $data = PVE
::Tools
::file_get_contents
($sysconfig_network);
165 if ($data !~ s/^HOSTNAME=\s*(\S+)\s*$/HOSTNAME=$hostname\n/m) {
166 $data .= "HOSTNAME=$hostname\n";
168 PVE
::Tools
::file_set_contents
($sysconfig_network, $data);
171 PVE
::Tools
::file_set_contents
($hosts_fn, $etc_hosts_data);
175 my ($self, $conf) = @_;
177 my $rootdir = $self->{rootdir
};
180 mkpath
"$rootdir/etc/sysconfig/network-scripts";
182 foreach my $k (keys %$conf) {
183 next if $k !~ m/^net(\d+)$/;
186 my $filename = "$rootdir/etc/sysconfig/network-scripts/ifcfg-$d->{name}";
187 my $data = "DEVICE=$d->{name}\n";
188 $data .= "ONBOOT=yes\n";
189 $data .= "BOOTPROTO=none\n";
190 if (defined($d->{ip
})) {
191 my $ipinfo = PVE
::LXC
::parse_ipv4_cidr
($d->{ip
});
192 $data .= "IPADDR=$ipinfo->{address}\n";
193 $data .= "NETMASK=$ipinfo->{netmask}\n";
194 if (defined($d->{gw
})) {
195 $data .= "GATEWAY=$d->{gw}\n";
198 if (defined($d->{gw6
})) {
201 if (defined($d->{ip6
})) {
204 PVE
::Tools
::file_set_contents
($filename, $data);