systemd/pystemd

How should I start, restart, stop a service?

Opened this issue · 4 comments

Hello there,

I was reading the document of this project, and, interestingly, I couldn't find any way to restart or start a service?
Any suggestions? Could you update your documents, please?

In [12]: m.Manager.EnableUnitFiles?
Signature: m.Manager.EnableUnitFiles(*args)
Docstring: <no docstring>
File:      ~/.local/lib/python3.8/site-packages/pystemd/base.py
Type:      method

This API asks for three parameters; neither name of these parameters nor the type of them is defined or documented anywhere!

Another suggestion, maybe it's better to accept a string from the user and convert it to bytes inside pystemd module.

Thanks

Having looked at the documentation again and after reading this StackOverflow answer, I think this is the correct way to start, stop and restart services:

with Unit(b'your-service.service') as service:
    service.Unit.Start('replace') # Start
    service.Unit.Stop('replace') # Stop
    service.Unit.Restart('replace') # Restart

Does anyone know how to start the service with sudo?

Does anyone know how to start the service with sudo?

That is my question as well. I was hoping to eliminate the systemctl subprocess with pystemd in my user mode application (I need to restart a unit after changing a config file) but I don't see how to do it with this package or any other.

I got the following error when tried to start a service:

unit.Unit.Start(b'replace')
Traceback (most recent call last):
File "", line 1, in
File "/home/nvidia/.local/lib/python3.6/site-packages/pystemd/base.py", line 191, in _call
return func(self, name, *args)
File "/home/nvidia/.local/lib/python3.6/site-packages/pystemd/base.py", line 161, in _call_method
return self._auto_call_dbus_method(method_name, in_args, *args)
File "/home/nvidia/.local/lib/python3.6/site-packages/pystemd/base.py", line 185, in _auto_call_dbus_method
call_args,
File "pystemd/dbuslib.pyx", line 446, in pystemd.dbuslib.DBus.call_method
pystemd.dbusexc.DBusAccessDeniedError: [err -13]: b'Rejected send message, 2 matched rules; type="method_call", sender=":1.151" (uid=1000 pid=23357 comm="python3 ") interface="org.freedesktop.systemd1.Unit" member="Start" error name="(unset)" requested_reply="0" destination="org.freedesktop.systemd1" (uid=0 pid=1 comm="/lib/systemd/systemd --system --deserialize 18 ")'

Someone knows what means?