Action Utils

Several utilities to help with the implementation of actions and diagnostic tests are implemented in this module.

Python action utility functions.

class plinth.action_utils.WebserverChange[source]

Context to restart/reload Apache after configuration changes.

__init__()[source]

Initialize the context object state.

disable(name, kind='config')[source]

Disable a config/module/site in Apache.

Don’t apply the changes until the context is exited.

enable(name, kind='config')[source]

Enable a config/module/site in Apache.

Don’t apply the changes until the context is exited.

plinth.action_utils.apt_hold(packages)[source]

Prevent packages from being removed during apt operations.

apt-mark hold PACKAGES accepts a list of packages. But if one of the package is missing from the apt repository, then it will fail to hold any of the listed packages. So it is necessary to try to hold each package by itself.

Packages held by this context will be unheld when leaving the context. But if a package was already held beforehand, it will be ignored (and not unheld).

plinth.action_utils.apt_hold_freedombox()[source]

Prevent freedombox package from being removed during apt operations.

plinth.action_utils.apt_unhold_freedombox()[source]

Remove any hold on freedombox package, and clear flag.

plinth.action_utils.debconf_set_selections(presets)[source]

Answer debconf questions before installing a package.

plinth.action_utils.dpkg_reconfigure(package, config)[source]

Reconfigure package using debconf database override.

plinth.action_utils.get_addresses()[source]

Return a list of IP addresses and hostnames.

plinth.action_utils.get_hostname()[source]

Return the current hostname.

plinth.action_utils.get_ip_addresses()[source]

Return a list of IP addresses assigned to the system.

plinth.action_utils.is_disk_image()[source]

Return whether the current machine is from a disk image.

Two primary ways to install FreedomBox are: - Using FreedomBox image for various hardware platforms. - Installing packages on a Debian machine using apt.

plinth.action_utils.is_package_manager_busy()[source]

Return whether package manager is busy. This command uses the lsof command to check whether the dpkg lock file is open which indicates that the package manager is busy

plinth.action_utils.is_systemd_running()[source]

Return if we are running under systemd.

plinth.action_utils.run_apt_command(arguments)[source]

Run apt-get with provided arguments.

plinth.action_utils.service_action(service_name, action)[source]

Perform the given action on the service_name.

plinth.action_utils.service_daemon_reload()[source]

Reload systemd to ensure that newer unit files are read.

plinth.action_utils.service_disable(service_name)[source]

Disable and stop service in systemd and sysvinit using update-rc.d.

plinth.action_utils.service_enable(service_name)[source]

Enable and start a service in systemd and sysvinit using update-rc.d.

plinth.action_utils.service_is_enabled(service_name, strict_check=False)[source]

Check if service is enabled in systemd.

In some cases, after disabling a service, systemd puts it into a state called ‘enabled-runtime’ and returns a positive response to ‘is-enabled’ query. Until we understand better, a conservative work around is to pass strict=True to services effected by this behavior.

plinth.action_utils.service_is_running(servicename)[source]

Return whether a service is currently running.

Does not need to run as root.

plinth.action_utils.service_mask(service_name)[source]

Mask a service

plinth.action_utils.service_reload(service_name)[source]

Reload a service with systemd or sysvinit.

plinth.action_utils.service_restart(service_name)[source]

Restart a service with systemd or sysvinit.

plinth.action_utils.service_start(service_name)[source]

Start a service with systemd or sysvinit.

plinth.action_utils.service_stop(service_name)[source]

Stop a service with systemd or sysvinit.

plinth.action_utils.service_try_restart(service_name)[source]

Try to restart a service with systemd or sysvinit.

plinth.action_utils.service_unmask(service_name)[source]

Unmask a service

plinth.action_utils.uwsgi_disable(config_name)[source]

Disable a uwsgi configuration that runs under uwsgi.

plinth.action_utils.uwsgi_enable(config_name)[source]

Enable a uwsgi configuration that runs under uwsgi.

plinth.action_utils.uwsgi_is_enabled(config_name)[source]

Return whether a uwsgi config is enabled.

plinth.action_utils.webserver_disable(name, kind='config', apply_changes=True)[source]

Disable config/module/site in Apache.

Restart/reload the webserver if apply_changes is True. Return whether restart(‘restart’), reload(‘reload’) or no action (None) is required. If changes have been applied, then performed action is returned.

plinth.action_utils.webserver_enable(name, kind='config', apply_changes=True)[source]

Enable a config/module/site in Apache.

Restart/reload the webserver if apply_changes is True. Return whether restart(‘restart’), reload(‘reload’) or no action (None) is required. If changes have been applied, then performed action is returned.

plinth.action_utils.webserver_is_enabled(name, kind='config')[source]

Return whether a config/module/site is enabled in Apache.