Skip to content

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

Open

Description

@HeuristicPerson

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.

Activity

  1. sezanzeb commented on Feb 17, 2024

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

  2. HeuristicPerson commented on Feb 18, 2024

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

  3. changed the title [-]Not getting any device when running as a daemon[/-] [+][SOLVED] Not getting any device when running as a daemon[/+] on Feb 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions