1

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.

mlx11
  • 170
  • 1
  • 8
  • I assume you mean that the gui should show in the attached monitor? not that you expect the gui to print in the terminal from which you have connected via remote? I often start a gui application from my remote terminal pretty much as you describe. I have not used export DISPLAY=:0. A thought is that the environment variables have not been set up so you could try adding variables and configuring PATH and PYTHONPATH in your script. or refer to my proposed answer to use .bashrc file – Mark Nov 23 '22 at 22:04

1 Answers1

1

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
Mark
  • 532
  • 1
  • 4
  • 9
  • 1
    Thank you. This is a nice script although it didn't work for me initially. In fact, the SESSION_TYPE variable was not defined when I accessed my raspi over SSH (maybe an other version of rasping? I am using the newest one). A quick fix was to check whether the variable SSH_CONNECTION is set. – mlx11 Nov 28 '22 at 13:57
  • my apologies, I neglected to notice that my code sourced a script in which there was a function to determine the session type. I have amended my answer to show this. I am not sure of the ramifications of this technique verses what you did. Maybe your way is simpler and more direct. – Mark Nov 28 '22 at 16:14