Skip to main content
Manage sysvinit services (/etc/init.d).

Functions

sysvinit.service

Manage the state of SysV Init (/etc/init.d) services.
sysvinit.service(
    service,
    running=True,
    restarted=False,
    reloaded=False,
    enabled=None,
    command=None,
)
Enabled: Because managing /etc/rc.d/X files is a mess, only certain Linux distributions support enabling/disabling services:
  • Ubuntu/Debian (update-rc.d)
  • Fedora/RHEL (chkconfig)
  • Gentoo (rc-update)
For other distributions and more granular service control, see the sysvinit.enable operation.

sysvinit.enable

Manually enable /etc/init.d scripts by creating /etc/rcX.d/Y links.
sysvinit.enable(
    service,
    start_priority=20,
    stop_priority=80,
    start_levels=(2, 3, 4, 5),
    stop_levels=(0, 1, 6),
)

Examples

from pyinfra.operations import sysvinit

# Restart and enable rsyslog
sysvinit.service(
    name="Restart and enable rsyslog",
    service="rsyslog",
    restarted=True,
    enabled=True,
)

# Finer control on which runlevels rsyslog should run
sysvinit.enable(
    name="Finer control on which runlevels rsyslog should run",
    service="rsyslog",
    start_levels=(3, 4, 5),
    stop_levels=(0, 1, 2, 6),
)

Build docs developers (and LLMs) love