It is possible to use systemd's manager via dbus to control services, e.g: Starting a systemd service via python using this:
import dbus
sysbus = dbus.SystemBus()
systemd1 = sysbus.get_object('org.freedesktop.systemd1', '/org/freedesktop/systemd1')
manager = dbus.Interface(systemd1, 'org.freedesktop.systemd1.Manager')
job = manager.RestartUnit('test.service', 'fail')
However, systemd can also handle user's service files with the --user
flag, e.g.:
systemctl --user start test.service
How can the user's manager be used from dbus (with python)? Replacing dbus.SystemBus()
with dbus.Bus()
or dbus.SessionBus()
did not do the trick, as this gives:
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.Spawn.ChildExited: Process org.freedesktop.systemd1 exited with status 1