title: Start an Electron app at boot on Raspberry Pi 3 with yocto
body: <p>I built an image with X11 using yocto for a Raspberry Pi 3 and a touchscreen. I can start my app built with Electron (chromium) by running commands manually in a serial session:</p>
  
  <pre><code>export DISPLAY=:0
  /usr/lib/node/electron/dist/electron --no-sandbox /home/root/app
  </code></pre>
  
  <p>I though to use an init.d script to do it automatically at startup but I'd like to do it the proper way. I tried to create an <code>.Xsession</code> file in my user directory with the commands above but it doesn't work and I don't know if I can get logs of what happened.</p>
  
  <p>According to <a href="http://wiki.openmoko.org/wiki/Window_Manager_Startup" rel="nofollow noreferrer">this wiki</a>, there is a lot of steps at X11 startup. Currently, I only see a Terminal (from Matchbox I guess) and a mouse cursor.</p>
  
  <p>What's the "standard" way to start an app with the system and is there a way to remove the cursor for a touchscreen?</p>
  
  <p><strong>Edit</strong></p>
  
  <p>Here is the content of my <code>/etc/X11</code> directory:</p>
  
  <ul>
  <li>Xsession</li>
  <li>Xsession.d/</li>
  <li>xinit/</li>
  <li>xorg.conf</li>
  </ul>
  
  <p><em>Xsession</em>:</p>
  
  <pre><code>#!/bin/sh
  
  if [ -x /usr/bin/dbus-launch ]; then
      # As this is the X session script, always start a new DBus session.
      eval `dbus-launch --sh-syntax --exit-with-session &lt;/dev/null`
      echo "D-BUS per-session daemon address is: $DBUS_SESSION_BUS_ADDRESS"
  fi
  
  . /etc/profile
  
  if [ -f $HOME/.profile ]; then
      . $HOME/.profile
  fi
  
  SYSSESSIONDIR=/etc/X11/Xsession.d
  
  export CLUTTER_DISABLE_MIPMAPPED_TEXT=1
  
  for SESSIONFILE in $SYSSESSIONDIR/*; do
      set +e
      case "$SESSIONFILE" in
          *.sh)
              . "$SESSIONFILE"
              ;;
          *.shbg)
              "$SESSIONFILE" &amp;
              ;;
          *~)
              # Ignore backup files
              ;;
          *)
              "$SESSIONFILE"
              ;;
      esac
      set -e
  done
  
  exit 0
  </code></pre>
  
  <p><em>xorg.con</em>f: empty.</p>
  
  <p><em>Xsession.d/</em>:</p>
  
  <ul>
  <li>13xdgbasedirs.sh</li>
  <li>30xinput_calibrate.sh</li>
  <li>89xdgautostart.sh</li>
  <li>90XWindowManager.sh</li>
  </ul>
  
  <p><em>89xdgautostart.sh</em>:</p>
  
  <pre><code>XDGAUTOSTART=/etc/xdg/autostart
  if [ -d $XDGAUTOSTART ]; then
      for SCRIPT in $XDGAUTOSTART/*; do
          CMD=`grep ^Exec= $SCRIPT | cut -d '=' -f 2`
          $CMD &amp;
      done
  fi
  </code></pre>
  
  <p><em>90XWindowManager.sh</em>:</p>
  
  <pre><code>if [ -x $HOME/.Xsession ]; then
      exec $HOME/.Xsession
  elif [ -x /usr/bin/x-session-manager ]; then
      exec /usr/bin/x-session-manager
  else
      exec /usr/bin/x-window-manager
  fi
  </code></pre>
  
  <p>There is also a file <code>/etc/xserver-nodm/Xserver</code>:</p>
  
  <pre><code>#!/bin/sh
  
  # This script is only needed to make sure /etc/X11/xserver-common
  # can affect XSERVER, ARGS &amp; DPI: otherwise systemd could just use
  # /etc/default/xserver-nodm as EnvironmentFile and sysvinit could just
  # source the same file
  
  . /etc/profile
  
  # load default values for XSERVER, ARGS, DISPLAY...
  . /etc/default/xserver-nodm
  
  # Allow xserver-common to override ARGS, XSERVER, DPI
  if [ -e /etc/X11/xserver-common ] ; then
      . /etc/X11/xserver-common
      if [ ! -e $XSERVER ] ; then
          XSERVER=$(which $XSERVER)
      fi
  fi
  
  if [ -n "$DPI" ] ; then
      ARGS="$ARGS -dpi $DPI"
  fi
  
  exec xinit /etc/X11/Xsession -- $XSERVER $DISPLAY $ARGS $*
  </code></pre>
  
  <p>and a file <code>/etc/rc5.d/S09xserver-nodm</code>:</p>
  
  <pre><code>#!/bin/sh
  #
  ### BEGIN INIT INFO
  # Provides: xserver
  # Required-Start: $local_fs $remote_fs dbus
  # Required-Stop: $local_fs $remote_fs
  # Default-Start:     5
  # Default-Stop:      0 1 2 3 6
  ### END INIT INFO
  
  killproc() {            # kill the named process(es)
          pid=`/bin/pidof $1`
          [ "$pid" != "" ] &amp;&amp; kill $pid
  }
  
  read CMDLINE &lt; /proc/cmdline
  for x in $CMDLINE; do
          case $x in
          x11=false)
          echo "X Server disabled" 
          exit 0;
                  ;;
          esac
  done
  
  case "$1" in
    start)
         . /etc/profile
  
         #default for USER
         . /etc/default/xserver-nodm
         echo "Starting Xserver"
         if [ "$USER" != "root" ]; then
             # setting for rootless X
             chmod o+w /var/log
             chmod g+r /dev/tty[0-3]
             # hidraw device is probably needed
             if [ -e /dev/hidraw0 ]; then
                 chmod o+rw /dev/hidraw*
             fi
         fi
  
         # Using su rather than sudo as latest 1.8.1 cause failure [YOCTO #1211]
         su -l -c '/etc/xserver-nodm/Xserver &amp;' $USER
         # Wait for the desktop to say its finished loading
         # before loading the rest of the system
         # dbus-wait org.matchbox_project.desktop Loaded
    ;;
  
    stop)
          echo "Stopping XServer"
          killproc xinit
          sleep 1
          chvt 1 &amp;
    ;;
  
    restart)
      $0 stop
          $0 start
    ;;
  
    *)
          echo "usage: $0 { start | stop | restart }"
    ;;
  esac
  
  exit 0
  </code></pre>