You are not logged in.

#1 2015-08-13 07:42:17

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,734
Website

Cannot get systemd to auto start vncserver in usermode

I created the attached ~/.config/systemd/user/vncserver@.service and I am able to run it manually via `systemctl --user start vncserver@:1` just fine.  I enabled it via `systemctl --user enable vncserver@:1` and I see the symlink systemd created for me but it never starts automatically on a reboot... why?

On a reboot, all I is 'inactive (dead)'. for the status.

Here is the symlink:

% ls -l ~/.config/systemd/user/multi-user.target.wants
total 0
lrwxrwxrwx 1 facade users 53 Aug 13 03:25 vncserver@:1.service -> /home/facade/.config/systemd/user/vncserver@.service

Here is the service file:

% cat ~/.config/systemd/user/vncserver@.service  
[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target

[Service]
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/usr/bin/vncserver -fg -geometry 2000x1200 -AlwaysShared -localhost -dpi 100 %i
ExecStop=/usr/bin/vncserver -kill %i

[Install]
WantedBy=multi-user.target

Last edited by graysky (2015-08-13 07:44:37)

Offline

#2 2015-08-13 11:38:40

mauritiusdadd
Member
From: Benevento, Italy
Registered: 2013-10-27
Posts: 776

Re: Cannot get systemd to auto start vncserver in usermode

I can confirm that your user unit is not executed, even if it is enabled. The problem seems to be here:

graysky wrote:
[Install]
WantedBy=multi-user.target

User units in facts are executed on user login, so using multi-user.target will screw them up in some way: just use default.target. If you want a service that is started independently of the fact that the user is logged in or not, you should create a system unit and add the following line to the [Service] section

User=<your user>

Last edited by mauritiusdadd (2015-08-13 11:43:12)


About me - github

-- When you have eliminated the impossible, whatever remains, however improbable, must be the truth -- Spock | Sherlock Holmes

Offline

#3 2015-08-13 12:00:33

Raynman
Member
Registered: 2011-10-22
Posts: 1,539

Re: Cannot get systemd to auto start vncserver in usermode

When systemd starts, it starts default.target. At the system level, that is usually symlinked to multi-user.target or graphical.target (which requires multi-user.target). At the user level, a multi-user.target does not exist, so your vncserver never gets activated as a dependency of this nonexistent unit.

The man page systemd.special(7) documents these special targets.

Offline

#4 2015-08-14 05:36:41

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,734
Website

Re: Cannot get systemd to auto start vncserver in usermode

Changing the WantedBy target to default does indeed get it to autostart, but upon logging into the server, I am presented with a black screen instead of xfce4 per my ~/.vnc/xstart.  If I manually restart it, everything works as expected.  Perhaps the default target doesn't have everything up?  How about for others?

Offline

#5 2015-08-14 10:14:16

mauritiusdadd
Member
From: Benevento, Italy
Registered: 2013-10-27
Posts: 776

Re: Cannot get systemd to auto start vncserver in usermode

graysky wrote:
ExecStart=/usr/bin/vncserver -fg -geometry 2000x1200 -AlwaysShared -localhost -dpi 100 %i

Try without the option -fg: it cause my user session to hang on my machine, but it works quite fine without that (I'm using DWM tough, and the mouse and the keyboard do not work, but everything else works just fine*). Does

systemctl --user status vncserver@:1.service

show anything interesting?

--edit: * I just logged in in view-only mode...

Last edited by mauritiusdadd (2015-08-14 12:01:24)


About me - github

-- When you have eliminated the impossible, whatever remains, however improbable, must be the truth -- Spock | Sherlock Holmes

Offline

#6 2015-08-14 11:29:42

Buddlespit
Member
From: Chesapeake, Va.
Registered: 2014-02-07
Posts: 507

Re: Cannot get systemd to auto start vncserver in usermode

I've only been able to get any user services and timers to auto start by creating a script calling for them (startservices.sh), then adding the script to the user (my) xinitrc. YMMV.


An old man, trying to stay sane

Offline

Board footer

Powered by FluxBB