[pve-devel] [PATCH] add Alpine Linux distribution

Jens Vehlhaber jens at eisfair.org
Tue Dec 8 08:00:15 CET 2015


Signed-off-by: Jens Vehlhaber <jens at eisfair.org>
---
 src/PVE/LXC.pm              |  4 ++--
 src/PVE/LXC/Setup.pm        |  5 ++++-
 src/PVE/LXC/Setup/Alpine.pm | 48 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 54 insertions(+), 3 deletions(-)
 create mode 100644 src/PVE/LXC/Setup/Alpine.pm

diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index 38ce71c..40d320f 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -98,7 +98,7 @@ my $confdesc = {
     ostype => {
 	optional => 1,
 	type => 'string',
-	enum => ['debian', 'ubuntu', 'centos', 'fedora', 'opensuse', 'archlinux'],
+	enum => ['debian', 'ubuntu', 'centos', 'fedora', 'opensuse', 'archlinux', 'alpine'],
 	description => "OS type. Corresponds to lxc setup scripts in /usr/share/lxc/config/<ostype>.common.conf.",
     },
     console => {
@@ -1072,7 +1072,7 @@ sub update_lxc_config {
     my $custom_idmap = grep { $_->[0] eq 'lxc.id_map' } @{$conf->{lxc}};
 
     my $ostype = $conf->{ostype} || die "missing 'ostype' - internal error";
-    if ($ostype =~ /^(?:debian | ubuntu | centos | fedora | opensuse | archlinux)$/x) {
+    if ($ostype =~ /^(?:debian | ubuntu | centos | fedora | opensuse | archlinux | alpine)$/x) {
 	$raw .= "lxc.include = /usr/share/lxc/config/$ostype.common.conf\n";
 	if ($unprivileged || $custom_idmap) {
 	    $raw .= "lxc.include = /usr/share/lxc/config/$ostype.userns.conf\n"
diff --git a/src/PVE/LXC/Setup.pm b/src/PVE/LXC/Setup.pm
index 20f8530..b932be6 100644
--- a/src/PVE/LXC/Setup.pm
+++ b/src/PVE/LXC/Setup.pm
@@ -11,6 +11,7 @@ use PVE::LXC::Setup::Redhat;
 use PVE::LXC::Setup::Fedora;
 use PVE::LXC::Setup::SUSE;
 use PVE::LXC::Setup::ArchLinux;
+use PVE::LXC::Setup::Alpine;
 
 my $plugins = {
     debian    => 'PVE::LXC::Setup::Debian',
@@ -19,6 +20,7 @@ my $plugins = {
     fedora    => 'PVE::LXC::Setup::Fedora',
     opensuse  => 'PVE::LXC::Setup::SUSE',
     archlinux => 'PVE::LXC::Setup::ArchLinux',
+    alpine    => 'PVE::LXC::Setup::Alpine',
 };
 
 my $autodetect_type = sub {
@@ -42,8 +44,9 @@ my $autodetect_type = sub {
 	return "redhat";
     } elsif (-f  "$rootdir/etc/arch-release") {
 	return "archlinux";
+    } elsif (-f  "$rootdir/etc/alpine-release") {
+	return "alpine";
     }
-
     die "unable to detect OS disribution\n";
 };
 
diff --git a/src/PVE/LXC/Setup/Alpine.pm b/src/PVE/LXC/Setup/Alpine.pm
new file mode 100644
index 0000000..b32c798
--- /dev/null
+++ b/src/PVE/LXC/Setup/Alpine.pm
@@ -0,0 +1,48 @@
+package PVE::LXC::Setup::Alpine;
+
+use strict;
+use warnings;
+
+use Data::Dumper;
+use PVE::LXC;
+use PVE::Network;
+use File::Path;
+
+use PVE::LXC::Setup::Base;
+
+use base qw(PVE::LXC::Setup::Base);
+
+sub new {
+    my ($class, $conf, $rootdir) = @_;
+    my $self = { conf => $conf, rootdir => $rootdir, version => 0 };
+    $conf->{ostype} = "alpine";
+    return bless $self, $class;
+}
+
+sub template_fixup {
+    my ($self, $conf) = @_;
+    my $rootdir = $self->{rootdir};
+    # enable networking service
+    $self->ct_symlink('/etc/init.d/networking',
+                      '/etc/runlevels/boot/networking');
+    # fixup any symlinks
+    $self->ct_symlink('/etc/init.d/bootmisc',
+                      '/etc/runlevels/boot/bootmisc');
+    $self->ct_symlink('/etc/init.d/hostname',
+                      '/etc/runlevels/boot/hostname');                                            
+    # fix stop system                  
+    $self->ct_symlink('/etc/init.d/killprocs',
+                      '/etc/runlevels/shutdown/killprocs'); 
+    $self->ct_symlink('/etc/init.d/savecache',
+                      '/etc/runlevels/shutdown/savecache');                            
+}
+
+sub setup_init {
+    # Nothing to do
+}
+
+sub setup_network {
+    # Nothing to do
+}
+
+1;
-- 
2.4.1



More information about the pve-devel mailing list