I would like to setup system socket activation for x11vnc on a server but I'm not getting the proper configuration to achieve my requirements.
I would like to:
- Open a new VNC connection to the server on standard port (5900). Socket activation should launch x11vnc on the currently running X server.
- Be able to connect a second client to the same vnc server so they can both see the same screen.
- When the last client disconnects,
x11vnc
should be stoped. - A new client connection re-launches
x11vnc
if it is not running.
Systemd is at 225 and x11vnc at 0.9.13.
It seems I can't use a simple x11vnc.socket
+x11vnc.service
files combination because x11vnc
will map to the next TCP port (5901) if it detects the standard port (5900) is already used (by the systemd socket).
So I use a systemd "proxy" (see https://www.freedesktop.org/software/systemd/man/systemd-socket-proxyd.html) so that systemd listen to 5900 and x11vnc on 5901. So I have:
proxy-to-x11vnc.socket:
[Socket]
ListenStream=5900
[Install]
WantedBy=sockets.target
proxy-to-x11vnc.service:
[Unit]
Description=x11vnc
Requires=x11vnc.service
After=x11vnc.service
[Service]
User=myuser
ExecStart=/lib/systemd/systemd-socket-proxyd 127.0.0.1:5901
x11vnc.service:
[Unit]
Description=x11vnc
[Service]
User=myuser
StandardError=syslog
ExecStart=/usr/bin/x11vnc -auth /home/myuser/.Xauthority -shared -display :0 -rfbport 5901 -noipv6
Only proxy-to-x11vnc.socket is started/enabled.
The problem with this setup is:
- On first client connection, I see x11vnc being started and listening on the proper port, but the client connection just "hangs". Looking at the server logs
x11vnc
does not receive the connection attempt. - Killing the client and reconnecting successfully show the remote display.
- Disconnecting the client will let
x11vnc
terminate, but I then cannot re-connect to it.x11vnc.service
is in the inactive (dead) state.
Thanks!