Starting x11vnc from init.d in jessie

I've spent last hour trying to make a descent init.d script 'new way' that's working properly so I can have x11vnc started at boot time.
Here it is:
#!/bin/sh
### BEGIN INIT INFO
# Provides:          x11vnc
# Should-Start:
# Required-Start:    gdm3
# Required-Stop:
# Default-Start:     5
# Default-Stop:      0 1 2 6
# Short-Description: x11vnc server
# Description:       Debian init script for the x11vnc server
### END INIT INFO
#
# Author:       Anton Valqkoff < anton  valqk  com >
#
set -e
PATH=/sbin:/bin:/usr/sbin:/usr/bin
SERVICE=$(basename $0)
PIDFILE="/var/run/$SERVICE.pid"
BIN=/usr/bin/x11vnc
OPT=" -display :0 -auth guess -rfbauth /etc/x11vncpassword -oa /var/log/vnc.log -xkb -forever"

test -x $BIN || exit 0

if [ -r /etc/default/locale ]; then
  . /etc/default/locale
  export LANG LANGUAGE
fi

. /lib/lsb/init-functions

case "$1" in
  start)
        CONFIGURED_DAEMON=$(basename "$(cat $DEFAULT_DISPLAY_MANAGER_FILE 2> /dev/null)")
        if [ `ps ax|grep $SERVICE|grep -v grep|wc -l` -gt 1 ]; then
                log_daemon_msg "Starting $SERVICE server" "$SERVICE"
        set +e
                start-stop-daemon --start --pidfile $PIDFILE -m --background --exec $BIN -- $OPT || log_end_msg 1
                log_end_msg 0
        set -e
        else
            log_daemon_msg "$SERVICE Already started..." "$SERVICE"
        fi
  ;;
  stop)
        log_daemon_msg "Stopping $SERVICE" "$SERVICE"
        set +e
        start-stop-daemon --stop --quiet --pidfile $PIDFILE \
                --name $SERVICE --retry 5
        set -e
        log_end_msg $?
  ;;
  reload)
        log_daemon_msg "Scheduling reload of $SERVICE" "$SERVICE"
        set +e
        start-stop-daemon --stop --signal HUP --quiet --pidfile $PIDFILE \
                --name $SERVICE
        set -e
        log_end_msg $?
  ;;
  status)
        status_of_proc -p "$PIDFILE" "$BIN" $SERVICE && exit 0 || exit $?
  ;;
  restart|force-reload)
        $0 stop
        $0 start
  ;;
  *)
        echo "Usage: $0 {start|stop|restart|reload|force-reload|status}"
        exit 1
  ;;
esac

exit 0

Trackbacks

Trackback specific URI for this entry

This link is not meant to be clicked. It contains the trackback URI for this entry. You can use this URI to send ping- & trackbacks from your own blog to this entry. To copy the link, right click and select "Copy Shortcut" in Internet Explorer or "Copy Link Location" in Mozilla.

No Trackbacks

Comments

Display comments as Linear | Threaded

No comments

Add Comment

You can use [geshi lang=lang_name [,ln={y|n}]][/geshi] tags to embed source code snippets.
Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
Standard emoticons like :-) and ;-) are converted to images.
E-Mail addresses will not be displayed and will only be used for E-Mail notifications.
To leave a comment you must approve it via e-mail, which will be sent to your address after submission.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA