# setting up tigervnc under systemd

## Adel Ahmed

I've emerged tigervnc with the server use flag set, I'm having trouble starting or enabling the service under systemd though, I've tried creating a script myself that would run the vncserver command but I end up with an xterm session instead of my default xfce session(I'm also using xorg module to share screens), should I create a service script or is there one already available?

thanks

workaround: xfce sartup scripts from the user account

script:  (I used the echo to test the script, you can remove both lines)

#!/bin/bash

#check if the vncserver has already been started

ps aux | grep vnc | head -n1 | grep Xvnc

if [ $? -eq 0 ]

then

echo true

else

echo false

vncserver

fiLast edited by Adel Ahmed on Sat Mar 08, 2014 6:03 am; edited 1 time in total

----------

## Adel Ahmed

any help?

----------

## fpemud

In Arch's tigervnc package, there's a "vncserver.service", maybe this can help?

I commit I haven't tried it.

https://aur.archlinux.org/packages/tigervnc-svn/

----------

## Adel Ahmed

Failed to issue method call: Unit vncserver.service failed to load: No such file or directory.

I'm clueless so far

----------

## SirRobin2318

Did you set User= in the file? 

What display did you enable it for?

----------

## Adel Ahmed

here's my user line:

DISPLAYS="adel:1"

----------

## SirRobin2318

Can you show me your vncserver.service file, and how you enabled it, the name of the symlink in /etc.

----------

## Adel Ahmed

Ihere's my service file:

[Unit]

Description=Remote desktop service (VNC)

After=network.target

[Service]

Type=forking

User=

# Clean any existing files in /tmp/.X11-unix environment

ExecStartPre=-/usr/bin/vncserver -kill %i

ExecStart=/usr/bin/vncserver %i

ExecStop=/usr/bin/vncserver -kill %i

[Install]

WantedBy=multi-user.target

this service fails to start due to the following error(s):

  Process: 1555 ExecStart=/usr/bin/vncserver %i (code=exited, status=2)

  Process: 1553 ExecStartPre=/usr/bin/vncserver -kill %i (code=exited, status=2)

Mar 07 16:54:45 localhost vncserver[1553]: vncserver: The HOME environment variable is not set.

Mar 07 16:54:45 localhost vncserver[1555]: vncserver: The HOME environment variable is not set.

Mar 07 16:54:45 localhost systemd[1]: tigervnc.service: control process exited, code=exited status=2

Mar 07 16:54:45 localhost systemd[1]: Failed to start Remote desktop service (VNC).

Mar 07 16:54:45 localhost systemd[1]: Unit tigervnc.service entered failed state.

I enabled the service using:

#systemctl enable tigervnc.service 

here's the result

ln -s '/etc/systemd/system/tigervnc.service' '/etc/systemd/system/multi-user.target.wants/tigervnc.service'

thanks

----------

## Adel Ahmed

If I try running vncserver here's what I get when I connect to the server:

http://postimg.org/image/lzblox3hl/

If I run using the root account, I can connect to an xfce session(the screen is not shared though)

If that problem can be fixed, I suppose I can use the bashrc file to start the vnc service

----------

## Adel Ahmed

I've copied over the xstartup file from the root account to the user account and Now I can start an xfce session when I connect to the server

the screen is not shared though, and I'm still having problems with the startup script

----------

## SirRobin2318

You have to set the User= line in the service file. 

Then disable the service, and enable in with the display you want to use:

systemctl enable tigervnc@:1.sevice

----------

## Adel Ahmed

is there a specific place where I should use the 'User' variable?

or should I place it at the beginning of the file?

----------

## SirRobin2318

You said you were using this service file:

```
[Unit]

Description=Remote desktop service (VNC)

After=network.target

[Service]

Type=forking

User=

# Clean any existing files in /tmp/.X11-unix environment

ExecStartPre=-/usr/bin/vncserver -kill %i

ExecStart=/usr/bin/vncserver %i

ExecStop=/usr/bin/vncserver -kill %i

[Install]

WantedBy=multi-user.target 
```

Edit that file, on the 7th line add your user.

----------

## Adel Ahmed

Oh sorry didn't notice that

localhost system # systemctl enable tigervnc@:1.service

Failed to issue method call: No such file or directory

when I start the regular tigervnc.service I get the following:

systemctl status tigervnc.service

