]> git.proxmox.com Git - pve-container.git/blob - src/PVE/LXC/Setup/Ubuntu.pm
use systemd-networkd for ubuntu >= 17.10
[pve-container.git] / src / PVE / LXC / Setup / Ubuntu.pm
1 package PVE::LXC::Setup::Ubuntu;
2
3 use strict;
4 use warnings;
5 use Data::Dumper;
6 use PVE::Tools;
7 use PVE::LXC;
8 use File::Path;
9
10 use PVE::LXC::Setup::Debian;
11
12 use base qw(PVE::LXC::Setup::Debian);
13
14 my $known_versions = {
15 '17.10' => 1, # artful
16 '17.04' => 1, # zesty
17 '16.10' => 1, # yakkety
18 '16.04' => 1, # xenial
19 '15.10' => 1, # wily
20 '15.04' => 1, # vivid
21 '14.04' => 1, # trusty LTS
22 '12.04' => 1, # precise LTS
23 };
24
25 sub 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
40 die "unsupported Ubuntu version '$version'\n"
41 if !$known_versions->{$version};
42
43 my $self = { conf => $conf, rootdir => $rootdir, version => $version };
44
45 $conf->{ostype} = "ubuntu";
46
47 return bless $self, $class;
48 }
49
50 sub template_fixup {
51 my ($self, $conf) = @_;
52
53 my $version = $self->{version};
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
68 if ($version eq '15.04' || $version eq '15.10' || $version eq '16.04') {
69 # edit /etc/securetty (enable login on console)
70 $self->setup_securetty($conf, qw(pts/0));
71 }
72
73 if ($version eq '12.04') {
74 # suppress log level output for udev
75 my $filename = '/etc/udev/udev.conf';
76 my $data = $self->ct_file_get_contents($filename);
77 $data =~ s/=\"err\"/=0/m;
78 $self->ct_file_set_contents($filename, $data);
79 }
80 }
81
82 sub setup_init {
83 my ($self, $conf) = @_;
84
85 my $version = $self->{version};
86
87 if ($version eq '17.10' || $version eq '17.04' || $version eq '16.10') {
88 $self->setup_container_getty_service($conf);
89 }
90
91 if ($version eq '12.04' || $version eq '14.04') {
92 my $ttycount = PVE::LXC::Config->get_tty_count($conf);
93 for (my $i = 1; $i < 7; $i++) {
94 my $filename = "/etc/init/tty$i.conf";
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
102 start on stopped rc RUNLEVEL=[2345] and (
103 not-container or
104 container CONTAINER=lxc or
105 container CONTAINER=lxc-libvirt)
106
107 stop on runlevel [!2345]
108
109 respawn
110 exec /sbin/getty -8 38400 tty$i
111 __EOD__
112 $self->ct_file_set_contents($filename, $tty_conf);
113 } else {
114 for (my $i = $ttycount + 1; $i < 7; $i++) {
115 $self->ct_unlink($filename);
116 }
117 }
118 }
119 }
120 }
121
122 sub 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
132 1;