Score:1

Running multiple simultaneous VNC sessions

hm flag

I'm working on a project for a client that wants to access some Windows-apps via my website using noVNC, that gave me an idea for setting up a server with multiple users. I've installed TigerVNC-server on my CentOS 7 VPS, which works well when one user is connected, but when the second user connects, he/she will only get a black screen as it seems like gnome won't start for the second user.

If i, for example run the vncservice@:1 it all works fine and the user will be logged in no problem but when vncservice@:2 starts, it won't start gnome and he/she will get a black screen with only a cursor. When vncservice@:2 starts first, that user will be launched in to gnome but vncservice@:1 won't see their desktop etc. etc.

This is what my setup looks like:

[User 1 and 2 ~/.vnc/xstartup]
#!/bin/sh

unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
/etc/X11/xinit/xinitrc
# Assume either Gnome or KDE will be started by default when installed
# We want to kill the session automatically in this case when user logs out. In case you modify
# /etc/X11/xinit/Xclients or ~/.Xclients yourself to achieve a different result, then you should
# be responsible to modify below code to avoid that your session will be automatically killed

sleep 60

if [ -e /usr/bin/gnome-session -o -e /usr/bin/startkde ]; then
    vncserver -kill $DISPLAY
    killall -u $USER
fi

[/etc/X11/xinit/xinitrc]

#!/bin/sh

# Mandatorily source xinitrc-common, which is common code shared between the
# Xsession and xinitrc scripts which has been factored out to avoid duplication
. /etc/X11/xinit/xinitrc-common

# The user may have their own clients they want to run.  If they don't,
# fall back to system defaults.
if [ -f $HOME/.Xclients ]; then
    exec $CK_XINIT_SESSION $SSH_AGENT $HOME/.Xclients || \
    exec $CK_XINIT_SESSION $SSH_AGENT $HOME/.Xclients
elif [ -f /etc/X11/xinit/Xclients ]; then
    exec $CK_XINIT_SESSION $SSH_AGENT /etc/X11/xinit/Xclients || \
    exec $CK_XINIT_SESSION $SSH_AGENT /etc/X11/xinit/Xclients
else
    # Failsafe settings.  Although we should never get here
    # (we provide fallbacks in Xclients as well) it can't hurt.
    [ -x /usr/bin/xsetroot ] && /usr/bin/xsetroot -solid '#222E45'
    [ -x /usr/bin/xclock ] && /usr/bin/xclock -geometry 100x100-5+5 &
    [ -x /usr/bin/xterm ] && xterm -geometry 80x50-50+150 &
    [ -x /usr/bin/twm ] && /usr/bin/twm
fi

[vncserver@:1 and vncserver@:2, is replace with the actual username]

