3 # vncserver Starts/stop VNC server
7 # description: Starts and stops vncserver.
8 # Used to provide remote X administration services.
12 # Source function library
13 . /etc/rc.d/init.d/functions
16 . /etc/sysconfig/network
19 [ -f /etc/sysconfig/vncserver ] && . /etc/sysconfig/vncserver
21 # Check that networking is up.
22 if is_yes "${NETWORKING}"; then
23 if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
24 msg_network_down vncserver
32 # Check if the service is already running?
33 if [ ! -f /var/lock/subsys/vncserver ]; then
34 ulimit -S -c 0 >/dev/null 2>&1
37 if [ ! -d /tmp/.X11-unix ]
39 mkdir -m 1777 /tmp/.X11-unix || :
40 restorecon /tmp/.X11-unix 2>/dev/null || :
44 for display in $VNCSERVERS
46 msg_starting "vncserver ($display)"
50 if [ "x$USER" == "xroot" ]; then
52 echo "-- Do not run vncserver as root!"
55 VNCUSERARGS="${VNCSERVERARGS[${DISP}]}"
56 USEREXISTS=`cat /etc/passwd | awk -F: "{ if (\"$USER\"==\\\$1) print \"yes\" }"`
57 if [ "x$USEREXISTS" != "xyes" ]; then
59 echo "-- User $USER does not exists!"
62 USERHOME=`runuser $USER -c 'echo $HOME'`
63 if [ ! -f "$USERHOME/.vnc/passwd" ]; then
65 echo "-- No password file found for user $USER!"
68 export USER VNCUSERARGS
69 daemon --user ${USER} "vncserver :${DISP} ${VNCUSERARGS}"
71 [ "$RETVAL" -eq 0 ] && echo $display >> /var/lock/subsys/vncserver && continue
74 msg_already_running vncserver
79 if [ -f /var/lock/subsys/vncserver ]; then
82 for display in `cat /var/lock/subsys/vncserver`
84 msg_stopping "vncserver ($display)"
85 export USER="${display##*:}"
86 runuser ${USER} -c "vncserver -kill :${display%%:*}" >/dev/null 2>&1
88 [ "$RETVAL" -eq 0 ] && ok && continue
90 ERRDISP="$ERRDISP $display"
92 rm -f /var/lock/subsys/vncserver
93 [ "x$ERRDISP" != "x" ] && echo "$ERRDISP" > /var/lock/subsys/vncserver
95 msg_not_running vncserver
100 # See how we were called.
119 msg_usage "$0 {start|stop|restart|status}"
125 # This must be last line !