5

I am running Linux (Debian). I recently installed the x11VNC server on my computer. I found the command to start the server is:

x11vnc -display :0

I have been searching but did not find any information on how to restart and shutdown the x11VNC server. Is there a command(s) to do this?

5

If you're using systemd you should be able to set it up as a service. I found this thread which shows a similar task of setting up x11vnc as a Systemd service. The thread is titled: Index» Newbie Corner» how to enable x11vnc at startup using systemd ?.

From a comment in that thread

  1. Create the file: /etc/systemd/system/x11vnc.service

    [Unit]
    Description=VNC Server for X11
    Requires=display-manager.service
    After=display-manager.service
    
    [Service]
    Type=forking
    ExecStart=/usr/bin/x11vnc -norc -forever -shared -bg -rfbauth /etc/x11vnc.pass -allow 192.168.1. -autoport 5900 -o /var/log/x11vnc.log
    
  2. Create the file: /etc/systemd/system/graphical.target

    #  This file is part of systemd.
    #
    #  systemd is free software; you can redistribute it and/or modify it
    #  under the terms of the GNU Lesser General Public License as published by
    #  the Free Software Foundation; either version 2.1 of the License, or
    #  (at your option) any later version.
    
    [Unit]
    Description=Graphical Interface
    Documentation=man:systemd.special(7)
    Requires=multi-user.target
    After=multi-user.target
    Conflicts=rescue.target
    Wants=display-manager.service
    Wants=x11vnc.service
    AllowIsolate=yes
    
    [Install]
    Alias=default.target
    
  3. Enable Systemd service

    $ sudo systemctl enable graphical.target
    

    This should create a link like this:

    /etc/systemd/system/default.target -> /etc/systemd/system/graphical.target

  4. Reboot

  • Sorry but how does this stop the service? I can't see anything for kill/stop, just to launch it. – erm3nda Mar 30 '18 at 22:29
  • Systemctl stop .... – slm Mar 31 '18 at 14:11
  • Weak reply... ... ... Op asked for x11vnc "program" and not especifically "one and only one service". You may have many services or many instances. Systemctl work only for services. Your service has no ExecStop so i can't understand what do you expect when stoping the service but not the instance of x11vnc. Running services as like onehot with -forever and -bg will break your stuff. Do you use your service? I'll give a shot but i tried many things and i think you just wrote things that may not work. – erm3nda Mar 31 '18 at 14:26
10

Since you know how to start the server, here is a way to gracefully stop it:

x11vnc -R stop

basically you send a remote command (see -remote) to the running instance.

2

The solution for this that works for me is:

$ x11vnc -clear-all
  • This clears modifier keys, does nothing about shutting down the server. – NateS Jul 12 '17 at 13:42
0

Try:

killall x11vnc && /usr/bin/x11vnc -rfbport 5900 -bg -vncconnect -xvnc -forever 

Add any personalized options.

0

TLDR: What you want is asnwered here with a nice "not oneshot" type service:

http://www.lueckdatasystems.com/Successfully_running_x11vnc_as_a_Systemd_Service_in_Xubuntu_16.04_Xenial-Xerus

In case you wanna play things, i've do that before found the right answer. It worked sometimes, because it was setup wrong. If you use -bg or any other script that exit inmediately after executed, you'll need that, otherwise just stick to first link to run x11vnc service properly. I've ended using it, works perfect.

Advised: All stuff below just to play with

First of all, you must use service Type=oneshot along RemainAfterExit=yes to make the "stop" action to work. I've been struggling untill i got mine working.

To stop the x11vnc server by "display" like you'll do with vncserver -kill :1 (:1 here means :5901 because vnc uses default 590x ports) you need to use in example lsof to get pid, then kill it, gracefully or not, you choose -9 option or other of your choice.

If you always use the service (then the same rfbport) with the service, you already know the listening port, so it could be like thit:

ExecStop=/bin/bash -c "/bin/kill -9 `lsof -i:5901 -t`"

Because those params only accepts binarys and doesn't allow pipe, you have to wrap all inside bash -c "command"

Mine looks like https://gist.github.com/erm3nda/37e5720b4197a7a16c564418d377aac0 and doesnt work at boot, but works if you restart or start manually.

Server will not be killed if you run start again, but restart will do.

If you plan to run several x11servers in different ports, you must add @ to the service name then invoke with the number you want, and modify script to use %i as argument.

Just use x11vnc@NUMBER to start service:

Service filename: x11vnc@.service Enable it with port 5901: sudo systemctl enable x11vnc@1 Service ExecStart example: /usr/bin/x11vnc -forever -shared -bg -rfbport 590%i -display :0 -geometry 800x600 -rfbauth /etc/x11vnc.pass -listen 127.0.0$ Service ExecStop example: /bin/sh -c "/bin/kill -9 lsof -i:590%i -t" Start it: sudo service x11vnc@1 start to run under port 5901

Mine looks like https://gist.github.com/erm3nda/fa0bfb8f3737dc6398889adb50fdc84b and doesnt work at boot, but works if you restart it or start manually.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.