I am using OpenSUSE and I have created a script that launches at startup the x11vnc server. But when the user logs out x11vnc is killed. I want it to start again automatically. Here the script I wrote. It works perfectly at boot.

# /etc/init.d/vnc
# Provides:          x11vnc server
# Required-Start:    xdm
# Should-Start: 
# Required-Stop: 
# Should-Stop: 
# Default-Start:     5
# Default-Stop:      0 1 2 6
# Short-Description: 
# Description:       Start or stop vnc server

SERVICE=$(basename $0)
#Gets the name of the script

#Binary path
ALLOWED_GROUP=$(getent group g_vnc-usr | awk -F ":" '{ print $4 }')
#Only inf-usr group is allowed to take control of any machine.

AUTH=`ps wwaux | grep '/X.*-auth' | sed -e 's/^.*-auth *//' -e 's/ .*$//' | head -n 1`

OPT="-display :0 -auth ${AUTH} -nopw -unixpw ${ALLOWED_GROUP} -shared -oa /var/log/vnc.log -xkb -bg -verbose -forever"
#Various options of the x11vnc providing auth, user auth, logging and "keep alive" connection.

CMD="${BIN} ${OPT}"
#Both bin and options are stored

. /lib/lsb/init-functions

# Reset status of this service

case "$1" in
    echo -n "Starting ${SERVICE}..."
        ## Start daemon with startproc(8). 
    /sbin/startproc ${CMD}

    ##>> /dev/null 2>&1
    sleep 2s

    # Remember status and be verbose.
        rc_status -v

    echo -n "Shutting down ${SERVICE}..."
    ## Stop daemon with killproc(8) 
    /sbin/killproc ${BIN}

    # Remember status and be verbose
    rc_status -v

    ## Stop the service and regardless of whether it was
    ## running or not, start it again.
    $0 stop
    $0 start

    # Remember status and be quiet

    echo -n "Checking for service ${SERVICE}..."
    ## Check status with checkproc(8), if process is running
    ## checkproc will return with exit status 0.
    /sbin/checkproc ${BIN}

    # Remember status and be verbose
    rc_status -v
    echo -n 
    echo -n "Usage: ${SERVICE} {start|stop|restart|status}"
    exit 1

This script allows any user from the group to take the machine over even if no one is currently logged in.

I wanted to use xinitrc and to add exec /etc/init.d/vnc restart

Thank you.

  • 1
    I finally added -loop at the end of the x11vnc command and it works. Create an outer loop restarting the x11vnc process whenever it terminates – igor012 Jul 19 '12 at 14:41

(Converting a comment to an answer)

The -loop argument can be used to restart x11vnc in a loop. From the man page:

Create an outer loop restarting the x11vnc process whenever it terminates. -bg and -inetd are ignored in this mode (however see -loopbg below).

Useful for continuing even if the X server terminates and restarts (at that moment the process will need permission to reconnect to the new X server of course).


On a RHEL box, using the systemctl, I made the following change. I added an "/bin/at now" command to start the service a minute later. In my case, I changed the stop command to be:

ExecStop=/bin/sh -c '/usr/bin/vncserver -kill -9 %i > /dev/null 2>&1; echo "systemctl start vncserver@:1.service" | /bin/at now + 1 minute || :'

I edited: /etc/systemd/system/vncserver@:1.service

After making the change, run this command to update the system: systemctl daemon-reload

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.