Sample Header Ad - 728x90

can't start VNC server from a service, Works fine when started from terminal TigerVNC + noVNC

2 votes
0 answers
4103 views
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 'vncserver@.service' 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 vncserver@1.service
And It starts without any error same for starting it
sudo systemctl start vncserver@1.service
However my vnc server don't start, running
sudo systemctl status vncserver@1.service
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: Thu Apr 13 16:26:40 2023 vncserver: ComparingUpdateTracker: 0 pixels in / 0 pixels out vncserver: ComparingUpdateTracker: (1:-nan ratio) vncserver: Killing Xtigervnc process ID 6921... which seems to be deadlocked. Using SIGKILL! vncserver: Starting applications specified in /home/tai79/.vnc/xstartup has failed. vncserver: Maybe try something simple first, e.g., vncserver: tigervncserver -xstartup /usr/bin/xterm systemd: vncserver@1.service: Main process exited, code=exited, status=255/EXCEPTION systemd: vncserver@1.service: Failed with result 'exit-code'.
Asked by ahmed (121 rep)
Apr 13, 2023, 09:06 PM
Last activity: Apr 13, 2023, 09:22 PM