I have a python app called main.py, that runs upon startup using rc.local. During this app's runtime, it runs an external bash script 'play.sh' that runs vlc to play a song. The code in the 'play.sh' is simple: /usr/bin/cvlc '/song.mp3'
The main.py code works great, it gets run on startup and all it's functionalities are intact, except running the play.sh file. When the main.py gets to the section in the code where it's supposed to run the 'play.sh', nothing happens.
The odd thing is, when I run the /etc/rc.local from the pi user when logged in, the 'play.sh' works as expected and the song is played. When running sudo /etc/rc.local , the issue persists. Even when running su - pi /etc/rc.local , the issue still persists.
I tried replacing vlc for mpv, but still no luck. What am I missing? What could be the reason for this?
Any help would be greatly appreciated.
P.S. this may be a bigger deal than I take it to be, but the Raspberry is connected via bluetooth to a speaker, and the audio is supposed to be routed there. It has no problem connected automatically to the speaker, and is connected when the issue occurs... but perhaps there is something there as well..
EDIT: I further investigated the issue. Upon closer inspection, it appears that it's something to do with the user environment. When I run a command 'su -m pi -c ' it works, but just calling su - pi -c '' doesn't work. How can I run with the env of the pi user upon startup? Either with rc.local, or systemd.