Skip to content

openrc

OpenrcConfigFile

The current content of an OpenRC configuration file, or None when absent.

Commands:

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

Returns:

str | None

Raises:

CommandNotFoundError, HostConnectionError

Examples:

Examples can be found in examples/modules/openrc/openrc_config.py.

OpenrcEnabled

Whether each OpenRC service is enabled in a runlevel.

Commands:

rc-update show -v

Returns:

dict[str, bool]

Raises:

CommandNotFoundError, HostConnectionError

Examples:

Examples can be found in examples/modules/openrc/openrc_openrc_enabled.py.

OpenrcRunlevels

The runlevels and the service names assigned to each.

Commands:

ls -R /etc/runlevels 2>/dev/null || true

Returns:

dict[str, list[str]]

Raises:

HostConnectionError

Examples:

Examples can be found in examples/modules/openrc/openrc_openrc_runlevels.py.

OpenrcServices

The raw state word of each OpenRC service in a runlevel.

Commands:

rc-status <runlevel>

Returns:

dict[str, str]

Raises:

CommandNotFoundError, HostConnectionError

Examples:

Examples can be found in examples/modules/openrc/openrc_openrc_services.py.

OpenrcStatus

Whether each OpenRC service in a runlevel is running.

Commands:

rc-status <runlevel>

Returns:

dict[str, bool]

Raises:

CommandNotFoundError, HostConnectionError

Examples:

Examples can be found in examples/modules/openrc/openrc_openrc_status.py.

OpenrcVersion

The installed OpenRC version, or None without OpenRC.

Commands:

openrc --version 2>/dev/null || true

Returns:

str | None

Raises:

HostConnectionError

Examples:

Examples can be found in examples/modules/openrc/openrc_openrc_version.py.

config async

config(
    ctx: OpContext,
    key: str,
    value: str,
    service: str | None = None,
    present: bool = True,
    **kwargs: Any,
) -> AsyncGenerator[Command]

Set or unset a variable in /etc/rc.conf or a service's /etc/conf.d file.

Parameters:

Name Type Description Default
ctx OpContext

Execution context for the operation.

required
key str

Name of the shell variable to manage -- a shell identifier such as rc_parallel.

required
value str

The value to assign, rendered as key="value" (the file is sourced by the shell). Must not contain ", \, $, a backtick or a newline. Ignored when present=False.

required
service str | None

The service whose /etc/conf.d/<service> file to edit; None edits the global /etc/rc.conf. Defaults to None.

None
present bool

Whether the variable should be set (True) or unset (False -- every assignment of key is dropped, commented-out ones included). Defaults to True.

True
**kwargs Any

Additional keyword arguments.

{}

Yields:

Name Type Description
Command AsyncGenerator[Command]

Generated openrc config spool-and-install commands.

Raises:

CommandNotFoundError, HostConnectionError, ValueError

Examples:

Examples can be found in examples/modules/openrc/openrc_config.py.

custom_runlevel async

custom_runlevel(
    ctx: OpContext,
    runlevel: str,
    present: bool = True,
    stacked_to: str | None = None,
    **kwargs: Any,
) -> AsyncGenerator[Command]

Create or remove a custom OpenRC runlevel, optionally stacked.

Parameters:

Name Type Description Default
ctx OpContext

Execution context for the operation.

required
runlevel str

Name of the custom runlevel to create or remove (a directory under /etc/runlevels).

required
present bool

Whether the runlevel should exist (True) or be removed (False). Defaults to True.

True
stacked_to str | None

An existing runlevel to stack this one onto (rc-update -s add, so entering the target also enters this runlevel); None leaves stacking alone. Ignored on the present=False direction -- removal always unstacks from every target the facts report. Defaults to None.

None
**kwargs Any

Additional keyword arguments.

{}

Yields:

Name Type Description
Command AsyncGenerator[Command]

Generated runlevel-directory and rc-update commands.

Raises:

HostConnectionError, ValueError

Examples:

Examples can be found in examples/modules/openrc/openrc_custom_runlevel.py.

runlevel async

runlevel(
    ctx: OpContext,
    service: str,
    runlevel: str = "default",
    enabled: bool = True,
    **kwargs: Any,
) -> AsyncGenerator[Command]

Add or remove a service from an OpenRC runlevel.

Parameters:

Name Type Description Default
ctx OpContext

Execution context for the operation.

required
service str

Name of the service (its /etc/init.d script name) to assign or unassign.

required
runlevel str

The runlevel to manage the assignment in. Defaults to "default".

'default'
enabled bool

Whether the service should be assigned to the runlevel (True, rc-update add) or removed from it (False, rc-update del). Defaults to True.

True
**kwargs Any

Additional keyword arguments.

{}

Yields:

Name Type Description
Command AsyncGenerator[Command]

Generated rc-update commands.

Raises:

CommandNotFoundError, HostConnectionError

Examples:

Examples can be found in examples/modules/openrc/openrc_runlevel.py.

service async

service(
    ctx: OpContext,
    service: str,
    running: bool | None = True,
    restarted: bool = False,
    reloaded: bool = False,
    enabled: bool | None = None,
    runlevel: str = "default",
    **kwargs: Any,
) -> AsyncGenerator[Command]

Manage the state of an OpenRC service.

Parameters:

Name Type Description Default
ctx OpContext

Execution context for the operation.

required
service str

Name of the service to manage (its /etc/init.d script name).

required
running bool | None

Whether the service should be running (True), stopped (False), or left alone (None). Defaults to True.

True
restarted bool

Whether to restart the service (only if it is already running). Defaults to False.

False
reloaded bool

Whether to reload the service (only if it is already running). Defaults to False.

False
enabled bool | None

Whether the service should be enabled in runlevel at boot; None leaves the boot setting alone. Defaults to None.

None
runlevel str

The runlevel the status and boot settings are managed for. Defaults to "default".

'default'
**kwargs Any

Additional keyword arguments.

{}

Yields:

Name Type Description
Command AsyncGenerator[Command]

Generated rc-service and rc-update commands.

Raises:

CommandNotFoundError, HostConnectionError

Examples:

Examples can be found in examples/modules/openrc/openrc_service.py.