[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target

[Service]
Type=forking
User=<USERNAME>
Group=<USERNAME>

ExecStartPre=-/usr/bin/vncserver -kill %i
ExecStart=/usr/bin/vncserver %i
PIDFile=/home/<USERNAME>/.vnc/%H%i.pid
ExecStop=-/usr/bin/vncserver -kill %i


[Install]
WantedBy=multi-user.target

[Second user VNC log]

[root@.... ~]# systemctl status vncserver@:5
● vncserver@:5.service - Remote desktop service (VNC)
   Loaded: loaded (/etc/systemd/system/vncserver@:5.service; disabled; vendor preset: disabled)
   Active: active (running) since za 2021-07-24 19:04:54 CEST; 59s ago
  Process: 25990 ExecStart=/usr/bin/vncserver %i (code=exited, status=0/SUCCESS)
  Process: 25981 ExecStartPre=/usr/bin/vncserver -kill %i (code=exited, status=2)
 Main PID: 25997 (Xvnc)
   CGroup: /system.slice/system-vncserver.slice/vncserver@:5.service
           ├─25997 /usr/bin/Xvnc :5 -auth /home/AHtYezzDXegQScyu/.Xauthority -desktop <HOSTNAME>:5 (AHtYezzDXegQScyu) -fp catalogue:/etc/X11/fontpath.d -geometry 1024x768 -pn -rfbauth /home/AHtYezzDXegQScyu/.vnc/passwd -rfbport 5905 -rfbwait 30000
           ├─26006 /bin/sh /home/AHtYezzDXegQScyu/.vnc/xstartup
           ├─26018 dbus-launch --sh-syntax --exit-with-session
           ├─26019 /usr/bin/dbus-daemon --fork --print-pid 5 --print-address 7 --session
           ├─26053 /usr/libexec/imsettings-daemon
           ├─26057 /usr/libexec/gvfsd
           ├─26062 /usr/libexec/gvfsd-fuse /home/AHtYezzDXegQScyu/.gvfs -f -o big_writes
           ├─26126 /usr/libexec/at-spi-bus-launcher
           ├─26131 /usr/bin/dbus-daemon --config-file=/usr/share/defaults/at-spi2/accessibility.conf --nofork --print-address 3
           ├─26135 /usr/libexec/at-spi2-registryd --use-gnome-session
           ├─26158 /usr/bin/gnome-keyring-daemon --start --components=ssh
           ├─26241 /usr/libexec/xdg-permission-store
           ├─26246 /usr/libexec/gnome-shell-calendar-server
           ├─26251 /usr/libexec/evolution-source-registry
           ├─26258 /usr/libexec/goa-daemon
           ├─26269 /usr/libexec/goa-identity-service
           ├─26275 /usr/libexec/mission-control-5
           ├─26286 /usr/libexec/gvfs-udisks2-volume-monitor
           ├─26293 /usr/libexec/gvfs-mtp-volume-monitor
           ├─26299 /usr/libexec/gvfs-goa-volume-monitor
           ├─26305 /usr/libexec/gvfs-gphoto2-volume-monitor
           ├─26310 /usr/bin/dbus-daemon --fork --print-pid 5 --print-address 7 --session
           ├─26311 /usr/libexec/gvfs-afc-volume-monitor
           ├─26411 /usr/libexec/gsd-print-notifications
           ├─26413 /usr/libexec/gsd-rfkill
           ├─26418 /usr/libexec/gsd-screensaver-proxy
           ├─26454 sleep 60
           └─26458 /usr/libexec/evolution-calendar-factory

jul 24 19:05:22 <HOSTNAME> gnome-session-binary[26007]: WARNING: Failed to start app: Unable to start application: Failed to fork (Resource temporarily unavailable)
jul 24 19:05:22 <HOSTNAME> gsd-print-notif[26411]: Could not execute system-config-printer-udev handler: Failed to fork (Resource temporarily unavailable)
jul 24 19:05:22 <HOSTNAME> gnome-session-binary[26007]: WARNING: Application 'org.gnome.SettingsDaemon.Power.desktop' killed by signal 5
jul 24 19:05:22 <HOSTNAME> gnome-session[26007]: gnome-session-binary[26007]: WARNING: Application 'org.gnome.SettingsDaemon.Power.desktop' killed by signal 5
jul 24 19:05:22 <HOSTNAME> gnome-session-binary[26007]: GLib-WARNING: GError set over the top of a previous GError or uninitialized memory.
                                                                       This indicates a bug in someone's code. You must ensure an error is NULL before it's set.
                                                                       The overwriting error message was: Unable to start application: Failed to fork (Resource temporarily unavailable)...
jul 24 19:05:22 <HOSTNAME> gnome-session[26007]: gnome-session-binary[26007]: GLib-WARNING: GError set over the top of a previous GError or uninitialized memory.
jul 24 19:05:22 <HOSTNAME> gnome-session[26007]: This indicates a bug in someone's code. You must ensure an error is NULL before it's set.
jul 24 19:05:22 <HOSTNAME> gnome-session[26007]: The overwriting error message was: Unable to start application: Failed to fork (Resource temporarily unavailable)
jul 24 19:05:22 <HOSTNAME> evolution-calen[26465]: creating thread 'gdbus': Error creating thread: Resource temporarily unavailable
jul 24 19:05:47 <HOSTNAME> gnome-shell-cal[26246]: Could not load source 'birthdays': Timeout was reached

[/etc/X11/xinit/Xclients]

#!/bin/bash

GSESSION="$(type -p gnome-session)"
STARTKDE="$(type -p startkde)"

# check to see if the user has a preferred desktop
PREFERRED=
if [ -f /etc/sysconfig/desktop ]; then
    . /etc/sysconfig/desktop
    if [ "$DESKTOP" = "GNOME" ]; then
        PREFERRED="$GSESSION"
    elif [ "$DESKTOP" = "KDE" ]; then
        PREFERRED="$STARTKDE"
    fi
fi

if [ -n "$PREFERRED" ]; then
    exec "$PREFERRED"
fi

# now if we can reach here, either no desktop file was present,
# or the desktop requested is not installed.

if [ -n "$GSESSION" -a -f /usr/share/xsessions/gnome.desktop ]; then
    # by default, we run GNOME.
    exec "$GSESSION" --session=gnome
elif [ -n "$STARTKDE" ]; then
    # if GNOME isn't installed, try KDE.
    exec "$STARTKDE"
fi

# We should also support /etc/X11/xinit/Xclients.d scripts
XCLIENTS_D=/etc/X11/xinit/Xclients.d
if [ "$#" -eq 1 ] && [ -x "$XCLIENTS_D/Xclients.$1.sh" ]; then
    exec -l $SHELL -c "$SSH_AGENT $XCLIENTS_D/Xclients.$1.sh"
fi

# Failsafe.

# these files are left sitting around by TheNextLevel.
rm -f $HOME/Xrootenv.0

# Argh! Nothing good is installed. Fall back to twm
{
    # gosh, neither fvwm95 nor fvwm2 is available;
    # fall back to failsafe settings
    [ -x /usr/bin/xsetroot ] && /usr/bin/xsetroot -solid '#222E45'

    if [ -x /usr/bin/xclock ] ; then
        /usr/bin/xclock -geometry 100x100-5+5 &
    fi
    if [ -x /usr/bin/xterm ] ; then
        /usr/bin/xterm -geometry 80x50-50+150 &
    fi
    if [ -x /usr/bin/firefox -a -f /usr/share/doc/HTML/index.html ]; then
        /usr/bin/firefox /usr/share/doc/HTML/index.html &
    fi
    if [ -x /usr/bin/twm ] ; then
        exec /usr/bin/twm
    fi
}

The stupid thing is, after trying to start the second vncserver about 50 times, it usually works one time, when i stop and start the service again it won't show anything again, except for a mouse cursor.

There is plenty of free memory left (about 5 gigs), there also is plenty of storage space left (about 100 gigs). When i edit my ~/.vnc/xstartup file to include only a file manager, it works fine everytime, trying to run a session for multiple users seems to be the problem.

Thanks for reading trough all of this, i've already lost countless hours trying to debug this without any (major) improvements.

UPDATE 1: After many hours of more tinkering, i still didn't get gnome working. Desperate times call for desperate measures so i just ended up installing Xfce and made it prettier with a nice theme and a icon pack. It just worked after i installed it. I removed all gnome references from the xstartup files and added startxfce4.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.