Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

#!/bin/sh
#
# /etc/init.d/vnc
#
### BEGIN INIT INFO
# 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
### END INIT INFO


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

BIN="/usr/bin/x11vnc"
#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

rc_reset
# Reset status of this service

case "$1" in
    start)
    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
    ;;

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

    # Remember status and be verbose
    rc_status -v
        ;;

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

    # Remember status and be quiet
    rc_status
    ;;

    status)
    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
    ;;
esac
rc_exit

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.

share|improve this question
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
add comment

1 Answer

(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).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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