-
Notifications
You must be signed in to change notification settings - Fork 0
/
vncserver_rc
executable file
·113 lines (96 loc) · 2.56 KB
/
vncserver_rc
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/bin/bash -e
### BEGIN INIT INFO
# Provides: vncserver
# Required-Start: networking
# Default-Start: 3 4 5
# Default-Stop: 0 6
### END INIT INFO
set -e
. /lib/lsb/init-functions
#Does the config file exist, if not halt
[ -f /etc/vncservers.conf ] || { echo "Config file /etc/vncservers.conf does not exist" ; exit 1 ;}
#Prep some variables to received input from the config file
unset VNCSERVERARGS
VNCSERVERS=""
[ -f /etc/vncservers.conf ] && . /etc/vncservers.conf
prog=$"VNC Server"
#### START THE SERVICES ####
start() {
REQ_USER=$2 #Check to see if a specific user's server need to be restarted
echo -n $"Starting $prog: " #This line start the output and it appended below
ulimit -S -c 0 >/dev/null 2>&1
RETVAL=0
for display in ${VNCSERVERS} #iterate over the displays
do
export USER="${display##*:}"
if test -z "${REQ_USER}" -o "${REQ_USER}" == ${USER} ; then
echo "${display} " #appends the display number to the output line
unset BASH_ENV ENV
DISP="${display%%:*}"
export VNCUSERARGS="${VNCSERVERARGS[${DISP}]}"
su ${USER} -c "cd ~${USER} && [ -f .vnc/passwd ] && tightvncserver :${DISP} ${VNCUSERARGS}" #start a single display
fi
done
}
#### STOP THE SERVICES ####
stop() {
REQ_USER=$2
echo -n $"Shutting down ${prog}: "
for display in ${VNCSERVERS}
do
export USER="${display##*:}"
if test -z "${REQ_USER}" -o "${REQ_USER}" == ${USER} ; then
echo "${display} "
unset BASH_ENV ENV
export USER="${display##*:}"
su ${USER} -c "tightvncserver -kill :${display%%:*}" >/dev/null 2>&1
fi
done
echo -e "${prog} Stopped"
}
#### GET THE SERVICES STATUS ####
status() {
REQ_USER=$2
exitcode=0
if test ${REQ_USER}
then echo "Checking User Service: ${REQ_USER}"
else echo "Checking ${VNCSERVERS}"
fi
for display in ${VNCSERVERS}
do
if test ${REQ_USER}
then status_of_proc -p "/tmp/.X${displayy%%:*}-lock" /usr/bin/Xtightvnc $display && exit 0 || exit $?
else status_of_proc -p "/tmp/.X${displayy%%:*}-lock" /usr/bin/Xtightvnc $display && statuscode=$?
if test $statuscode > $exitcode; then $exitcode=statuscode; fi
fi
done
exit $exitcode
}
# See how we were called.
case "$1" in
start)
start $@
;;
stop)
stop $@
;;
restart|reload)
stop $@
sleep 3
start $@
;;
condrestart)
if [ -f /var/lock/subsys/vncserver ]; then
stop $@
sleep 3
start $@
fi
;;
status)
echo "This doesn't quite work."
status $@
;;
*)
echo $"Usage: $0 {start|stop|restart|condrestart|status}"
exit 1
esac