3 # vncserver Starts/stop VNC server
7 # description: Starts and stops vncserver.
8 # Used to provide remote X administration services.
11 # Source function library
12 . /etc/rc.d/init.d/functions
15 . /etc/sysconfig/network
18 [ -f /etc/sysconfig/vncserver ] && . /etc/sysconfig/vncserver
20 # Check that networking is up.
21 if is_yes "${NETWORKING}"; then
22 if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
23 msg_network_down vncserver
31 # Check if the service is already running?
32 if [ -f /var/lock/subsys/vncserver ]; then
33 msg_already_running vncserver
37 ulimit -S -c 0 >/dev/null 2>&1
40 if [ ! -d /tmp/.X11-unix ]; then
41 mkdir -m 1777 /tmp/.X11-unix || :
42 restorecon /tmp/.X11-unix 2>/dev/null || :
46 for display in $VNCSERVERS; do
47 msg_starting "vncserver ($display)"
51 if [ "x$USER" == "xroot" ]; then
53 echo "-- Do not run vncserver as root!"
56 VNCUSERARGS="${VNCSERVERARGS[${DISP}]}"
57 USEREXISTS=`cat /etc/passwd | awk -F: "{ if (\"$USER\"==\\\$1) print \"yes\" }"`
58 if [ "x$USEREXISTS" != "xyes" ]; then
60 echo "-- User $USER does not exists!"
63 USERHOME=`runuser $USER -c 'echo $HOME'`
64 if [ ! -f "$USERHOME/.vnc/passwd" ]; then
66 echo "-- No password file found for user $USER!"
69 export USER VNCUSERARGS
70 daemon --user ${USER} "vncserver :${DISP} ${VNCUSERARGS}"
72 [ "$RETVAL" -eq 0 ] && echo $display >> /var/lock/subsys/vncserver
77 if [ ! -f /var/lock/subsys/vncserver ]; then
78 msg_not_running vncserver
84 for display in `cat /var/lock/subsys/vncserver`
86 msg_stopping "vncserver ($display)"
87 export USER="${display##*:}"
88 runuser ${USER} -c "vncserver -kill :${display%%:*}" >/dev/null 2>&1
90 [ "$RETVAL" -eq 0 ] && ok && continue
92 ERRDISP="$ERRDISP $display"
94 rm -f /var/lock/subsys/vncserver
95 [ "x$ERRDISP" != "x" ] && echo "$ERRDISP" > /var/lock/subsys/vncserver
99 # See how we were called.
118 msg_usage "$0 {start|stop|restart|status}"