[pve-devel] [PATCH container v2 1/5] getty setup: move hack for old systemd getty services out
Thomas Lamprecht
t.lamprecht at proxmox.com
Thu Jul 18 18:36:58 CEST 2019
This makes it easier to remove the setup_systemd_console method in
the future.
Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
new in v2
src/PVE/LXC/Setup/Base.pm | 43 ++++++++++++++++++++++---------------
src/PVE/LXC/Setup/CentOS.pm | 2 ++
src/PVE/LXC/Setup/SUSE.pm | 2 ++
3 files changed, 30 insertions(+), 17 deletions(-)
diff --git a/src/PVE/LXC/Setup/Base.pm b/src/PVE/LXC/Setup/Base.pm
index f5f8b0d..791be32 100644
--- a/src/PVE/LXC/Setup/Base.pm
+++ b/src/PVE/LXC/Setup/Base.pm
@@ -165,23 +165,6 @@ sub setup_systemd_console {
return if !$self->ct_file_exists($systemd_getty_service_rel);
- my $raw = $self->ct_file_get_contents($systemd_getty_service_rel);
-
- my $systemd_container_getty_service_rel = "$systemd_dir_rel/container-getty\@.service";
-
- # systemd on CenoOS 7.1 is too old (version 205), so there is no
- # container-getty service
- if (!$self->ct_file_exists($systemd_container_getty_service_rel)) {
- if ($raw =~ s!^ConditionPathExists=/dev/tty0$!ConditionPathExists=/dev/tty!m) {
- $self->ct_file_set_contents($systemd_getty_service_rel, $raw);
- }
- } else {
- # undo above change (in case someone updated systemd)
- if ($raw =~ s!^ConditionPathExists=/dev/tty$!ConditionPathExists=/dev/tty0!m) {
- $self->ct_file_set_contents($systemd_getty_service_rel, $raw);
- }
- }
-
my $ttycount = PVE::LXC::Config->get_tty_count($conf);
for (my $i = 1; $i < 7; $i++) {
@@ -204,6 +187,32 @@ sub devttydir {
return $conf->{unprivileged} ? '' : 'lxc/';
}
+sub fixup_old_getty {
+ my ($self) = @_;
+
+ my $sd_dir_rel = $self->ct_is_executable("/lib/systemd/systemd") ?
+ "/lib/systemd/system" : "/usr/lib/systemd/system";
+
+ my $sd_getty_service_rel = "$sd_dir_rel/getty\@.service";
+ return if !$self->ct_file_exists($sd_getty_service_rel);
+
+ my $raw = $self->ct_file_get_contents($sd_getty_service_rel);
+
+ my $sd_container_getty_service_rel = "$sd_dir_rel/container-getty\@.service";
+ # systemd on CenoOS 7.1 is too old (version 205), so there is no
+ # container-getty service
+ if (!$self->ct_file_exists($sd_container_getty_service_rel)) {
+ if ($raw =~ s!^ConditionPathExists=/dev/tty0$!ConditionPathExists=/dev/tty!m) {
+ $self->ct_file_set_contents($sd_getty_service_rel, $raw);
+ }
+ } else {
+ # undo above change (in case someone updated systemd)
+ if ($raw =~ s!^ConditionPathExists=/dev/tty$!ConditionPathExists=/dev/tty0!m) {
+ $self->ct_file_set_contents($sd_getty_service_rel, $raw);
+ }
+ }
+}
+
sub setup_container_getty_service {
my ($self, $conf) = @_;
diff --git a/src/PVE/LXC/Setup/CentOS.pm b/src/PVE/LXC/Setup/CentOS.pm
index 748dd5b..f72dbc0 100644
--- a/src/PVE/LXC/Setup/CentOS.pm
+++ b/src/PVE/LXC/Setup/CentOS.pm
@@ -115,6 +115,8 @@ sub setup_init {
# edit/etc/securetty
+ $self->fixup_old_getty();
+
$self->setup_systemd_console($conf);
}
diff --git a/src/PVE/LXC/Setup/SUSE.pm b/src/PVE/LXC/Setup/SUSE.pm
index e5ee752..4a037b4 100644
--- a/src/PVE/LXC/Setup/SUSE.pm
+++ b/src/PVE/LXC/Setup/SUSE.pm
@@ -60,6 +60,8 @@ sub template_fixup {
sub setup_init {
my ($self, $conf) = @_;
+ $self->fixup_old_getty();
+
if ($self->{setup_ct_getty_service}) {
$self->setup_container_getty_service($conf);
}
--
2.20.1
More information about the pve-devel
mailing list