Systemd Operations

Manage systemd services.

systemd.daemon_reload

Reload the systemd daemon to read unit file changes.

systemd.daemon_reload()

systemd.service

Manage the state of systemd managed units.

systemd.service(
    service, running=True, restarted=False, reloaded=False, command=None, enabled=None,
    daemon_reload=False,
)
  • service: name of the systemd unit to manage
  • running: whether the unit should be running
  • restarted: whether the unit should be restarted
  • reloaded: whether the unit should be reloaded
  • command: custom command to pass like: /etc/rc.d/<name> <command>
  • enabled: whether this unit should be enabled/disabled on boot
  • daemon_reload: reload the systemd daemon to read updated unit files

Example:

systemd.service(
    name='Restart and enable the dnsmasq service',
    service='dnsmasq.service',
    running=True,
    restarted=True,
    enabled=True,
)

systemd.service(
    name='Enable logrotate timer',
    service='logrotate.timer',
    running=True,
    enabled=True,
)