Any ideas?
Yes.
For some time (at least two OS releases) the sound subsystem does not get started until a user logs in and then only for that user (and, I think, root can use it too).
If you're starting your python program before login, without a login, or for a different user to the one logged in there will be no sound subsystem for it to access. It isn't a systemd issue; the same happens with cron @reboot jobs and with /etc/rc.local. And, probably, with sysV init.
I can think of at least the following ways to work around this:
- Use automatic login to the command line then start it from the user's .profile or .bashrc. Insecure and will be started every time that file is processed (every login, every time a terminal is opened, ...)
- Use automatic login to then desktop start it with a .desktop file in $HOME/.config/autostart, wayfire.ini. autostart, ect depending on whetehr you're using Wayland or X11 and which window manager you're using. Insecure.
- Use Pulse Audio and configure it to run as a system wide daemon rather than a single user service (instruction on their website). I've no idea is pipewire (which is the default in RPiOS Bookworm can be used this way).
- Find out the command needed to start the sound subsystem (no, I don't know what it is) and add it to your service as an ExecStartPre=. See the systemd documentation.
- As above but call it from within your program before any sound (including intialisation) is required.
- As abov but use a wrapper shell script instead of ExecStartPre=.
If you opt for either of the first two methods be sure and disable passwordless sudo and, better yet all sudo, access for that user. If possible use a dedicated user account that us locked down as much as possible (you'll have to ask the internet about that though).
Statistics: Posted by thagrol — Sat May 18, 2024 11:42 pm