08-02-2020, 09:38 PM
I know this is more of a linux question than OAP. But, I am asking to see if anyone has come up with a solution.
I've written a Python script to adjust the volume of OAP using a rotary encoder. The script works perfectly (even tuned for debounce).
The only drawback is that the script uses uinput for sending the key commands. This requires to be executed as SU. I've tried starting the script as a service (works great when already booted to a desktop). I've also tried adding to rc.local.
sudo bash -c 'usr/bin/python3 /home/pi/autopc/volume.py > /home/pi/volume.log 2>&1' &
No mater which startup method I have tried, I do not get the script to launch unless I do so interactively (elevated with sudo).
Here's the error:
pi@saab900spg:~ $ cat volume.log
Traceback (most recent call last):
File "/home/pi/autopc/volume.py", line 18, in
uinput.KEY_ESC,
File "/usr/local/lib/python3.7/dist-packages/uinput/__init__.py", line 178, in __init__
self.__uinput_fd = fd or fdopen()
File "/usr/local/lib/python3.7/dist-packages/uinput/__init__.py", line 84, in fdopen
return _libsuinput.suinput_open()
File "/usr/local/lib/python3.7/dist-packages/uinput/__init__.py", line 70, in _open_error_handler
raise OSError(code, msg)
It seems like uinput is not available for python when started via service or rc.local.
When booted, python is found in /usr/bin/python3 when I execute which python3.
What is a reliable way to get scripts to run elevated at startup?
I've written a Python script to adjust the volume of OAP using a rotary encoder. The script works perfectly (even tuned for debounce).
The only drawback is that the script uses uinput for sending the key commands. This requires to be executed as SU. I've tried starting the script as a service (works great when already booted to a desktop). I've also tried adding to rc.local.
sudo bash -c 'usr/bin/python3 /home/pi/autopc/volume.py > /home/pi/volume.log 2>&1' &
No mater which startup method I have tried, I do not get the script to launch unless I do so interactively (elevated with sudo).
Here's the error:
pi@saab900spg:~ $ cat volume.log
Traceback (most recent call last):
File "/home/pi/autopc/volume.py", line 18, in
uinput.KEY_ESC,
File "/usr/local/lib/python3.7/dist-packages/uinput/__init__.py", line 178, in __init__
self.__uinput_fd = fd or fdopen()
File "/usr/local/lib/python3.7/dist-packages/uinput/__init__.py", line 84, in fdopen
return _libsuinput.suinput_open()
File "/usr/local/lib/python3.7/dist-packages/uinput/__init__.py", line 70, in _open_error_handler
raise OSError(code, msg)
It seems like uinput is not available for python when started via service or rc.local.
When booted, python is found in /usr/bin/python3 when I execute which python3.
What is a reliable way to get scripts to run elevated at startup?