|
| 1 | +#!/bin/bash -e |
| 2 | +### BEGIN INIT INFO |
| 3 | +# Provides: vncserver |
| 4 | +# Required-Start: networking |
| 5 | +# Default-Start: 3 4 5 |
| 6 | +# Default-Stop: 0 6 |
| 7 | +### END INIT INFO |
| 8 | + |
| 9 | +set -e |
| 10 | +. /lib/lsb/init-functions |
| 11 | + |
| 12 | +#Does the config file exist, if not halt |
| 13 | +[ -f /etc/vncservers.conf ] || { echo "Config file /etc/vncservers.conf does not exist" ; exit 1 ;} |
| 14 | + |
| 15 | +#Prep some variables to received input from the config file |
| 16 | +unset VNCSERVERARGS |
| 17 | +VNCSERVERS="" |
| 18 | +[ -f /etc/vncservers.conf ] && . /etc/vncservers.conf |
| 19 | + |
| 20 | +prog=$"VNC Server" |
| 21 | + |
| 22 | +#### START THE SERVICES #### |
| 23 | +start() { |
| 24 | +REQ_USER=$2 #Check to see if a specific user's server need to be restarted |
| 25 | + |
| 26 | + |
| 27 | +echo -n $"Starting $prog: " #This line start the output and it appended below |
| 28 | +ulimit -S -c 0 >/dev/null 2>&1 |
| 29 | +RETVAL=0 |
| 30 | + |
| 31 | +for display in ${VNCSERVERS} #iterate over the displays |
| 32 | + do |
| 33 | + export USER="${display##*:}" |
| 34 | + if test -z "${REQ_USER}" -o "${REQ_USER}" == ${USER} ; then |
| 35 | + echo "${display} " #appends the display number to the output line |
| 36 | + unset BASH_ENV ENV |
| 37 | + DISP="${display%%:*}" |
| 38 | + export VNCUSERARGS="${VNCSERVERARGS[${DISP}]}" |
| 39 | + su ${USER} -c "cd ~${USER} && [ -f .vnc/passwd ] && tightvncserver :${DISP} ${VNCUSERARGS}" #start a single display |
| 40 | + fi |
| 41 | + done |
| 42 | +} |
| 43 | + |
| 44 | +#### STOP THE SERVICES #### |
| 45 | +stop() { |
| 46 | +REQ_USER=$2 |
| 47 | + |
| 48 | +echo -n $"Shutting down ${prog}: " |
| 49 | + |
| 50 | +for display in ${VNCSERVERS} |
| 51 | + do |
| 52 | + export USER="${display##*:}" |
| 53 | + if test -z "${REQ_USER}" -o "${REQ_USER}" == ${USER} ; then |
| 54 | + echo "${display} " |
| 55 | + unset BASH_ENV ENV |
| 56 | + export USER="${display##*:}" |
| 57 | + su ${USER} -c "tightvncserver -kill :${display%%:*}" >/dev/null 2>&1 |
| 58 | + fi |
| 59 | + done |
| 60 | + |
| 61 | +echo -e "${prog} Stopped" |
| 62 | +} |
| 63 | + |
| 64 | +#### GET THE SERVICES STATUS #### |
| 65 | +status() { |
| 66 | +REQ_USER=$2 |
| 67 | +exitcode=0 |
| 68 | + |
| 69 | +if test ${REQ_USER} |
| 70 | + then echo "Checking User Service: ${REQ_USER}" |
| 71 | + else echo "Checking ${VNCSERVERS}" |
| 72 | +fi |
| 73 | + |
| 74 | +for display in ${VNCSERVERS} |
| 75 | + do |
| 76 | + if test ${REQ_USER} |
| 77 | + then status_of_proc -p "/tmp/.X${displayy%%:*}-lock" /usr/bin/Xtightvnc $display && exit 0 || exit $? |
| 78 | + else status_of_proc -p "/tmp/.X${displayy%%:*}-lock" /usr/bin/Xtightvnc $display && statuscode=$? |
| 79 | + if test $statuscode > $exitcode; then $exitcode=statuscode; fi |
| 80 | + fi |
| 81 | + done |
| 82 | + |
| 83 | +exit $exitcode |
| 84 | +} |
| 85 | + |
| 86 | +# See how we were called. |
| 87 | +case "$1" in |
| 88 | + start) |
| 89 | + start $@ |
| 90 | + ;; |
| 91 | + stop) |
| 92 | + stop $@ |
| 93 | + ;; |
| 94 | + restart|reload) |
| 95 | + stop $@ |
| 96 | + sleep 3 |
| 97 | + start $@ |
| 98 | + ;; |
| 99 | + condrestart) |
| 100 | + if [ -f /var/lock/subsys/vncserver ]; then |
| 101 | + stop $@ |
| 102 | + sleep 3 |
| 103 | + start $@ |
| 104 | + fi |
| 105 | + ;; |
| 106 | + status) |
| 107 | + echo "This doesn't quite work." |
| 108 | + status $@ |
| 109 | + ;; |
| 110 | + *) |
| 111 | + echo $"Usage: $0 {start|stop|restart|condrestart|status}" |
| 112 | + exit 1 |
| 113 | +esac |
0 commit comments