2

I'm working on a raspberry pi project that involves running a node server in kiosk mode.

I'm using BROWSER=none to suppress the default opening of the localhost upon the server being run.

I'm thinking I should be able to use wait-on to force the bash script that runs the kiosk mode to wait until the server is fully up. Would I use something like this?

"scripts": {
    ...
    "kiosk": "concurrently -n \"npm start\" \"wait-on http://localhost:3000 & /home/pi/kiosk.sh\""
  },

It gives me the following error(s) which I'm not quite able to decipher:

[npm start] server does not have extension for -dpms option
[npm start] libEGL warning: DRI2: failed to authenticate
[npm start] [1498:1498:1125/180040.467781:ERROR:gpu_init.cc(441)] Passthrough is not supported, GL is egl
[npm start] [1498:1498:1125/180040.786918:ERROR:viz_main_impl.cc(162)] Exiting GPU process due to errors during initialization
[npm start] [1558:1558:1125/180041.392714:ERROR:gpu_init.cc(441)] Passthrough is not supported, GL is swiftshader
[npm start] [1443:1590:1125/180042.359030:ERROR:object_proxy.cc(622)] Failed to call method: org.freedesktop.DBus.Properties.Get: object_path= /org/freedesktop/UPower: org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.UPower was not provided by any .service files
[npm start] [1443:1590:1125/180042.364570:ERROR:object_proxy.cc(622)] Failed to call method: org.freedesktop.UPower.GetDisplayDevice: object_path= /org/freedesktop/UPower: org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.UPower was not provided by any .service files
[npm start] [1443:1590:1125/180042.367155:ERROR:object_proxy.cc(622)] Failed to call method: org.freedesktop.UPower.EnumerateDevices: object_path= /org/freedesktop/UPower: org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.UPower was not provided by any .service files
[npm start] Fontconfig error: Cannot load default config file: No such file: (null)

I'm now realizing the error in my code has more to do with kiosk.sh than it does with the npm commands. Here's the code to kiosk.sh:

#!/bin/bash

xset s noblank
xset s off
xset -dpms

unclutter -root &

sed -i 's/"exited_cleanly":false/"exited_cleanly":true/' /home/pi/.config/chromium/Default/Preferences
sed -i 's/"exit_type":"Crashed"/"exit_type":"Normal"/' /home/pi/.config/chromium/Default/Preferences

/usr/bin/chromium-browser --noerrdialogs --disable-infobars --kiosk http://localhost:3000/ &
JShoe
  • 3,186
  • 9
  • 38
  • 61
  • 1
    You tagged the question as bash, but you are showing a PowerShell error... Something doesn't add up here! Maybe you don't have a _bash_ script running the kiosk but a _PowerShell_ script! – CherryDT Nov 25 '21 at 21:47
  • @CherryDT Ah, my bad. I'm using WebStorm and it must use PowerShell as its terminal, although I am trying to get a bash script to execute. – JShoe Nov 25 '21 at 22:13
  • 1
    But then that's your issue right there. The `&` and `&&` would be the right syntax for bash, not wrong for PowerShell. – CherryDT Nov 25 '21 at 22:21
  • @CherryDT okay, I've updated the question to reflect what I think is a more accurate attempt to accomplish the functionality I'm going for. – JShoe Nov 25 '21 at 23:02
  • @JShoe Any chance I could get a look at your node.js script please, you're kiosk.sh looks fine – djmonki Dec 01 '21 at 06:08

4 Answers4

2

& and && mean different things, && means AND, & means background process, run that service in the background and continue with the next.

I think what you're trying to do is wait-on service && example, not wait-on service & example.

What will happen with what you've done is it will run the wait-on, then immediately background process it, then immediately run the shell script without waiting for anything. Your script will run before the server is up.

That's not really your issue though, I believe your issue is with chromium itself. There's an open issue for it here: https://bugs.chromium.org/p/chromium/issues/detail?id=1221905&q=Passthrough%20is%20not%20supported%2C%20GL%20is%20swiftshader&can=1. That issue was last updated earlier this year and seems to still be unresolved.

There was also another answer for it here: Passthrough is not supported, GL is disabled.

I've seen quite a few people suggest that you use --headless and --disable-gpu and --disable-software-rasterizer. People have mentioned that some of those options are only required on windows and some have already been fixed, I don't know which of those are actually required.

This answer here: Force headless chromium/chrome to use actual gpu instead of Google SwiftShader, mentioned that you can force webgl using --enable-webgl to prevent it from loading swiftshader and use the gpu. You can do this if you need to force it in headless mode.

It seems to have something to do with webgl or hardware acceleration. Apparently it happens if you've disabled gpu acceleration and then it's forced to fallback on swiftloader.

I don't know which one of those is actually going to help you, you'll have to play around with it. However I have seen over 10 different chromium and other related issues all made during 2021 because of this bug in chromium.

What's more is that I'm not sure it's actually a critical error, some people mention it's just showing the error but can be just ignored. I don't know if that's the case.

1

I assume that you are using the package "wait-on" (https://www.npmjs.com/package/wait-on). The wait-on command is used without npm in front of it.

Try to use

wait-on http://localhost:3000 && /home/pi/kiosk.sh
Pascal
  • 61
  • 2
  • 1
    Thanks, I just changed that and I'm still not getting the result I'm expecting; it seems to be hanging. I have updated my question! – JShoe Nov 25 '21 at 23:28
0

You could use the "child_process" npm package to execute your bash script once the server is ready. Assuming you use Express.js in your backend, this should work with little modification

const exec = require('child_process');
//all your other codes and whatevers
app.listen(3000, () => {
    var kiosk = exec('sh kiosk.sh',
        (error, stdout, stderr) => {
            if (error) {
                console.log(`exec error: ${error}`);
            }
     });
});
inzig0
  • 51
  • 1
  • 3
0

wait-on waits until the process is closed. You are not closing chromium so it never continues. If you want to wait until the server is running. You can log the server's status to a text file and have your bash script read it in a loop until it contains the ready text you specify.

If you want to confirm beyond a reasonable doubt that the server is running as needed.

You can install the npm package puppetter. Then use the create and run a node script from bash using page.goto command to load the web page in an instance of chromium and use waitForSelector to check if the DOM element of your web page exists.

Then you use call process.exit() with whatever error codes you want to use to confirm that the page is live and running.

John
  • 5,942
  • 3
  • 42
  • 79