0

I would like to launch my python program (Graphical User Interface) on startup in Linux (Raspbian on a Raspberry PI).

I've made an initscript to launch my Python program, and I put it in the etc/init.d map.

I enabled it with the update-rc.d command. It all works fine.

But my Python script won't start with the following code in the initscript:

#!/bin/bash

### BEGIN INIT INFO
# Provides:          GUI
# Required-Start:    
# Required-Stop:     
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: This is a test daemon
# Description:       This is a test daemon
#                    This provides example about how to
#                    write a Init script.
### END INIT INFO



case $1 in
 start)
  python3 /home/pi/Desktop/GUI/GUI.py
  ;;
 stop)
  # Stop the daemon.
  if [ -e $PIDFILE ]; then
   status_of_proc -p $PIDFILE $DAEMON "Stoppping the $NAME process" && status="0" || status="$?"
   if [ "$status" = 0 ]; then
    start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE
    /bin/rm -rf $PIDFILE
   fi
  else
   log_daemon_msg "$NAME process is not running"
   log_end_msg 0
  fi
  ;;
 restart)
  # Restart the daemon.
  $0 stop && sleep 2 && $0 start
  ;;
 status)
  # Check the status of the process.
  if [ -e $PIDFILE ]; then
   status_of_proc -p $PIDFILE $DAEMON "$NAME process" && exit 0 || exit $?
  else
   log_daemon_msg "$NAME Process is not running"
   log_end_msg 0
  fi
  ;;
 reload)
  # Reload the process. Basically sending some signal to a daemon to reload
  # it configurations.
  if [ -e $PIDFILE ]; then
   start-stop-daemon --stop --signal USR1 --quiet --pidfile $PIDFILE --name $NAME
   log_success_msg "$NAME process reloaded successfully"
  else
   log_failure_msg "$PIDFILE does not exists"
  fi
  ;;
 *)
  # For invalid arguments, print the usage message.
  echo "Usage: $0 {start|stop|restart|reload|status}"
  exit 2
  ;;
esac
1
  • how you try to run service --status-all is there any findings? Commented Nov 1, 2016 at 13:23

1 Answer 1

1

The problem is that when the init script run, there is not graphical interface available. Instead of using a init script, try configuring your application to run on X startup.

First add the command line to start your GUI app to ~/.xinitrc

# ~/.xinitrc

exec python3 /home/pi/Desktop/GUI/GUI.py

And then start the X server

startx
Sign up to request clarification or add additional context in comments.

4 Comments

Where can I find this file?
You can find it on your user's home directory (e.g. /home/jarno/.xinitrc). If it doesn't exist, just create a new one.
All right I've done that now. I stated the X server, and when I reboot I get a white login screen now (I never had that before). And when I login, it refreshes and I have to login again (keeps doing that). When I enter wrong login it says that the login is right. But when I use the right info it just refreshes. This same problem occurs without the xinitrc file btw.
I fixed that but my program still doesn't boot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.