You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've created a python script that detects inactivity on gamepads and disconnects them from the system if they are bluetooth devices. The script is working fine with no problems when I run it as a regular user in Ubuntu.
Then, I created an user service with the following content:
[Unit]
Description=This service disconnects bluetooth gamepads after 10 minutes of inactivity.
[Service]
Type=simple
RemainAfterExit=true
ExecStart=python3 /opt/bluetooth_pad_disconnect/bluetooth_pad_disconnect.py
[Install]
WantedBy=default.target
The script starts with no problem but it doesn't detect any device at all. Do you have an idea of what the problem could be?
I've tried running a .bash script printing the user id and groups just in case there was a problem but everything is the same as if I was running a regular terminal.
The text was updated successfully, but these errors were encountered:
It seems the problem was quite simple: Python's printing buffer, deactivating it when launching the scirpt, everthing is fine. What I didn't know until now is that the printing buffer can have a different size/behaviour when calling a script from terminal or as a service; the fact that I obtained different outputs didn't lead me to think about the buffer at all.
Thanks for the suggestion about using udev rules, @sezanzeb. I have a very limited understanding of Linux devices but the reason I opted for writing my own python script is that input devices ids can vary through time. My bluetooth pad can be device 11 now, but if I connect an USB pad before, it could be device 12 next time. By calling the service as a regular user (not as root), only devices connected by that user are obtained by list_devices, and then using some scripting I can detect which ones are bluetooth ones and can be deactivated after inactivity.
Regards
HeuristicPerson
changed the title
Not getting any device when running as a daemon
[SOLVED] Not getting any device when running as a daemon
Feb 18, 2024
I've created a python script that detects inactivity on gamepads and disconnects them from the system if they are bluetooth devices. The script is working fine with no problems when I run it as a regular user in Ubuntu.
Then, I created an user service with the following content:
The script starts with no problem but it doesn't detect any device at all. Do you have an idea of what the problem could be?
I've tried running a .bash script printing the user id and groups just in case there was a problem but everything is the same as if I was running a regular terminal.
The text was updated successfully, but these errors were encountered: