]> git.proxmox.com Git - pve-container.git/blame - src/PVE/LXC/Setup/Ubuntu.pm
simply version check
[pve-container.git] / src / PVE / LXC / Setup / Ubuntu.pm
CommitLineData
7af97ad5 1package PVE::LXC::Setup::Ubuntu;
a8e58e9c
DM
2
3use strict;
4use warnings;
5use Data::Dumper;
6use PVE::Tools;
7use PVE::LXC;
8use File::Path;
9
7af97ad5 10use PVE::LXC::Setup::Debian;
a8e58e9c 11
7af97ad5 12use base qw(PVE::LXC::Setup::Debian);
a8e58e9c 13
91bf89e1 14my $known_versions = {
5fc8ad5f 15 '17.10' => 1, # artful
d9d448fa 16 '17.04' => 1, # zesty
bd4082c1 17 '16.10' => 1, # yakkety
1c5e428d 18 '16.04' => 1, # xenial
90c85c7d 19 '15.10' => 1, # wily
91bf89e1
DM
20 '15.04' => 1, # vivid
21 '14.04' => 1, # trusty LTS
22 '12.04' => 1, # precise LTS
23};
24
a8e58e9c
DM
25sub new {
26 my ($class, $conf, $rootdir) = @_;
27
28 my $lsb_fn = "$rootdir/etc/lsb-release";
29 my $lsbinfo = PVE::Tools::file_get_contents($lsb_fn);
30
31 die "got unknown DISTRIB_ID\n" if $lsbinfo !~ m/^DISTRIB_ID=Ubuntu$/mi;
32
33 my $version;
34 if ($lsbinfo =~ m/^DISTRIB_RELEASE=(\d+\.\d+)$/mi) {
35 $version = $1;
36 }
37
38 die "unable to read version info\n" if !defined($version);
39
40dee029
DM
40 die "unsupported Ubuntu version '$version'\n"
41 if !$known_versions->{$version};
a8e58e9c
DM
42
43 my $self = { conf => $conf, rootdir => $rootdir, version => $version };
44
27916659 45 $conf->{ostype} = "ubuntu";
a8e58e9c
DM
46
47 return bless $self, $class;
48}
49
50sub template_fixup {
51 my ($self, $conf) = @_;
52
91bf89e1 53 my $version = $self->{version};
73a7a0e8
DC
54
55 if ($version >= '17.10') {
56 # enable systemd-networkd
57 $self->ct_mkdir('/etc/systemd/system/multi-user.target.wants');
58 $self->ct_mkdir('/etc/systemd/system/socket.target.wants');
59 $self->ct_symlink('/lib/systemd/system/systemd-networkd.service',
60 '/etc/systemd/system/multi-user.target.wants/systemd-networkd.service');
61 $self->ct_symlink('/lib/systemd/system/systemd-networkd.socket',
62 '/etc/systemd/system/socket.target.wants/systemd-networkd.socket');
63
64 # unlink default netplan lxc config
65 $self->ct_unlink('/etc/netplan/10-lxc.yaml');
66 }
67
45ebd6c7 68 if ($version eq '15.04' || $version eq '15.10' || $version eq '16.04') {
a8e58e9c 69 # edit /etc/securetty (enable login on console)
b7cd927f 70 $self->setup_securetty($conf, qw(pts/0));
a8e58e9c 71 }
91bf89e1
DM
72
73 if ($version eq '12.04') {
74 # suppress log level output for udev
2063d380
WB
75 my $filename = '/etc/udev/udev.conf';
76 my $data = $self->ct_file_get_contents($filename);
91bf89e1 77 $data =~ s/=\"err\"/=0/m;
2063d380 78 $self->ct_file_set_contents($filename, $data);
91bf89e1 79 }
a8e58e9c
DM
80}
81
82sub setup_init {
83 my ($self, $conf) = @_;
84
c40a11f2 85 my $version = $self->{version};
a8e58e9c 86
6e273acd 87 if ($version >= '16.10') {
5e84bdc8 88 $self->setup_container_getty_service($conf);
45ebd6c7
DM
89 }
90
c40a11f2 91 if ($version eq '12.04' || $version eq '14.04') {
1b4cf758 92 my $ttycount = PVE::LXC::Config->get_tty_count($conf);
c40a11f2 93 for (my $i = 1; $i < 7; $i++) {
2063d380 94 my $filename = "/etc/init/tty$i.conf";
c40a11f2
DM
95 if ($i <= $ttycount) {
96 my $tty_conf = <<__EOD__;
97# tty$i - getty
98#
99# This service maintains a getty on tty$i from the point the system is
100# started until it is shut down again.
101
102start on stopped rc RUNLEVEL=[2345] and (
103 not-container or
104 container CONTAINER=lxc or
105 container CONTAINER=lxc-libvirt)
106
107stop on runlevel [!2345]
108
109respawn
110exec /sbin/getty -8 38400 tty$i
111__EOD__
2063d380 112 $self->ct_file_set_contents($filename, $tty_conf);
c40a11f2
DM
113 } else {
114 for (my $i = $ttycount + 1; $i < 7; $i++) {
2063d380 115 $self->ct_unlink($filename);
c40a11f2
DM
116 }
117 }
118 }
119 }
a8e58e9c
DM
120}
121
73a7a0e8
DC
122sub setup_network {
123 my ($self, $conf) = @_;
124
125 if ($self->{version} >= '17.10') {
126 $self->setup_systemd_networkd($conf);
127 } else {
128 $self->SUPER::setup_network($conf);
129 }
130}
131
a8e58e9c 1321;