Skip to content

Desktop-Lite does not start Xtigervnc #1085

@cobnett3

Description

@cobnett3

I installed desktop-lite feature.
The build is successfully completed but Xtigervnc is not launched automatically.

I can see /usr/local/share/desktop-init.sh stopped or hanged up from the log:

$ cat /tmp/container-init.log
[Sat Aug 10 10:24:56 AM UTC 2024] ** SCRIPT START **
[Sat Aug 10 10:24:57 AM UTC 2024] Running "/etc/init.d/dbus start".
[Sat Aug 10 10:24:58 AM UTC 2024] Starting Xtigervnc.

I confirmed that tigervnc and novnc are installed by manually starting them on Terminal and access from vnc client / browser. So I guess something went wrong in desktop-init.sh.

Though not sure if this is relevant, I can see $1.log is created, which seems wired ($1 instead of Xtigervnc?).

$ ls /tmp
'$1.log'              dbus-daemon-system.log                                 vscode-ipc-7acb4610-355f-457f-bec6-fdc6478bf580.sock
'$1.pid'              vscode-git-28e133266e.sock                             vscode-ipc-971e000d-98f1-4bc4-a76e-db753bf0e6cc.sock
 codespaces_logs      vscode-git-fbb824366b.sock                             vscode-ipc-db7ae755-3039-46cd-949e-5c7cab4af4b5.sock
 container-init.log   vscode-ipc-5cc52e8f-5046-4f2a-a735-9c4760d441fe.sock
devcontainer.json
{
	"name": "Node.js & TypeScript",
	"image": "mcr.microsoft.com/devcontainers/typescript-node:1-22-bookworm",
	"features": {
		"ghcr.io/devcontainers/features/desktop-lite:1": {}
	},
	"forwardPorts": [
		6080
	],
	"portsAttributes": {
		"6080": {
			"label": "Desktop Lite Web"
		}
	}
}
netstat -tulpn | grep LISTEN
$ netstat -tulpn | grep LISTEN
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp        0      0 127.0.0.1:16634         0.0.0.0:*               LISTEN      -                   
tcp        0      0 127.0.0.1:16635         0.0.0.0:*               LISTEN      -                   
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      -                   
tcp        0      0 127.0.0.1:44093         0.0.0.0:*               LISTEN      529/node            
tcp        0      0 127.0.0.1:40045         0.0.0.0:*               LISTEN      -                   
tcp        0      0 0.0.0.0:2000            0.0.0.0:*               LISTEN      -                   
tcp6       0      0 :::2000                 :::*                    LISTEN      -                   
tcp6       0      0 ::1:16635               :::*                    LISTEN      -                   
tcp6       0      0 ::1:16634               :::*                    LISTEN      -                  
/usr/local/share/desktop-init.sh
#!/bin/bash

user_name="${USERNAME}"
group_name="$(id -gn ${USERNAME})"
LOG=/tmp/container-init.log

export DBUS_SESSION_BUS_ADDRESS="${DBUS_SESSION_BUS_ADDRESS:-"autolaunch:"}"
export DISPLAY="${DISPLAY:-:1}"
export VNC_RESOLUTION="${VNC_RESOLUTION:-1440x768x16}" 
export LANG="${LANG:-"en_US.UTF-8"}"
export LANGUAGE="${LANGUAGE:-"en_US.UTF-8"}"

# Execute the command it not already running
startInBackgroundIfNotRunning()
{
    log "Starting $1."
    echo -e "\n** $(date) **" | sudoIf tee -a /tmp/\$1.log > /dev/null
    if ! pgrep -x $1 > /dev/null; then
        keepRunningInBackground "$@"
        while ! pgrep -x $1 > /dev/null; do
            sleep 1
        done
        log "$1 started."
    else
        echo "$1 is already running." | sudoIf tee -a /tmp/\$1.log > /dev/null
        log "$1 is already running."
    fi
}

# Keep command running in background
keepRunningInBackground()
{
    ($2 bash -c "while :; do echo [\\$(date)] Process started.; $3; echo [\\$(date)] Process exited!; sleep 5; done 2>&1" | sudoIf tee -a /tmp/\$1.log > /dev/null & echo "\$!" | sudoIf tee /tmp/\$1.pid > /dev/null)
}

apt_get_update()
{
    if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then
        echo "Running apt-get update..."
        apt-get update -y
    fi
}

check_packages() {
    if ! dpkg -s "$@" > /dev/null 2>&1; then
        apt_get_update
        apt-get -y install --no-install-recommends "$@"
    fi
}

# Use sudo to run as root when required
sudoIf()
{
    if [ "$(id -u)" -ne 0 ]; then
        check_packages sudo
        sudo "$@"
    else
        "$@"
    fi
}

# Use sudo to run as non-root user if not already running
sudoUserIf()
{
    if [ "$(id -u)" -eq 0 ] && [ "${user_name}" != "root" ]; then
        check_packages sudo
        sudo -u "${user_name}" "$@"
    else
        "$@"
    fi
}

# Log messages
log()
{
    echo -e "[$(date)] $@" | sudoIf tee -a $LOG > /dev/null
}

log "** SCRIPT START **"

# Start dbus.
log 'Running "/etc/init.d/dbus start".'
if [ -f "/var/run/dbus/pid" ] && ! pgrep -x dbus-daemon  > /dev/null; then
    sudoIf rm -f /var/run/dbus/pid
fi
sudoIf /etc/init.d/dbus start 2>&1 | sudoIf tee -a /tmp/dbus-daemon-system.log > /dev/null
while ! pgrep -x dbus-daemon > /dev/null; do
    sleep 1
done

# Startup tigervnc server and fluxbox
sudoIf rm -rf /tmp/.X11-unix /tmp/.X*-lock
mkdir -p /tmp/.X11-unix
sudoIf chmod 1777 /tmp/.X11-unix
sudoIf chown root:${group_name} /tmp/.X11-unix
if [ "$(echo "${VNC_RESOLUTION}" | tr -cd 'x' | wc -c)" = "1" ]; then VNC_RESOLUTION=${VNC_RESOLUTION}x16; fi
screen_geometry="${VNC_RESOLUTION%*x*}"
screen_depth="${VNC_RESOLUTION##*x}"

# Check if VNC_PASSWORD is set and use the appropriate command
common_options="tigervncserver ${DISPLAY} -geometry ${screen_geometry} -depth ${screen_depth} -rfbport ${VNC_PORT} -dpi ${VNC_DPI:-96} -localhost -desktop fluxbox -fg"

if [ -n "${VNC_PASSWORD+x}" ]; then
    startInBackgroundIfNotRunning "Xtigervnc" sudoUserIf "${common_options} -passwd /usr/local/etc/vscode-dev-containers/vnc-passwd"
else
    startInBackgroundIfNotRunning "Xtigervnc" sudoUserIf "${common_options} -SecurityTypes None"
fi

# Spin up noVNC if installed and not running.
if [ -d "/usr/local/novnc" ] && [ "$(ps -ef | grep /usr/local/novnc/noVNC*/utils/launch.sh | grep -v grep)" = "" ]; then
    keepRunningInBackground "noVNC" sudoIf "/usr/local/novnc/noVNC*/utils/launch.sh --listen ${NOVNC_PORT} --vnc localhost:${VNC_PORT}"
    log "noVNC started."
else
    log "noVNC is already running or not installed."
fi

# Run whatever was passed in
log "Executing "\$@\"."
exec "$@"
log "** SCRIPT EXIT **"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions