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

[SOLVED] Not getting any device when running as a daemon #208

Open
HeuristicPerson opened this issue Feb 14, 2024 · 2 comments
Open

[SOLVED] Not getting any device when running as a daemon #208

HeuristicPerson opened this issue Feb 14, 2024 · 2 comments

Comments

@HeuristicPerson
Copy link

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.

@sezanzeb
Copy link
Collaborator

Does it work if you add a little bit of extra sleep to the beginning? Something like

import time
time.sleep(10)

You might want to consider writing an udev rule instead that runs the script for each individual bluetooth device, once they connect. Some hints on how this could work and debugged can be found here: https://github.com/sezanzeb/input-remapper/blob/main/data/99-input-remapper.rules

@HeuristicPerson
Copy link
Author

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 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
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

2 participants