Keep x11vnc alive for remote login

This commit is contained in:
jjbrunton committed 2026-08-08 15:16:51 +01:00
1 parent 89f7376b1b
commit 51438aa5db
2 files changed
+38 -1

No files matched your search

+22 -1
View File
@@ -54,7 +54,7 @@ if command -v fluxbox >/dev/null 2>&1; then
fluxbox >/dev/null 2>&1 & fluxbox >/dev/null 2>&1 &
fi fi
VNC_ARGS=(-display "${DISPLAY}" -forever -shared -rfbport "${VNC_PORT}" -nopw_warn) VNC_ARGS=(-display "${DISPLAY}" -forever -shared -rfbport "${VNC_PORT}")
if [ -n "${VNC_PASSWORD:-}" ]; then if [ -n "${VNC_PASSWORD:-}" ]; then
mkdir -p /root/.vnc mkdir -p /root/.vnc
x11vnc -storepasswd "${VNC_PASSWORD}" /root/.vnc/passwd >/dev/null x11vnc -storepasswd "${VNC_PASSWORD}" /root/.vnc/passwd >/dev/null
@@ -68,6 +68,27 @@ fi
x11vnc "${VNC_ARGS[@]}" >/var/log/x11vnc.log 2>&1 & x11vnc "${VNC_ARGS[@]}" >/var/log/x11vnc.log 2>&1 &
X11VNC_PID=$! X11VNC_PID=$!
VNC_READY=0
for i in $(seq 1 50); do
if ! kill -0 "${X11VNC_PID}" 2>/dev/null; then
echo "[entrypoint] FATAL: x11vnc exited before becoming ready" >&2
cat /var/log/x11vnc.log >&2
exit 1
fi
if (: </dev/tcp/127.0.0.1/${VNC_PORT}) 2>/dev/null; then
echo "[entrypoint] VNC server is ready after ${i} checks"
VNC_READY=1
break
fi
sleep 0.2
done
if [ "${VNC_READY}" != "1" ]; then
echo "[entrypoint] FATAL: x11vnc did not listen on port ${VNC_PORT} after 10s" >&2
cat /var/log/x11vnc.log >&2
exit 1
fi
echo "[entrypoint] starting noVNC (websockify) on :${NOVNC_PORT}" echo "[entrypoint] starting noVNC (websockify) on :${NOVNC_PORT}"
websockify --web "${NOVNC_WEB_DIR}" "${NOVNC_PORT}" "localhost:${VNC_PORT}" \ websockify --web "${NOVNC_WEB_DIR}" "${NOVNC_PORT}" "localhost:${VNC_PORT}" \
>/var/log/websockify.log 2>&1 & >/var/log/websockify.log 2>&1 &
+16
View File
@@ -0,0 +1,16 @@
import fs from 'node:fs';
import path from 'node:path';
import { describe, expect, it } from 'vitest';
describe('VNC container entrypoint', () => {
it('starts x11vnc with supported arguments and verifies its port before noVNC', () => {
const script = fs.readFileSync(path.resolve('docker/entrypoint.sh'), 'utf8');
expect(script).not.toContain('-nopw_warn');
expect(script).toContain('kill -0 "${X11VNC_PID}"');
expect(script).toContain('/dev/tcp/127.0.0.1/${VNC_PORT}');
expect(script.indexOf('VNC server is ready')).toBeLessThan(
script.indexOf('starting noVNC'),
);
});
});