I am trying to have a kivy GUI that starts automatically after boot on a raspberry pi 4 running headless raspbian (with a window manager installed). To do so, I added the following line to /etc/rc.local:
su -c /home/pi/dummyfolder/run_gui pi
The called script is
#!/bin/bash
# this stops the sleeping screen
killall light-locker
# set display - allows execution over ssh
export DISPLAY=:0
python3 /home/pi/dummyfolder/gui.py -a &
When I reboot my raspberry pi I don't see the GUI. Looking at the output of journalctl I can verify that my script is running.
When I run the shell script manually the GUI is displayed. The same is true when I directly run rc.local. I therefore assume that there's a problem in the boot-up sequence i.e. that a service needed to display the script is not yet running.
Does somebody have an idea what the problem is or if the boot sequence hypothesis is true?
Edit: Somebody proposed to set wait-for-network in the raspy-config. However, I can not do this as the gui must run when there's no network.
I do something similar except I do not run a window manager. the Kivy application takes the whole screen. i use ~/.bashrc file and put what I want at the end. The very simplest is to start the application at the end of the .bashrc file but there are some extra things that make it nicer. You can put the python command into a separate script file and in addition this bit of code will notice if you are over ssh or not so that when you log in for maintenance it doesn't run your kivy application at startup of that terminal session.
in the example below my_fun would be my script that starts the python/kivy application
# at the end of ~/.bashrc
if [[ $SESSION_TYPE == "remote/ssh" ]]; then
is_running=$(pgrep -l python)
# echo "${is_running}"
if [ -n "$is_running" ]; then
echo -e "\n\n\033[01;31m============================================"
echo "----- WARNING a Python Process is running ---------"
echo -e "================================================\033[0m\n\n"
fi
echo -e "this is a remote session so the menu will not be presented"
return 1
else
echo -e "pause some seconds to wait for network interfaces..."
sleep 12s
ifconfig | grep netmask
sleep 1s
echo "direct console session"
my_fun
fi
EDITED to add this: the code to detect session type which of course would have to be placed before usage of that variable.
# is this a remote terminal or not
if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
SESSION_TYPE=remote/ssh
# many other tests omitted
else
case $(ps -o comm= -p $PPID) in
sshd|*/sshd) SESSION_TYPE=remote/ssh;;
esac
fi