How to stop x11vnc from shutting down when I log out?

5,874

Same problem for me on Kubuntu 16.04.1, but your script given me an idea for a solution.

Create a service file for systemd:

sudo nano /etc/systemd/system/x11vnc.service

this is my x11vnc.service file's:

[Unit]
Description=Start x11vnc at startup.
After=multi-user.target display-manager.service

[Service]
Type=simple
ExecStart=/bin/bash -c '/usr/bin/x11vnc -auth /var/run/sddm/* -noxdamage -norepeat -rfbauth /home/x11vnc/passwd -display :0 -rfbport 5900 -shared -o /var/log/x11vnc.log'
Restart=always
RestartSec=5

[Install]
WantedBy=multi-user.target

Set permissions for execute:

sudo chmod u+x /etc/systemd/system/x11vnc.service

Reload and activate script on systemd:

sudo systemctl daemon-reload
sudo systemctl enable x11vnc.service

Important: Be sure to not use the -loop and -forever options on the x11vnc command otherwise x11vnc will not be able to kill the process after a logout and systemd will not be able to restart the service.

Share:
5,874

Related videos on Youtube

Ben
Author by

Ben

Updated on September 18, 2022

Comments

  • Ben
    Ben about 1 year

    At boot I have

    sudo x11vnc -xkb -noxrecord -forever -noxfixes -noxdamage -display :0 -auth /var/run/lightdm/root/:0 -usepw
    

    run via init.d

    It works and shows me the login prompt when I use a VNC Client, however if I the logout the VNC server gets shutdown and I have to SSH in to restart it, I found and modified a script that I think should work:

    #!/bin/bash
    
    if pgrep "x11vnc"
    then
        echo "Running"
    else
        echo "Stopped"
        sudo x11vnc -xkb -noxrecord -forever -noxfixes -noxdamage -display :0 -auth /var/run/lightdm/root/:0 -usepw
    fi
    

    and it does (its in /usr/local/bin/testvnc if I run it however my cron job:

    * * * * * /usr/local/bin/testvnc
    

    It says its been run cat var/log/syslog | grep vnc however it does NOT start the vnc.