tigervnc.service - Remote desktop service (VNC)

   Loaded: loaded (/etc/systemd/system/tigervnc.service; enabled)

   Active: failed (Result: exit-code) since (null); 4s ago

  Process: 1536 ExecStart=/usr/bin/vncserver %i (code=exited, status=2)

  Process: 1518 ExecStartPre=/usr/bin/vncserver -kill %i (code=exited, status=0/SUCCESS)

Mar 07 17:50:14 localhost vncserver[1518]: New 'localhost:3 (adel)' desktop is localhost:3

Mar 07 17:50:14 localhost vncserver[1518]: Starting applications specified in /home/adel/.vnc/xstartup

Mar 07 17:50:14 localhost vncserver[1518]: Log file is /home/adel/.vnc/localhost:3.log

Mar 07 17:50:14 localhost vncserver[1536]: usage: vncserver [:<number>] [-name <desktop-name>] [-depth <depth>]

Mar 07 17:50:14 localhost vncserver[1536]: [-geometry <width>x<height>]

Mar 07 17:50:14 localhost vncserver[1536]: [-pixelformat rgbNNN|bgrNNN]

Mar 07 17:50:14 localhost vncserver[1536]: [-fp <font-path>]

Mar 07 17:50:14 localhost systemd[1]: tigervnc.service: control process exited, code=exited status=2

Mar 07 17:50:14 localhost systemd[1]: Failed to start Remote desktop service (VNC).

Mar 07 17:50:14 localhost systemd[1]: Unit tigervnc.service entered failed state.

----------

## SirRobin2318

Try enabling it this way then: 

ln -s '/etc/systemd/system/tigervnc.service' '/etc/systemd/system/multi-user.target.wants/tigervnc@:1.service'

----------

## Adel Ahmed

nope nothing, I'm giving up the whole screen sharing idea, I'll just be trying to get the vnc server to start automatically, so if all else fails we can use bashrc

thanks for your help so far

----------

## SirRobin2318

Oh we can make this work. I'm guessing something is missing in tigervnc's config. I just wanted to do things one step at a time and first validate that the systemd side was correct (service file, how it's enabled, etc). 

If you change your mind and want to continue, try the following:

remove the link we added:

rm  '/etc/systemd/system/multi-user.target.wants/tigervnc@:1.service'

mv /etc/systemd/system/tigervnc.service /etc/systemd/system/tigervnc@.service

sytsemctl enable tigervnc@:1.service 

does that work better? 

if it does:

sytsemctl start tigervnc@:1.service 

and then give me:

journalctl -u tigervnc

----------

## Adel Ahmed

well, the vnc server starts but when I connect all I get is a black screen.

here's my journalctl since the last reboot:

Mar 07 20:11:28 localhost systemd[1]: Starting Remote desktop service (VNC)...

Mar 07 20:11:32 localhost vncserver[1283]: New 'localhost:1 (adel)' desktop is localhost:1

Mar 07 20:11:32 localhost vncserver[1283]: Starting applications specified in /home/adel/.vnc/xstartup

Mar 07 20:11:32 localhost vncserver[1283]: Log file is /home/adel/.vnc/localhost:1.log

Mar 07 20:11:32 localhost vncserver[1413]: usage: vncserver [:<number>] [-name <desktop-name>] [-depth <depth>]

Mar 07 20:11:32 localhost vncserver[1413]: [-geometry <width>x<height>]

Mar 07 20:11:32 localhost vncserver[1413]: [-pixelformat rgbNNN|bgrNNN]

Mar 07 20:11:32 localhost vncserver[1413]: [-fp <font-path>]

Mar 07 20:11:32 localhost vncserver[1413]: [-cc <visual>]

Mar 07 20:11:32 localhost vncserver[1413]: [-fg]

Mar 07 20:11:32 localhost vncserver[1413]: [-autokill]

Mar 07 20:11:32 localhost vncserver[1413]: <Xvnc-options>...

Mar 07 20:11:32 localhost vncserver[1413]: vncserver -kill <X-display>

Mar 07 20:11:32 localhost vncserver[1413]: vncserver -list

Mar 07 20:11:32 localhost systemd[1]: tigervnc.service: control process exited, code=exited status=2

Mar 07 20:11:32 localhost systemd[1]: Failed to start Remote desktop service (VNC).

Mar 07 20:11:32 localhost systemd[1]: Unit tigervnc.service entered failed state.

thanks

----------

## Adel Ahmed

I've used the xfce autostart to run a script that checks for running vnc servers and runs if no servers are started

I suppose I found what I was looking for. thanks alot for your help SirRobin

----------

## SirRobin2318

So everything is working now? Good  :Smile: 

----------

