1

I have a service running on Raspbian OS 11 lite on a Raspberry 3, which should play audio for me.

[Unit]
Description=My script to monitor the shutdown button
After=multi-user.target

[Service]
ExecStart=/usr/bin/python /home/pi/Radio/Radio/main.py
User=root
Group=root

[Install]
WantedBy=multi-user.target

The service is running and interacting with the user by reading his input. But as soon as it should play music, I always get the following error:

Oct 10 18:22:57 raspberrypiradio python[4180]: [755aa250] main audio output error: Audio output failed
Oct 10 18:22:57 raspberrypiradio python[4180]: [755aa250] main audio output error: The audio device "default" could not be used:
Oct 10 18:22:57 raspberrypiradio python[4180]: Connection refused.
Oct 10 18:22:57 raspberrypiradio python[4180]: [755aa250] main audio output error: module not functional
Oct 10 18:22:57 raspberrypiradio python[4180]: [7312c1f0] main decoder error: failed to create audio output
Oct 10 18:24:00 raspberrypiradio python[4180]: [75591ca8] vlcpulse audio output error: PulseAudio server connection failure: Access denied
Oct 10 18:24:01 raspberrypiradio python[4180]: [75588cb0] vlcpulse audio output error: PulseAudio server connection failure: Access denied
Oct 10 18:24:01 raspberrypiradio python[4180]: [73d01830] http stream error: cannot resolve stream.rockantenne.de: System error
Oct 10 18:24:01 raspberrypiradio python[4180]: [73d01830] access stream error: HTTP connection failure
Oct 10 18:24:01 raspberrypiradio python[4180]: [73d01830] http stream error: cannot connect to stream.rockantenne.de:80

When I am playing the main.py file directly via terminal, everything is working. I am playing the sound in the python file via vlc.

I am using a service, because I want the main.py to run all the time. Especially after rebooting the system.

maja95
  • 11
  • 2

2 Answers2

0

Try adding this to your service file under the service tag.

Environment=XDG_RUNTIME_DIR=/run/user/1000

Of course you'll have to change your directory to match the current user. You can run

printenv | grep -i 'xdg_runtime_dir'

to make sure what to copy to the service file.

That should fix the vlcpulse server connection denied failures but looks like you also have a DNS error not being able to resolve the remote stream. That's a different issue that will take some more information to solve.

bigC5012
  • 101
  • 2
  • Thanks. But this was unfortunately not working. I found out the problem is, that services start running before user defined services, such as alsa. This means, my service tries to use alsa but it is not available. I solved this with a start script in /profiles.d/ as explained in this post: https://unix.stackexchange.com/questions/56083/how-to-write-a-shell-script-that-gets-executed-on-login – maja95 Oct 21 '22 at 12:59
0

I found out the problem is, that services start running before user defined services, such as alsa. This means, my service tries to use alsa but it is not available, yet. I solved this with a start script in /profiles.d/ as explained in this post: How to write a shell script that gets executed on login?

maja95
  • 11
  • 2