Running an electron-kiosk-snap on ubuntu core

Hello,

I am currently trying to create an electron kiosk snap following this tutorial https://ubuntu.com/tutorials/electron-kiosk#1-overview. I would like to test this on a Raspberry Pi.

I was able to generate a snap with the following snapcraft.yaml file:

name: aidm-kiosk-system
version: '0.1'
summary: Hello World Electron app
description: |
  Simple Hello World Electron app as an example
base: core18
confinement: strict
grade: devel
architectures:
  - build-on: amd64
    run-on: armhf

apps:
  aidm-kiosk-system:
    command: desktop-launch xwayland-kiosk-launch "aidm-kiosk-system/aidm-kiosk-system" "--no-sandbox"
    plugs:
    - browser-support
    - network
    - network-bind
    - opengl
    - pulseaudio
    - wayland

  daemon:
    daemon: simple
    restart-condition: always
    command: desktop-launch xwayland-kiosk-launch "aidm-kiosk-system/aidm-kiosk-system" "--no-sandbox"
    plugs:
    - browser-support
    - network
    - network-bind
    - opengl
    - pulseaudio
    - wayland

environment:
  XWAYLAND_FULLSCREEN_WINDOW_HINT: window_role="browser-window"

parts:
  aidm-kiosk:
    plugin: nil
    source: ./
    override-build: |
        yarn add electron electron-packager --verbose &&
        ./node_modules/.bin/electron-packager . aidm-kiosk-system --overwrite --platform=linux --arch=$ARCH --output=release-build --prune=true
        cp -rv ./aidm-kiosk-system-linux-* $SNAPCRAFT_PART_INSTALL/aidm-kiosk-system
    build-snaps:
    - node/14/stable
    build-packages:
    - nodejs
    - npm
    - yarn
    - unzip
    stage-packages:
    - libasound2
    - libgconf-2-4
    - libnss3
    - libx11-xcb1
    - libxss1
    - libxtst6

  # Adapted from snapcraft-desktop-helpers https://github.com/ubuntu/snapcraft-desktop-helpers/blob/master/snapcraft.yaml#L183
  desktop-gtk3:
    source: https://github.com/ubuntu/snapcraft-desktop-helpers.git
    source-subdir: gtk
    plugin: make
    make-parameters: ["FLAVOR=gtk3"]
    build-packages:
      - build-essential
      - libgtk-3-dev
    stage-packages:
      - libxkbcommon0  # XKB_CONFIG_ROOT
      - ttf-ubuntu-font-family
      - dmz-cursor-theme
      - light-themes
      - adwaita-icon-theme
      - gnome-themes-standard
      - shared-mime-info
      - libgtk-3-0
      - libgdk-pixbuf2.0-0
      - libglib2.0-bin
      - libgtk-3-bin
      - unity-gtk3-module
      - libappindicator3-1
      - locales-all
      - xdg-user-dirs
      - ibus-gtk3
      - libibus-1.0-5

  xwayland-kiosk-helper:
    plugin: cmake
    source: https://github.com/MirServer/xwayland-kiosk-helper.git
    build-packages: [ build-essential ]
    stage-packages: [ xwayland, i3, libegl1-mesa, libgl1-mesa-glx ]

However, installing the snap with snap install --dangerous NAME and executing it with (sudo) snap run NAME returns the following errors:

