Operator Libs Linux

  • By Jon Seager
Channel Version Revision Published Runs on
latest/stable 1 1 28 Oct 2021
Ubuntu 20.04
juju deploy operator-libs-linux
Show information

Platform:

charms.operator_libs_linux.v1.systemd

Abstractions for stopping, starting and managing system services via systemd.

This library assumes that your charm is running on a platform that uses systemd. E.g., Centos 7 or later, Ubuntu Xenial (16.04) or later.

For the most part, we transparently provide an interface to a commonly used selection of systemd commands, with a few shortcuts baked in. For example, service_pause and service_resume with run the mask/unmask and enable/disable invocations.

Example usage:

from charms.operator_libs_linux.v0.systemd import service_running, service_reload

# Start a service
if not service_running("mysql"):
    success = service_start("mysql")

# Attempt to reload a service, restarting if necessary
success = service_reload("nginx", restart_on_failure=True)

class SystemdError

def _popen_kwargs()

def _systemctl(
    sub_cmd: str,
    service_name: str,
    now: bool,
    quiet: bool
)

Control a system service.

Arguments

sub_cmd
the systemctl subcommand to issue
service_name
the name of the service to perform the action on
now
passes the --now flag to the shell invocation.
quiet
passes the --quiet flag to the shell invocation.

def service_running(service_name: str)

Determine whether a system service is running.

Arguments

service_name
the name of the service

def service_start(service_name: str)

Start a system service.

Arguments

service_name
the name of the service to stop

def service_stop(service_name: str)

Stop a system service.

Arguments

service_name
the name of the service to stop

def service_restart(service_name: str)

Restart a system service.

Arguments

service_name
the name of the service to restart

def service_reload(
    service_name: str,
    restart_on_failure: bool
)

Reload a system service, optionally falling back to restart if reload fails.

Arguments

service_name
the name of the service to reload
restart_on_failure
boolean indicating whether to fallback to a restart if the reload fails.

def service_pause(service_name: str)

Pause a system service.

Arguments

service_name
the name of the service to pause

Description

Stop it, and prevent it from starting again at boot.

def service_resume(service_name: str)

Resume a system service.

Arguments

service_name
the name of the service to resume

Description

Re-enable starting again at boot. Start the service.

def daemon_reload()

Description

Reload systemd manager configuration. None