]>
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
74 my $power_status_changed_conf = <<__EOD__;
75 # power-status-changed - shutdown on SIGPWR
77 start on power-status-changed
79 exec /sbin/shutdown -h now "SIGPWR received"
83 my ($self, $conf) = @_;
85 my $rootdir = $self->{rootdir
};
87 if ($self->{version
} < 7) {
88 # re-create emissing files for tty
90 mkpath
"$rootdir/etc/init";
92 my $filename = "$rootdir/etc/init/tty.conf";
93 PVE
::Tools
::file_set_contents
($filename, $tty_conf)
97 $filename = "$rootdir/etc/init/start-ttys.conf";
98 PVE
::Tools
::file_set_contents
($filename, $start_ttys_conf)
101 $filename = "$rootdir/etc/init/power-status-changed.conf";
102 PVE
::Tools
::file_set_contents
($filename, $power_status_changed_conf)
106 $filename = "$rootdir/etc/rc.d/rc.sysinit";
107 my $data = PVE
::Tools
::file_get_contents
($filename);
108 $data =~ s!^(/sbin/start_udev.*)$!#$1!gm;
109 PVE
::Tools
::file_set_contents
($filename, $data);
111 # edit /etc/securetty (enable login on console)
112 $filename = "$rootdir/etc/securetty";
113 $data = PVE
::Tools
::file_get_contents
($filename);
114 chomp $data; $data .= "\n";
115 foreach my $dev (qw(console tty1 tty2 tty3 tty4)) {
116 if ($data !~ m!^lxc/$dev\s*$!m) {
117 $data .= "lxc/$dev\n";
120 PVE
::Tools
::file_set_contents
($filename, $data);
126 my ($self, $conf) = @_;
128 my $rootdir = $self->{rootdir
};
132 my $ttycount = defined($conf->{'lxc.tty'}) ?
$conf->{'lxc.tty'} : 4;
138 my ($self, $conf) = @_;
140 my $hostname = $conf->{'lxc.utsname'} || 'localhost';
142 $hostname =~ s/\..*$//;
144 my $rootdir = $self->{rootdir
};
146 my $hostname_fn = "$rootdir/etc/hostname";
147 my $sysconfig_network = "$rootdir/etc/sysconfig/network";
150 if (-f
$hostname_fn) {
151 $oldname = PVE
::Tools
::file_read_firstline
($hostname_fn) || 'localhost';
153 my $data = PVE
::Tools
::file_get_contents
($sysconfig_network);
154 if ($data =~ m/^HOSTNAME=\s*(\S+)\s*$/m) {
159 my $hosts_fn = "$rootdir/etc/hosts";
160 my $etc_hosts_data = '';
162 $etc_hosts_data = PVE
::Tools
::file_get_contents
($hosts_fn);
165 my ($ipv4, $ipv6) = PVE
::LXC
::get_primary_ips
($conf);
166 my $hostip = $ipv4 || $ipv6;
168 my ($searchdomains) = PVE
::LXCSetup
::Base
::lookup_dns_conf
($conf);
170 $etc_hosts_data = PVE
::LXCSetup
::Base
::update_etc_hosts
($etc_hosts_data, $hostip, $oldname,
171 $hostname, $searchdomains);
173 if (-f
$hostname_fn) {
174 PVE
::Tools
::file_set_contents
($hostname_fn, "$hostname\n");
176 my $data = PVE
::Tools
::file_get_contents
($sysconfig_network);
177 if ($data !~ s/^HOSTNAME=\s*(\S+)\s*$/HOSTNAME=$hostname\n/m) {
178 $data .= "HOSTNAME=$hostname\n";
180 PVE
::Tools
::file_set_contents
($sysconfig_network, $data);
183 PVE
::Tools
::file_set_contents
($hosts_fn, $etc_hosts_data);
187 my ($self, $conf) = @_;
189 my $rootdir = $self->{rootdir
};
192 mkpath
"$rootdir/etc/sysconfig/network-scripts";
194 foreach my $k (keys %$conf) {
195 next if $k !~ m/^net(\d+)$/;
198 my $filename = "$rootdir/etc/sysconfig/network-scripts/ifcfg-$d->{name}";
199 my $data = "DEVICE=$d->{name}\n";
200 $data .= "ONBOOT=yes\n";
201 $data .= "BOOTPROTO=none\n";
202 if (defined($d->{ip
})) {
203 my $ipinfo = PVE
::LXC
::parse_ipv4_cidr
($d->{ip
});
204 $data .= "IPADDR=$ipinfo->{address}\n";
205 $data .= "NETMASK=$ipinfo->{netmask}\n";
206 if (defined($d->{gw
})) {
207 $data .= "GATEWAY=$d->{gw}\n";
210 if (defined($d->{ip6
})) {
211 $data .= "IPV6ADDR=$d->{ip6}\n";
213 if (defined($d->{gw6
})) {
214 $data .= "IPV6_DEFAULTGW=$d->{gw6}\n";
216 PVE
::Tools
::file_set_contents
($filename, $data);