balena-labs-projects / xserver

A simple X11 server block
Apache License 2.0
15 stars 13 forks source link

Sometime upon reboot a lockfile is created and X cannot start #16

Closed danclimasevschi closed 2 years ago

danclimasevschi commented 2 years ago

Hi, I have tried this out on a FinCM3. It seems that sometimes a lockfile is created after a reboot and this prevents the X server to start on $FORCE_DISPLAY. The container then gets stuck in a restart loop with the same logs:

Running balena base image entrypoint...
Setting initial display to FORCE_DISPLAY - :0
balenaBlocks xserver version: 0.0.3
Checking GPU memory
/opt/xserver/entry.sh: 18: vcgencmd: not found
/opt/xserver/entry.sh: 18: [: Illegal number: 

(EE) 
Fatal server error:
(EE) Server is already active for display 0
        If this server is no longer running, remove /tmp/.X0-lock
        and start again.
(EE) 
(EE) 
Please consult the The X.Org Foundation support 
         at http://wiki.x.org
 for help. 
(EE) 
xinit: giving up
xinit: unable to connect to X server: Cannot assign requested address
xinit: server error

I would propose this fix for the entry.sh script: https://github.com/balenablocks/xserver/blob/c3acc3e2ed2c3b59abae711a84d6eb1846149ae6/src/entry.sh#L9

LOCK_FILE="/tmp/.X${FORCE_DISPLAY//:}-lock"   # remove ':' prefix from FORCE_DISPLAY
if [ -f $LOCK_FILE ]; then
    echo "Removing lockfile $LOCK_FILE"
    rm -f $LOCK_FILE &> /dev/null
fi
nucleardreamer commented 2 years ago

@danclimasevschi haven't run into that yet! I am assuming that the xserver didn't have time to cleanup before the container was shut down (only a guess).

That fix looks solid, I will get it merged today! Thank you!

danclimasevschi commented 2 years ago

It looks the bash style string substitution doesn’t work. Needs to be replaced with something like this:

result=$(echo "$firstString" | sed "s/Suzi/$secondString/")

danclimasevschi commented 2 years ago

@nucleardreamer This solution fixes the problem, here's the patchfile:

From 8a3d53ce3f120f7f567cd9c96bea294147b880b0 Mon Sep 17 00:00:00 2001
From: Dan Climasevschi <dan.climasevschi@ledcity.ch>
Date: Fri, 6 May 2022 08:51:17 +0200
Subject: [PATCH] Fixes #16

---
 src/entry.sh | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/entry.sh b/src/entry.sh
index 9501a3f..1509a6e 100644
--- a/src/entry.sh
+++ b/src/entry.sh
@@ -7,6 +7,13 @@ rm -r /tmp/.X11-unix 2>/dev/null

 echo "Setting initial display to FORCE_DISPLAY - $FORCE_DISPLAY"

+DISP_NUM=$(echo "$FORCE_DISPLAY" | sed "s/://")
+LOCK_FILE="/tmp/.X${DISP_NUM}-lock"
+if [ -f "$LOCK_FILE" ]; then
+    echo "Removing lockfile $LOCK_FILE"
+    rm -f "$LOCK_FILE" &> /dev/null
+fi
+
 export DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket

 echo "balenaBlocks xserver version: $(cat VERSION)"
-- 
2.35.1