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

Can't get to the unit methods. I want to be able to stop/start and test its status. #5

Closed
polymerchm opened this issue Nov 5, 2024 · 1 comment

Comments

@polymerchm
Copy link

`def is_service_active(service: str)->bool:

"""
use sdbus to check on statue of service

"""
systemd = Systemd(sdbus.sd_bus_open_system())
try:
    unit_object_path = systemd.get_unit(service)
except Exception as e:
    print(f"no such unit {e}")
    sys.exit()
unit = SystemdUnit(unit_object_path)
print(unit.description)
return True`

if name=="main":
service = "ssh.service"
print(f" is the the service {service} running? -> {is_service_active(service)}")

return the following errors:

pi@dawntest:/Programming/python-sdbus-wifi-connect $ cd /home/pi/Programming/python-sdbus-wifi-connect ; /usr/bin/env sudo -E /home/pi/Programming/python-sdbus-wifi-connect/venv/bin/python /home/pi/.vscode-server/extensions/ms-python.debugpy-2024.12.0/bundled/libs/debugpy/adapter/../../debugpy/launcher 38367 -- /home/pi/Programming/python-sdbus-wifi-connect/src/utility.py
Traceback (most recent call last):
File "/usr/lib/python3.11/runpy.py", line 198, in _run_module_as_main
return _run_code(code, main_globals, None,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/runpy.py", line 88, in _run_code
exec(code, run_globals)
File "/home/pi/.vscode-server/extensions/ms-python.debugpy-2024.12.0/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/main.py", line 71, in
cli.main()
File "/home/pi/.vscode-server/extensions/ms-python.debugpy-2024.12.0/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 501, in main
run()
File "/home/pi/.vscode-server/extensions/ms-python.debugpy-2024.12.0/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 351, in run_file
runpy.run_path(target, run_name="main")
File "/home/pi/.vscode-server/extensions/ms-python.debugpy-2024.12.0/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 310, in run_path
return _run_module_code(code, init_globals, run_name, pkg_name=pkg_name, script_name=fname)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/pi/.vscode-server/extensions/ms-python.debugpy-2024.12.0/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 127, in _run_module_code
_run_code(code, mod_globals, init_globals, mod_name, mod_spec, pkg_name, script_name)
File "/home/pi/.vscode-server/extensions/ms-python.debugpy-2024.12.0/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 118, in _run_code
exec(code, run_globals)
File "/home/pi/Programming/python-sdbus-wifi-connect/src/utility.py", line 212, in
print(f" is the the service {service} running? -> {is_service_active(service)}")
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/pi/Programming/python-sdbus-wifi-connect/src/utility.py", line 203, in is_service_active
print(unit.description)
^^^^^^^^^^^^^^^^
File "/home/pi/Programming/python-sdbus-wifi-connect/venv/lib/python3.11/site-packages/sdbus/dbus_proxy_sync_property.py", line 82, in get
reply_message = obj._dbus.attached_bus.call(new_call_message)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
sd_bus_internals.SdBusUnmappedMessageError: ('System.Error.ENOTCONN', 'Transport endpoint is not connected')
pi@dawntest:
/Programming/python-sdbus-wifi-connect $

Not sure how to actually get to the unit and its methods/properties.

@polymerchm
Copy link
Author

Figured it all out. Nice package!!

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

1 participant