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

[BUG] Cannot start systemd service #34

Open
igorsantos07 opened this issue Dec 24, 2024 · 1 comment
Open

[BUG] Cannot start systemd service #34

igorsantos07 opened this issue Dec 24, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@igorsantos07
Copy link
Contributor

igorsantos07 commented Dec 24, 2024

Describe the bug
Possibly related to the complaints at #15. I've submitted #33 with systemd instructions, but turns out my tries cause Python errors I have no clue how to solve.

To Reproduce
If I run the application manually, it works great. However, the following /etc/systemd/system/halinuxcompanion.service yields errors:

[Unit]
Description=Home Assistant Linux Companion
Documentation=https://github.com/muniter/halinuxcompanion
After=networking.target

[Service]
WorkingDirectory=/opt/halinuxcompanion
ExecStart=/opt/halinuxcompanion/.venv/bin/python -m halinuxcompanion -c config.json
Restart=always
RestartSec=30
# User=igor # I tried adding this, but doesn't help with the issue

[Install]
WantedBy=default.target

This yields the following errors:

Dec 24 14:43:54 mac-mint systemd[1]: Started halinuxcompanion.service - Home Assistant Linux Companion.
Dec 24 14:43:54 mac-mint python[99757]: INFO:halinuxcompanion:Reading configuration file config.json
Dec 24 14:43:54 mac-mint python[99757]: Traceback (most recent call last):
Dec 24 14:43:54 mac-mint python[99757]:   File "<frozen runpy>", line 198, in _run_module_as_main
Dec 24 14:43:54 mac-mint python[99757]:   File "<frozen runpy>", line 88, in _run_code
Dec 24 14:43:54 mac-mint python[99757]:   File "/opt/halinuxcompanion/halinuxcompanion/__main__.py", line 104, in <module>
Dec 24 14:43:54 mac-mint python[99757]:     loop.run_until_complete(main())
Dec 24 14:43:54 mac-mint python[99757]:   File "/usr/lib/python3.12/asyncio/base_events.py", line 687, in run_until_complete
Dec 24 14:43:54 mac-mint python[99757]:     return future.result()
Dec 24 14:43:54 mac-mint python[99757]:            ^^^^^^^^^^^^^^^
Dec 24 14:43:54 mac-mint python[99757]:   File "/opt/halinuxcompanion/halinuxcompanion/__main__.py", line 69, in main
Dec 24 14:43:54 mac-mint python[99757]:     await bus.init()
Dec 24 14:43:54 mac-mint python[99757]:   File "/opt/halinuxcompanion/halinuxcompanion/dbus.py", line 86, in init
Dec 24 14:43:54 mac-mint python[99757]:     self.session = await MessageBus(bus_type=BusType.SESSION).connect()
Dec 24 14:43:54 mac-mint python[99757]:                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Dec 24 14:43:54 mac-mint python[99757]:   File "/opt/halinuxcompanion/.venv/lib/python3.12/site-packages/dbus_next/aio/message_bus.py", line 122, in __init__
Dec 24 14:43:54 mac-mint python[99757]:     super().__init__(bus_address, bus_type, ProxyObject)
Dec 24 14:43:54 mac-mint python[99757]:   File "/opt/halinuxcompanion/.venv/lib/python3.12/site-packages/dbus_next/message_bus.py", line 72, in __init__
Dec 24 14:43:54 mac-mint python[99757]:     get_bus_address(bus_type))
Dec 24 14:43:54 mac-mint python[99757]:     ^^^^^^^^^^^^^^^^^^^^^^^^^
Dec 24 14:43:54 mac-mint python[99757]:   File "/opt/halinuxcompanion/.venv/lib/python3.12/site-packages/dbus_next/_private/address.py", line 98, in get_bus_address

Trying with the same file but from userland, according to the suggestion at #15, yields this:

Dec 24 15:06:49 mac-mint systemd[1263]: Started halinuxcompanion.service - Home Assistant Linux Companion.
Dec 24 15:06:49 mac-mint (python)[126176]: halinuxcompanion.service: Failed to determine supplementary groups: Operation not permitted
Dec 24 15:06:49 mac-mint systemd[1263]: halinuxcompanion.service: Main process exited, code=exited, status=216/GROUP
Dec 24 15:06:49 mac-mint systemd[1263]: halinuxcompanion.service: Failed with result 'exit-code'.
Dec 24 15:07:19 mac-mint systemd[1263]: halinuxcompanion.service: Scheduled restart job, restart counter is at 4.

Finally, trying to add /opt/halinuxcompanion/.venv/bin/python -m halinuxcompanion -c config.json or python3 -m halinuxcompanion -c config.json to Mint's Startup Applications doesn't yield any error, nor updates HA. I ended up creating a bash script that runs cd /opt/halinuxcompanion/ && .venv/bin/python -m halinuxcompanion -c config.json and added that as a Startup Application, which is quite a workaround, but seems to work for now 👀

Thanks and merry Christmas 🎅

@igorsantos07 igorsantos07 added the bug Something isn't working label Dec 24, 2024
@slovdahl
Copy link
Contributor

slovdahl commented Jan 1, 2025

I don't think it's possible to run halinuxcompanion as a system-wide systemd service (due to the DBUS usage I believe). So in that regard I'm not sure if the instructions added in #33 are accurate 🤔

How did you try to start halinuxcompanion using systemd as your own user? I found https://unix.stackexchange.com/a/479977/73666 that seems to describe a similar problem. Something like systemctl --user start halinuxcompanion.service without any user specified in the unit file should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants