Skip to content

sysctl module

Sysctl

The sysctl settings, as a dict of key -> value.

Commands:

sysctl -a 2>/dev/null || true

Returns:

dict[str, Any]

Raises:

HostConnectionError

Examples:

Examples can be found in examples/modules/sysctl/sysctl_sysctl.py.

SysctlFile

The raw text of one sysctl config file, or None when it is absent.

Commands:

test -e <path> && { printf '#reemote-sysctl-file\n'; cat -- <path>; }

Returns:

str | None

Raises:

CommandNotFoundError, HostConnectionError

Examples:

Examples can be found in examples/modules/sysctl/sysctl_sysctl_file.py.

SysctlFiles

The persistent sysctl configuration, as a dict of file path -> settings.

Commands:

for f in /etc/sysctl.conf /etc/sysctl.d/*.conf; do test -f "$f" && { printf '#reemote-sysctl-files %s\n' "$f"; cat -- "$f"; }; done

Returns:

dict[str, dict[str, str]]

Raises:

CommandNotFoundError, HostConnectionError

Examples:

Examples can be found in examples/modules/sysctl/sysctl_sysctl_files.py.

conf async

conf(
    ctx: OpContext,
    settings: tuple[tuple[str, str | int], ...],
    sysctl_file: str = "/etc/sysctl.d/99-reemote.conf",
    present: bool = True,
    reload: bool = True,
    **kwargs: Any,
) -> AsyncGenerator[Command]

Ensure a whole sysctl config file matches the given settings.

Parameters:

Name Type Description Default
ctx OpContext

Execution context for the operation.

required
settings tuple[tuple[str, str | int], ...]

The (key, value) pairs to write, one key = value line each, in the given order. A tuple, not a dict: op() rejects unhashable arguments.

required
sysctl_file str

The config file to manage. Defaults to "/etc/sysctl.d/99-reemote.conf".

'/etc/sysctl.d/99-reemote.conf'
present bool

Whether the file should exist. False removes it (runtime values are left alone). Defaults to True.

True
reload bool

Run sysctl -p <sysctl_file> after a changed write so the settings apply immediately. Defaults to True.

True
**kwargs Any

Additional keyword arguments.

{}

Yields:

Name Type Description
Command AsyncGenerator[Command]

The spool transfer + elevated install (+ reload) when the content differs, or a removal when present=False and the file exists.

Raises:

CommandNotFoundError, HostConnectionError

Examples:

Examples can be found in examples/modules/sysctl/sysctl_conf.py.

setting async

setting(
    ctx: OpContext,
    key: str,
    value: str | int | list[str | int],
    present: bool = True,
    persist: bool = True,
    sysctl_file: str = "/etc/sysctl.conf",
    sysctl_set: bool = True,
    reload: bool = True,
    ignore_errors: bool = False,
    **kwargs: Any,
) -> AsyncGenerator[Command]

Ensure one kernel parameter is set (or removed from persistence).

Parameters:

Name Type Description Default
ctx OpContext

Execution context for the operation.

required
key str

The sysctl parameter name (e.g. vm.swappiness).

required
value str | int | list[str | int]

The desired value; a list joins with spaces, digits compare as ints against the runtime fact.

required
present bool

Whether the setting should exist. False removes the key's lines from the persistence file (the runtime value is left alone -- a kernel parameter cannot be "unset"). Defaults to True.

True
persist bool

Whether to manage the persistence file. Defaults to True.

True
sysctl_file str

The config file to edit when persist is set; a /etc/sysctl.d/*.conf drop-in keeps the legacy file untouched. Defaults to "/etc/sysctl.conf".

'/etc/sysctl.conf'
sysctl_set bool

Whether to apply the value to the running kernel (sysctl -w) when it differs. False manages only the file. Defaults to True.

True
reload bool

Run sysctl -p <sysctl_file> after a changed file write. Defaults to True.

True
ignore_errors bool

Append || true to the runtime command so an unknown or read-only key does not abort the run. Defaults to False.

False
**kwargs Any

Additional keyword arguments.

{}

Yields:

Name Type Description
Command AsyncGenerator[Command]

The runtime apply when the live value differs, and/or the spool transfer + elevated install (+ reload) when the file content differs.

Raises:

CommandNotFoundError, HostConnectionError

Examples:

Examples can be found in examples/modules/sysctl/sysctl_setting.py.