ERROR: ld.so: object '/snap/aidm-kiosk-system/x2/lib/bindtextdomain.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS64): ignored.
/snap/aidm-kiosk-system/x2/bin/desktop-launch: line 309: /snap/aidm-kiosk-system/x2/usr/bin/xdg-user-dirs-update: cannot execute binary file: Exec format error
ERROR: ld.so: object '/snap/aidm-kiosk-system/x2/lib/bindtextdomain.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS64): ignored.
realpath: '': No such file or directory
ERROR: ld.so: object '/snap/aidm-kiosk-system/x2/lib/bindtextdomain.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS64): ignored.
realpath: '': No such file or directory
ERROR: ld.so: object '/snap/aidm-kiosk-system/x2/lib/bindtextdomain.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS64): ignored.
realpath: '': No such file or directory
ERROR: ld.so: object '/snap/aidm-kiosk-system/x2/lib/bindtextdomain.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS64): ignored.
realpath: '': No such file or directory
ERROR: ld.so: object '/snap/aidm-kiosk-system/x2/lib/bindtextdomain.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS64): ignored.
realpath: '': No such file or directory
ERROR: ld.so: object '/snap/aidm-kiosk-system/x2/lib/bindtextdomain.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS64): ignored.
realpath: '': No such file or directory
ERROR: ld.so: object '/snap/aidm-kiosk-system/x2/lib/bindtextdomain.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS64): ignored.
realpath: '': No such file or directory
ERROR: ld.so: object '/snap/aidm-kiosk-system/x2/lib/bindtextdomain.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS64): ignored.
realpath: '': No such file or directory
ERROR: ld.so: object '/snap/aidm-kiosk-system/x2/lib/bindtextdomain.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS64): ignored.
ERROR: ld.so: object '/snap/aidm-kiosk-system/x2/lib/bindtextdomain.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS64): ignored.
ERROR: ld.so: object '/snap/aidm-kiosk-system/x2/lib/bindtextdomain.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS64): ignored.
ERROR: ld.so: object '/snap/aidm-kiosk-system/x2/lib/bindtextdomain.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS64): ignored.
ERROR: ld.so: object '/snap/aidm-kiosk-system/x2/lib/bindtextdomain.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS64): ignored.
/snap/aidm-kiosk-system/x2/bin/desktop-launch: line 10: /snap/aidm-kiosk-system/x2/usr/bin/update-mime-database: cannot execute binary file: Exec format error
ERROR: ld.so: object '/snap/aidm-kiosk-system/x2/lib/bindtextdomain.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS64): ignored.
ERROR: ld.so: object '/snap/aidm-kiosk-system/x2/lib/bindtextdomain.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS64): ignored.
ERROR: ld.so: object '/snap/aidm-kiosk-system/x2/lib/bindtextdomain.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS64): ignored.
ERROR: ld.so: object '/snap/aidm-kiosk-system/x2/lib/bindtextdomain.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS64): ignored.
ERROR: ld.so: object '/snap/aidm-kiosk-system/x2/lib/bindtextdomain.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS64): ignored.
ERROR: ld.so: object '/snap/aidm-kiosk-system/x2/lib/bindtextdomain.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS64): ignored.
ERROR: ld.so: object '/snap/aidm-kiosk-system/x2/lib/bindtextdomain.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS64): ignored.
/snap/aidm-kiosk-system/x2/bin/desktop-launch: line 10: /snap/aidm-kiosk-system/x2/usr/lib/arm-linux-gnueabihf/libgtk-3-0/gtk-query-immodules-3.0: No such file or directory
ERROR: update-mime-database /home/aj1123123/snap/aidm-kiosk-system/x2/.local/share/mime exited abnormally with status 126
ERROR: /snap/aidm-kiosk-system/x2/usr/lib/arm-linux-gnueabihf/libgtk-3-0/gtk-query-immodules-3.0 exited abnormally with status 127
ERROR: ld.so: object '/snap/aidm-kiosk-system/x2/lib/bindtextdomain.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS64): ignored.
ERROR: ld.so: object '/snap/aidm-kiosk-system/x2/lib/bindtextdomain.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS64): ignored.
ERROR: ld.so: object '/snap/aidm-kiosk-system/x2/lib/bindtextdomain.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS64): ignored.
Error: Unable to find a valid Wayland socket in /run/user/1000
Is a Wayland server running?
You could try running as root
ERROR: ld.so: object '/snap/aidm-kiosk-system/x2/lib/bindtextdomain.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS64): ignored.

I checked the /run/user/1000 directory and there is no such wayland-file. Also, there is no /run/user/0 directory at all.

Does anyone know why these required wayland files are not generated in this case? I think I am missing something here, but can’t figure out what it is…

Thanks in advance!

you are saying here that all binaries created during a build on an amd64 machine will definitely run on armhf … this is unlikely to be true unless you jump through a lot of hoops (which, according to your snapcraft.yaml, you dont seem to do) … what you end up with is an amd64 snap that you try to execute on arm … you need to compile natively (either by using snapcraft.io/build or by building on an arm based device), else this will not work …

Thank you for that fast reply!

I’ve also tried to build it without the architectures property on a mac and run it afterwards on that same machine. However, I also ended up with the same issue that these wayland files were not generated. Could this also be related to an architecture-mismatch?

Well, lets first get it to build properly, then take a look if the socket is still missing …

first of all remove the architectures entry and try building on the pi to get the right binary architecture …

I tried building the snap on top of your blog post. The only error showing up now is this one. So the lib reference errors are gone.

Error: Unable to find a valid Wayland socket in /run/user/1000
Is a Wayland server running?
You could try running as root

However, running as a root user returns this error message:

mkdir: cannot create directory '/run/user/0': Permission denied
rm: cannot remove '/root/snap/aidm-kiosk-system/x1/.local/share/mime/application': Directory not empty
rm: cannot remove '/root/snap/aidm-kiosk-system/x1/.local/share/mime/text': Directory not empty
mkdir: cannot create directory '/run/user/0': Permission denied

Tried to install it as the root user as well as my user. I don’t know if this makes a difference.
I also checked the recommended tasks from this blog post.

The output of ps aux | grep mir-kiosk looks like this. So mir-kiosk is running.

16083 0.0 0.0 3704 572 pts/0 S+ 11:07 0:00 grep --color=auto mir-kiosk

so this looks like mir-kiosk did not start at all then …
is mir-kiosk even installed ? do you see a short flash of orange on boot and after this a mouse cursor on the screen ?

@ogra thank you again for your help with this. I got the snap running in kiosk mode!
The only thing missing now is click events. Are they turned off by default?
I mean the kiosk mode starts on a reboot but I can’t click anywhere when a mouse is plugged in (e.g. to browse through the dev tools).
A left click will always open the File > Quit window.