The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

App::LXC::Container::Update - update real LXC configuration

SYNOPSIS

    lxc-app-update <container>

ABSTRACT

This is the module used to (re-)create the real concrete configuration for an LXC application container from one (or more) meta-configurations created with App::LXC::Container::Create (via its calling script lxc-app-setup). It is called from lxc-app-update via the main module App::LXC::Container.

DESCRIPTION

The module takes the default configuration for the operating system and meta-configuration for one (or more) containers to create one long real concrete configuration file for LXC itself. Each section of this created configuration file starts with a comment naming the corresponding (used) meta-configuration file to make debugging and analysis easy.

MAIN METHODS

The module defines the following main methods which are used by App::LXC::Container:

new - create configuration object for application container

    $configuration = App::LXC::Container::Update->new(@container);

parameters:

    @container          name of the container(s) to be configured

description:

This is the constructor for the object used to transform the meta-configuration into the real one. It reads all global configuration files. Note that the name of the last container is the one actually used for the created configuration (as it's the one overwriting most other configurations, see _parse methods for details).

returns:

the configuration object for the application container

main - transform meta-configuration(s) into real one

    $configuration->main();

description:

This method reads the meta-configuration files for the operating system and the specified container(s), analysis them and creates the real LXC application container configuration.

network_number - return current container's network number

    $network_number = $self->network_number();

description:

This method determines the network number (the last number of the IP v4 network address) of the current container. If the number is not yet defined the next free number is used and stored in the global network configuration file.

returns:

current container's network number

HELPER METHODS

The following methods should not be used outside of this module itself:

_create_mount_points - create all mount points for path

    $self->_create_mount_points($mounts, '/');

parameters:

    $path               root path
    $mounts             App::LXC::Container::Mounts object

description:

This method (recursively) creates all (real) mount-points below (including) the given path.

_make_lxc_path - create path in LXC directory tree of container

    $self->_make_lxc_path($path);

parameters:

    $path               the path to be created

description:

This method creates the given path below the containers LXC directory (usually /var/lib/lxc/CONTAINER). The path will have the same permissions as the original one. If the update is run by root, it will also have the same ownership as the original one.

_parse_filter - parse filter configuration file

    $self->_parse_filter();

description:

This method parses the applicable global special filter meta-configuration files and those of the chosen container(s) into the configuration object.

Note that in the case of multiple containers the filter configurations are merged and only the last occurrence of a filter is the one used in the created LXC configuration file.

_parse_master - parse master configuration file(s)

    $self->_parse_master();

description:

This method parses the master meta-configuration file(s) of the chosen container(s) into the configuration object.

Note that in the case of multiple containers the master configurations are merged and the least restrictive (e.g. full network access) overrides the more restrictive ones (e.g. only local network) regardless of their sequence.

_parse_mounts - parse mounts configuration file

    $self->_parse_mounts();

description:

This method parses the applicable global special mounts meta-configuration files and those of the chosen container(s) into the configuration object.

Note that in the case of multiple containers the mounts configurations are merged and only the last occurrence of a mount-point is the one used in the created LXC configuration file.

_parse_packages - parse packages configuration file

    $self->_parse_packages();

description:

This method parses the applicable global packages meta-configuration files and those of the chosen container(s) into the configuration object.

Note that in the case of multiple containers the packages configurations are merged and only the first occurrence of a package is the one reported in the comment of the created LXC configuration file.

_parse_specials - parse special configuration file

    $self->_parse_specials();

description:

This method parses the container's optional special configuration file(s) into the configuration object.

_parse_users - add mounts for users' home directories

    $self->_parse_users();

description:

This method parses /etc/passwd to add the users' home directories to the list of global mounts.

TODO: better move reading of passwd to new function ...::Data::users_homes

_write_lxc_configuration - write LXC configuration file

    $self->_write_lxc_configuration();

description:

This method writes the parsed meta-configuration into the real concrete LXC configuration file for the selected (command-line) application container.

SEE ALSO

man pages lxc.container.conf, lxc and lxcfs

LXC documentation on https://linuxcontainers.org

LICENSE

Copyright (C) Thomas Dorner.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See LICENSE file for more details.

AUTHOR

Thomas Dorner <dorner (at) cpan (dot) org>

Contributors

none so far