Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How should I start, restart, stop a service? #60

Open
GreatBahram opened this issue Mar 1, 2021 · 4 comments
Open

How should I start, restart, stop a service? #60

GreatBahram opened this issue Mar 1, 2021 · 4 comments

Comments

@GreatBahram
Copy link

GreatBahram commented Mar 1, 2021

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

@ddibiasi
Copy link

ddibiasi commented Aug 10, 2021

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

@vinnyvinny1989
Copy link

vinnyvinny1989 commented Jul 29, 2022

Does anyone know how to start the service with sudo?

@ThomasFreedman
Copy link

ThomasFreedman commented Jun 12, 2023

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.

@gustavojoseleite
Copy link

gustavojoseleite commented Jul 6, 2023

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants