-
Notifications
You must be signed in to change notification settings - Fork 3
/
x11vnc
executable file
·72 lines (67 loc) · 1.75 KB
/
x11vnc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
### BEGIN INIT INFO
# Provides: x11vnc
# Should-Start:
# Required-Start: lightdm
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: X11 VNC Server for Display :0
# Description: Debian init script for the X11 VNC Server
### END INIT INFO
#
# Authors: Brian Cunnie <[email protected]>
# Colin Deeb <[email protected]>
# Laurence Koret <[email protected]>
#
# MIT License
set -e
PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/x11vnc
DAEMON_ARGS="-forever -display :0"
DAEMON_USER=pi
eval DAEMON_HOME=~$DAEMON_USER
DISPLAY=:0
. /lib/lsb/init-functions
# The X Server can take from 3-8 seconds to start, so we
# try for 20 seconds to test to see if the Xserver is up
# before starting the VNC server.
function start_x11vnc() {
local COUNT LIMIT XAUTHORITY
COUNT=0
LIMIT=20
while :; do
if xrdb -query -display $DISPLAY > /dev/null 2>&1; then
log_daemon_msg "Start x11vnc: X is running"
start-stop-daemon --start --quiet \
--name x11vnc --chuid $DAEMON_USER --background \
--exec $DAEMON -- $DAEMON_ARGS
return $?
else
COUNT=$(($COUNT + 1))
if [ $COUNT -ge $LIMIT ]; then
log_daemon_msg "Start x11vnc: Giving up; X isn't running on $DISPLAY"
return 2
fi
log_daemon_msg "Start x11vnc: X isn't up yet; waited $COUNT seconds"
sleep 1
cp $DAEMON_HOME/.Xauthority ~ || true
fi
done
}
case "$1" in
start)
log_daemon_msg "Start x11vnc"
start_x11vnc
log_daemon_msg " End start x11vnc"
;;
stop)
start-stop-daemon --stop --quiet --name x11vnc
log_daemon_msg "x11vnc has been stopped"
;;
*)
echo "Usage: /etc/init.d/x11vnc {start|stop}"
exit 1
;;
esac
exit 0