Support systemd notifications#23
Conversation
2b27f02 to
cb748e7
Compare
|
This looks clean, but I think it has a bug: because systemd is not a dependency of the Python package, there's no guarantee it's installed. That's fine because you've added a dynamic import guard. But the systemd unit is changed to use Your description of the PR says you've added |
Require `addcffi = "^1.17.0"` for Python 3.14 compatability
Opps, got a bit overzealous with my tidying up. I've added that now. I also realised that doing a optional import is a bit redundant with this being a dependency so I just made that a regular import. I decided to do a test by installing this on a fresh Ubuntu 24.04 VM and got this error: So to fix that I added an updated dependency for Here's my full test after fixing that: sudo apt-get update
sudo apt-get install -y pipx gcc libffi-dev libpcsclite-dev swig python3-dev pcscd
pipx ensurepath
export PATH=$HOME/.local/bin:$PATH
pipx install poetry
cd fido2-hid-bridge/
poetry install
sudo mkdir -p /opt/fido2-hid-bridge
sudo cp -r . /opt/fido2-hid-bridge/
sudo cp fido2-hid-bridge.service /etc/systemd/system/
cd /opt/fido2-hid-bridge && sudo -E $HOME/.local/bin/poetry install
sudo systemctl daemon-reload
sudo systemctl enable --now fido2-hid-bridgeTest stop and start: $ sudo systemctl status fido2-hid-bridge.service
● fido2-hid-bridge.service - Fido2 to HID bridge
Loaded: loaded (/etc/systemd/system/fido2-hid-bridge.service; enabled; preset: enabled)
Active: active (running) since Sun 2026-03-08 11:26:09 UTC; 1min 20s ago
Main PID: 710 (fido2-hid-bridg)
Tasks: 1 (limit: 4601)
Memory: 31.1M (peak: 31.4M)
CPU: 129ms
CGroup: /system.slice/fido2-hid-bridge.service
└─710 /opt/fido2-hid-bridge/.venv/bin/python /opt/fido2-hid-bridge/.venv/bin/fido2-hid-bridge
Mar 08 11:26:08 systemd[1]: Starting fido2-hid-bridge.service - Fido2 to HID bridge...
Mar 08 11:26:09 fido2-hid-bridge[710]: INFO:UHIDDevice:initializing device
Mar 08 11:26:09 fido2-hid-bridge[710]: INFO:UHIDDevice:(UHID_CREATE2) create UHIDDevice(vid=39321, pid=39321, name=FIDO2 Virtual USB Device, uniq=UHIDDevice_b586f6c9-fffa-4721-a2b6-cee42be0f15a)
Mar 08 11:26:09 fido2-hid-bridge[710]: INFO:root:FIDO2 HID Bridge started successfully
Mar 08 11:26:09 systemd[1]: Started fido2-hid-bridge.service - Fido2 to HID bridge.
$ sudo systemctl stop fido2-hid-bridge.service
$ sudo systemctl status fido2-hid-bridge.service --no-pager
○ fido2-hid-bridge.service - Fido2 to HID bridge
Loaded: loaded (/etc/systemd/system/fido2-hid-bridge.service; enabled; preset: enabled)
Active: inactive (dead) since Sun 2026-03-08 11:27:43 UTC; 2s ago
Duration: 1min 34.129s
Process: 710 ExecStart=/opt/fido2-hid-bridge/.venv/bin/fido2-hid-bridge (code=exited, status=0/SUCCESS)
Main PID: 710 (code=exited, status=0/SUCCESS)
CPU: 138ms
Mar 08 11:26:08 systemd[1]: Starting fido2-hid-bridge.service - Fido2 to HID bridge...
Mar 08 11:26:09 fido2-hid-bridge[710]: INFO:UHIDDevice:initializing device
Mar 08 11:26:09 fido2-hid-bridge[710]: INFO:UHIDDevice:(UHID_CREATE2) create UHIDDevice(vid=39321, pid=39321, name=FIDO2 Virtual USB Device, uniq=UHIDDevice_b586f6c9-fffa-4721-a2b6-cee42be0f15a)
Mar 08 11:26:09 fido2-hid-bridge[710]: INFO:root:FIDO2 HID Bridge started successfully
Mar 08 11:26:09 systemd[1]: Started fido2-hid-bridge.service - Fido2 to HID bridge.
Mar 08 11:27:43 systemd[1]: Stopping fido2-hid-bridge.service - Fido2 to HID bridge...
Mar 08 11:27:43 fido2-hid-bridge[710]: INFO:root:Received signal SIGTERM, shutting down...
Mar 08 11:27:43 fido2-hid-bridge[710]: INFO:root:FIDO2 HID Bridge shutting down...
Mar 08 11:27:43 systemd[1]: fido2-hid-bridge.service: Deactivated successfully.
Mar 08 11:27:43 systemd[1]: Stopped fido2-hid-bridge.service - Fido2 to HID bridge.
I also set |
Fixes an issue where systemd would incorrectly detect the service as hung, causing restart loops.
Also updated code to allow the service to be shutdown cleanly.
Changes
Event Loop Management
asyncio.run()for cleaner shutdown and automatic cleanupSystemd Integration
Type=notifyto the service file to support service state trackingsd-notifyfor systemd ready-state signalingSIGTERM/SIGINTsignals to ensure clean terminationService
Dependencies
sd-notify = "^0.1.0"