[pve-devel] [PATCH container 2/2] setup: add helper to disable static units when fixing up templates
Fabian Grünbichler
f.gruenbichler at proxmox.com
Fri Nov 8 14:47:44 CET 2024
> Thomas Lamprecht <t.lamprecht at proxmox.com> hat am 08.11.2024 14:40 CET geschrieben:
>
>
> Am 08/11/2024 um 14:18 schrieb Fabian Grünbichler:
> > modelled after setup_systemd_preset, which unfortunately doesn't work for
> > static units, since those are skipped by `systemctl preset-all` which runs on
> > first boot.
> >
> > our Debian-based templates already come with those masking symlinks in place.
>
> yeah, I added symlinking those units to /dev/null in the DAB and AAB
> image builders, but thanks for providing the generic way.
I didn't check all distros, there might be others that would also benefit (or at least, become a bit less noisy). But given that this is mainly to cleanup the container journal/systemctl status, it's not super important.
> >
> > Signed-off-by: Fabian Grünbichler <f.gruenbichler at proxmox.com>
> > ---
> >
> > Notes:
> > noticed while testing the openEuler template
> >
> > src/PVE/LXC/Setup/Base.pm | 23 +++++++++++++++++++++++
> > src/PVE/LXC/Setup/CentOS.pm | 2 ++
> > src/PVE/LXC/Setup/OpenEuler.pm | 1 +
> > 3 files changed, 26 insertions(+)
> >
> > diff --git a/src/PVE/LXC/Setup/Base.pm b/src/PVE/LXC/Setup/Base.pm
> > index 084b039..decd62a 100644
> > --- a/src/PVE/LXC/Setup/Base.pm
> > +++ b/src/PVE/LXC/Setup/Base.pm
> > @@ -352,6 +352,29 @@ sub setup_systemd_preset {
> > );
> > }
> >
> > +# some units cannot be disabled via presets because they are static
> > +# this helper can be called as part of template_fixup to explicitly mask them instead
> > +sub setup_systemd_disable_static_units {
> > + my ($self, $extra_units) = @_;
> > +
> > + # some don't make sense in CTs, child-plugins can add extra units via $extra_preset
> > + my $units = [
> > + 'sys-kernel-config.mount',
> > + 'sys-kernel-debug.mount',
> > + ];
> > +
> > + if (defined($extra_units)) {
> > + for my $unit (@$extra_units) {
> > + push @$units, $unit;
> > + }
> > + }
> > +
>
> would apply this with the following squashed in as there's no need for
> allocations/copies here, if you have no objection?
yes, fine by me :)
> diff --git a/src/PVE/LXC/Setup/Base.pm b/src/PVE/LXC/Setup/Base.pm
> index decd62a..bb084af 100644
> --- a/src/PVE/LXC/Setup/Base.pm
> +++ b/src/PVE/LXC/Setup/Base.pm
> @@ -363,13 +363,7 @@ sub setup_systemd_disable_static_units {
> 'sys-kernel-debug.mount',
> ];
>
> - if (defined($extra_units)) {
> - for my $unit (@$extra_units) {
> - push @$units, $unit;
> - }
> - }
> -
> - for my $unit (@$units) {
> + for my $unit ($units->@*, $extra_units->@*) {
> $self->ct_symlink('/dev/null', "/etc/systemd/system/$unit")
> if !$self->ct_file_exists("/etc/systemd/system/$unit");
> }
More information about the pve-devel
mailing list