]> git.proxmox.com Git - pve-container.git/blame - src/PVE/LXC/Setup/Alpine.pm
fix #4192: revamp check for systemd version
[pve-container.git] / src / PVE / LXC / Setup / Alpine.pm
CommitLineData
a8700492
JV
1package PVE::LXC::Setup::Alpine;
2
3use strict;
4use warnings;
5
a8700492
JV
6use PVE::LXC;
7use PVE::Network;
8use File::Path;
9
10use PVE::LXC::Setup::Base;
d93a2739 11use PVE::LXC::Setup::Debian;
a8700492
JV
12
13use base qw(PVE::LXC::Setup::Base);
14
15sub new {
16 my ($class, $conf, $rootdir) = @_;
b46d6081
WB
17
18 my $version = PVE::Tools::file_read_firstline("$rootdir/etc/alpine-release");
19
20 my $self = { conf => $conf, rootdir => $rootdir, version => $version };
a8700492
JV
21 $conf->{ostype} = "alpine";
22 return bless $self, $class;
23}
24
5e84bdc8
DM
25# Alpine doesn't support the /dev/lxc/ subdirectory.
26sub devttydir {
27 return '';
28}
29
a8700492
JV
30sub template_fixup {
31 my ($self, $conf) = @_;
855b0646 32
a8700492 33 # enable networking service
49a2a72a 34 $self->ct_symlink('/etc/init.d/networking', '/etc/runlevels/boot/networking');
a8700492 35 # fixup any symlinks
49a2a72a
TL
36 $self->ct_symlink('/etc/init.d/bootmisc', '/etc/runlevels/boot/bootmisc');
37 $self->ct_symlink('/etc/init.d/hostname', '/etc/runlevels/boot/hostname');
e9076752 38 # fix stop system
49a2a72a
TL
39 $self->ct_symlink('/etc/init.d/killprocs', '/etc/runlevels/shutdown/killprocs');
40 $self->ct_symlink('/etc/init.d/savecache', '/etc/runlevels/shutdown/savecache');
6077b5dd 41
5e84bdc8 42 $self->setup_securetty($conf);
a8700492
JV
43}
44
45sub setup_init {
0c63baec
TL
46 my ($self, $conf) = @_;
47
48 my $filename = "/etc/inittab";
49 return if !$self->ct_file_exists($filename);
50
51 my $ttycount = PVE::LXC::Config->get_tty_count($conf);
52 my $inittab = $self->ct_file_get_contents($filename);
53
54 my @lines = grep {
49a2a72a 55 !/^\s*tty\d+:\d*:[^:]*:.*getty/ # remove getty lines
0c63baec
TL
56 } split(/\n/, $inittab);
57
58 $inittab = join("\n", @lines) . "\n";
59
60 for (my $id = 1; $id <= $ttycount; $id++) {
61 next if $id == 7; # reserved for X11
62 $inittab .= "tty$id\::respawn:/sbin/getty 38400 tty$id\n";
63 }
64
65 $self->ct_file_set_contents($filename, $inittab);
a8700492
JV
66}
67
68sub setup_network {
d93a2739
WB
69 # Network is debian compatible, but busybox' udhcpc6 is unfinished
70 my ($self, $conf) = @_;
71
72 # XXX: udhcpc6 in busybox is broken; once a working alpine release comes
73 # we can remove this bit.
74 #
75 # Filter out ipv6 dhcp and turn it into 'manual' so they see what's up.
c09b2996
SI
76 #
77 # XXX: slaac works different from debian - busybox has no 'auto'
78 # configuration type - https://wiki.alpinelinux.org/wiki/Configure_Networking#IPv6_Stateless_Autoconfiguration
79 # the suggested configuration sadly does not take the interface up, but
80 # at least with the workaround the networking starts and if an ipv4 is
81 # configured slaac for ipv6 works (unless accept_ra = 0 in the node)
82
264755b8 83 my $newconf = {};
d93a2739
WB
84 my $networks = {};
85 foreach my $k (keys %$conf) {
264755b8
TL
86 my $value = $conf->{$k};
87 $newconf->{$k} = $value;
d93a2739 88 next if $k !~ m/^net(\d+)$/;
264755b8
TL
89
90 my $netstring = $value;
d93a2739 91 # check for dhcp6:
1b4cf758 92 my $d = PVE::LXC::Config->parse_lxc_network($netstring);
c09b2996 93 if (defined($d->{ip6}) && ($d->{ip6} eq 'dhcp' || $d->{ip6} eq 'auto')) {
d93a2739 94 $d->{ip6} = 'manual';
1b4cf758 95 $netstring = PVE::LXC::Config->print_lxc_network($d);
d93a2739 96 }
264755b8 97 $newconf->{$k} = $netstring;
d93a2739
WB
98 }
99
264755b8 100 PVE::LXC::Setup::Debian::setup_network($self, $newconf);
a8700492
JV
101}
102
766ffcc9
SI
103# non systemd based containers work with pure cgroupv2
104sub unified_cgroupv2_support {
917f7ae3 105 my ($self, $init) = @_;
766ffcc9
SI
106
107 return 1;
108}
109
a8700492 1101;