]> git.proxmox.com Git - pve-container.git/commitdiff
setup getty: generalize setup_container_getty_service
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 18 Jul 2019 15:10:30 +0000 (17:10 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 26 Jul 2019 07:00:03 +0000 (09:00 +0200)
to allow switching the two remaining users and then finally dropping
the setup_systemd_console method

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Co-developed-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Acked-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
(cherry picked from commit bfe63c1a05a692cd8cc54c2bb7f9460ff8df93fd)
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
src/PVE/LXC/Setup/Base.pm

index e0b8244b814e53cf962943dad5f7815680479f20..e811043ecc3cc0c333f12037b4ddae749684f954 100644 (file)
@@ -216,26 +216,41 @@ sub fixup_old_getty {
 sub setup_container_getty_service {
     my ($self, $conf) = @_;
 
-    my $systemd_dir_rel = $self->ct_is_executable("/lib/systemd/systemd") ?
+    my $sd_dir = $self->ct_is_executable("/lib/systemd/systemd") ?
        "/lib/systemd/system" : "/usr/lib/systemd/system";
-    my $servicefile = "$systemd_dir_rel/container-getty\@.service";
-    my $raw = $self->ct_file_get_contents($servicefile);
+
+    # prefer container-getty.service shipped by newer systemd versions
+    # fallback to getty.service and just return if that doesn't exists either..
+    my $template_base = "container-getty\@";
+    my $template_path = "${sd_dir}/${template_base}.service";
+    my $instance_base = $template_base;
+
+    if (!$self->ct_file_exists($template_path)) {
+       $template_base = "getty\@";
+       $template_path = "${template_base}.service";
+       $instance_base = "{$template_base}tty";
+       return if !$self->ct_file_exists($template_path);
+    }
+
+    my $raw = $self->ct_file_get_contents($template_path);
     my $ttyname = $self->devttydir($conf) . 'tty%I';
     if ($raw =~ s@pts/%I|lxc/tty%I@$ttyname@g) {
-       $self->ct_file_set_contents($servicefile, $raw);
+       $self->ct_file_set_contents($template_path, $raw);
     }
 
+    my $getty_target_fn = "/etc/systemd/system/getty.target.wants/";
     my $ttycount = PVE::LXC::Config->get_tty_count($conf);
-    for (my $i = 1; $i < 7; $i++) {
-       my $getty_target_fn = "/etc/systemd/system/getty.target.wants/";
-       my $tty_service_lnk = "$getty_target_fn/container-getty\@$i.service";
 
+    for (my $i = 1; $i < 7; $i++) {
        # ensure that not two gettys are using the same tty!
        $self->ct_unlink("$getty_target_fn/getty\@tty$i.service");
+       $self->ct_unlink("$getty_target_fn/container-getty\@$i.service");
 
-       $self->ct_unlink($tty_service_lnk);
+       # re-enable only those requested
        if ($i <= $ttycount) {
-           $self->ct_symlink($servicefile, $tty_service_lnk);
+           my $tty_service = "${instance_base}${i}.service";
+
+           $self->ct_symlink($template_path, "$getty_target_fn/$tty_service");
        }
     }
 }