2

Posting this because I've seen a lot of similar posts in searching for a solution, but no solution.

The issue is that I can launch a vncserver session to create a GNOME desktop by issuing a command in terminal or a script -- but only when ssh'd in to a computer or directly on the computer: NOT via a script at startup or via systemd. Here is the ~/.vnc/xstartup script:

#!/bin/sh 
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey -cursor_name left_ptr
xsetroot -solid grey left_ptr
vncconfig -iconic &
dbus-launch --exit-with-session /usr/bin/gnome-session &

And here is the command to start the session: vncserver :1 -localhost no -geometry 2560x1440 -depth 24.

All works perfectly from ssh or the computer itself: whether a direct terminal command or via a script that includes the command.

But that same script will fail if used as a startup script, and the same command will fail via systemd. Well, "fail" is strong: it does result in a semi-functional GNOME desktop session. That is, it does start a vnc session that I can reach and that has launched my startup applications (e.g.,gnome-terminal and nautilus). But the underlying desktop has failed to launch properly, so I can't move the windows (though I can quit them), there is not top bar, and I get the "Oh no! Something has gone wrong!” error where the desktop should be.

My sense is that this has something to do with how ~/.vnc/xstartup is being run at startup, but I can't figure it out. I am using tigervnc, as that is the only one that appears to like GNOME enough to work at all.

2
  • Did you find a fix for this issue or how did you handle it?
    – xyz
    Commented Aug 5, 2022 at 22:25
  • 1
    Things started from a startup script or systemd are likely to have a very limited environment set up for them. For example, $HOME might be unset. I'd recommend letting the startup script start a semi-functional session, and then inspecting the environment of the processes of that session via strings /proc/<PID/environ | sort | less or similar.
    – telcoM
    Commented Aug 6, 2022 at 2:55

1 Answer 1

1

In the old days of VNC, you would run one VNC service and it would service many clients to a single session (that session didn't even have to be logged in, you could log-in as any local user from VNC). And all was bright and good in the world (I got complacent with this way of doing things and originally found change hard to accept).

Then users and administrators wanted multiple users to be able to use VNC to run independent sessions via VNC. Doing so requires running independent instances of the VNC server software. Systemd supports this by providing templated service unit files. This allows for one VNC server unit file to service multiple instances of the service, with the username of the user running/using the service to be parameterized. See "SERVICE TEMPLATES" at: https://www.man7.org/linux/man-pages/man5/systemd.service.5.html.

You should use the templated service unit file that comes with TigerVNC Server (a fresh copy should be at /lib/systemd/system/[email protected]). Then each user can start an instance of the service when they need it. This will cause that user's ~/.vnc/passwd and ~/.vnc/xstartup to be used for their instance of the service.

This does somewhat prevent the "at startup" capability you are looking for (you could enable several variations of the service at startup, but their port #'s may change), but you should likely be forwarding the VNC session over SSH anyway (since VNC is NOT secure.)

2
  • I'm now really sure you answered the question as to why the vnc server works when starting it manually but has issues when starting through systemd.
    – xyz
    Commented Aug 10, 2022 at 7:11
  • 1
    @xyz - I don't know about the specific problem faced, but I do know that what is trying to be accomplished doesn't require a user generated systemd service unit file that has unknown environment settings and other hard to debug issues. The systemd service unit file provided by the TigerVNC Server package already accomplishes the goal set out, is known to work, and is supported by the package maintainers. The configurability that the OP wants is in the VNC session via the user's config/home directory not the service unit file. Using the package provided file may help solve the issue.
    – t0w0i7ne
    Commented Aug 10, 2022 at 15:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .