Score:1

Why does vncserver fail when run from a service, Works fine when started from terminal [Tiger VNC, noVNC]

nf flag

Why does vncserver fail when run from a service I have a VNC setup using TigerVNC and noVNC on my linux machine (Ubuntu 20.4). It works perfectly when started it from terminal but I want to start it from a service so that it can auto start on boot however it is not working

My service file name '[email protected]' located at /etc/systemd/system looks like this

[Unit]
Description = VNC server
After=syslog.target network.target

[Service]
Type=forking
User=taisafmr15

ExecStartPre=-/usr/bin/vncserver -kill :2
ExecStart=/usr/bin/vncserver :2 -geometry 1600x900 -depth 24 -localhost no
ExecStop=/usr/bin/vncserver -kill :2

[Install]
WantedBy=multi-user.target

I can enable my service using

sudo systemctl enable [email protected]

And It starts without any error same for starting it

sudo systemctl start [email protected]

However my vnc server don't start, running

sudo systemctl status [email protected]

shows that it failed (code=exited, status=255/EXCEPTION) looking into logs it shows it failed on ExecStart and the only error code / message I see is this (code=exited, status=255/EXCEPTION)

However when I run that command normally from my terminal my vnc server starts fine just not from a service,

Struggling with for days Any help / recommendation would be helpful

EDIT: My xstartup file at ~/.vnc/xstartup

#!/bin/sh
[-x /etc/vnc/xstartup] && exec /etc/vnc/xstartup
[-r $HOME/.Xresources] && xrdb $HOME/.Xresources

My xstartup file at /etc/vnc/xstartup

#!/bin/sh
export DISPLAY=:2
test x"$SHELL" = x"" && SHELL=/bin/bash
test x"$1"     = x"" && set -- default

vncconfig -iconic &
"$SHELL" -l << EOF
export XDG_SESSION_TYPE=x11
export XDG_DATA_DIRS=/usr/share/ubuntu:/usr/local/share/:/usr/share/:/var/lib/snapd/desktop
export XDG_CONFIG_DIRS=/etc//xdg-ubuntu:/etc/xdg
export XDG_CURRENT_DESKTOP=ubuntu:GNOME
export DESKTOP_SESSION=/usr/share/xsessions/ubuntu.desktop
export GNOME_SHELL_SESSION_MODE=ubuntu
dbus-launch --exit-with-session /usr/bin/gnome-session --session=ubuntu
EOF
vncserver -kill $DISPLAY

both xstartup files have follwoing permissions

sudo chmod +x /etc/vnc/xstartup
sudo chmod 777 /etc/vnc/xstartup

Full Error message

vncserver[7143]: Thu Apr 13 16:26:40 2023
vncserver[7143]:  ComparingUpdateTracker: 0 pixels in / 0 pixels out
vncserver[7143]:  ComparingUpdateTracker: (1:-nan ratio)
vncserver[7143]: Killing Xtigervnc process ID 6921... which seems to be deadlocked. Using SIGKILL!

vncserver[6912]: Starting applications specified in /home/tai79/.vnc/xstartup has failed.
vncserver[6912]: Maybe try something simple first, e.g.,
vncserver[6912]:         tigervncserver -xstartup /usr/bin/xterm
systemd[1]: [email protected]: Main process exited, code=exited, status=255/EXCEPTION
systemd[1]: [email protected]: Failed with result 'exit-code'.

Tried changing xstartup files, using different desktop environments etc

petep avatar
in flag
Change type to "oneshot". And or add RemainAfterExit=yes SuccessExitStatus=0 to Service section
petep avatar
in flag
Why you named the vnc service file with "@1", when its display :2? Comment out both lines in .vnc/xstartup . And try "vncconfig -iconic &" to /etc/vnc/xstartup
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.