]> git.pld-linux.org Git - packages/tigervnc.git/blob - vncserver.init
- vncserver.{init,sysconfig) from vnc package
[packages/tigervnc.git] / vncserver.init
1 #!/bin/sh
2 #
3 # vncserver     Starts/stop VNC server
4 #
5 # chkconfig:    345 91 35
6 #
7 # description:  Starts and stops vncserver.
8 #               Used to provide remote X administration services.
9 #
10 # $Id$
11
12 # Source function library
13 . /etc/rc.d/init.d/functions
14
15 # Get network config
16 . /etc/sysconfig/network
17
18 VNCSERVERS=""
19 [ -f /etc/sysconfig/vncserver ] && . /etc/sysconfig/vncserver
20
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
25                 exit 1
26         fi
27 else
28         exit 0
29 fi
30
31 start() {
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
35                 RETVAL=0
36
37                 if [ ! -d /tmp/.X11-unix ]
38                 then
39                         mkdir -m 1777 /tmp/.X11-unix || :
40                         restorecon /tmp/.X11-unix 2>/dev/null || :
41                 fi
42
43                 NOSERV=1
44                 for display in $VNCSERVERS
45                 do
46                         msg_starting "vncserver ($display)"
47                         NOSERV=0
48                         DISP="${display%%:*}"
49                         USER="${display##*:}"
50                         if [ "x$USER" == "xroot" ]; then
51                             fail
52                             echo "-- Do not run vncserver as root!"
53                             continue
54                         fi
55                         VNCUSERARGS="${VNCSERVERARGS[${DISP}]}"
56                         USEREXISTS=`cat /etc/passwd | awk -F: "{ if (\"$USER\"==\\\$1) print \"yes\" }"`
57                         if [ "x$USEREXISTS" != "xyes" ]; then
58                             fail
59                             echo "-- User $USER does not exists!"
60                             continue
61                         fi
62                         USERHOME=`runuser $USER -c 'echo $HOME'`
63                         if [ ! -f "$USERHOME/.vnc/passwd" ]; then
64                             fail
65                             echo "-- No password file found for user $USER!"
66                             continue
67                         fi
68                         export USER VNCUSERARGS
69                         daemon --user ${USER} "vncserver :${DISP} ${VNCUSERARGS}"
70                         RETVAL=$?
71                         [ "$RETVAL" -eq 0 ] && echo $display >> /var/lock/subsys/vncserver && continue
72                 done
73         else
74                 msg_already_running vncserver
75         fi
76 }
77
78 stop() {
79         if [ -f /var/lock/subsys/vncserver ]; then
80                 # Stop daemons.
81                 ERRDISP=""
82                 for display in `cat /var/lock/subsys/vncserver`
83                 do
84                         msg_stopping "vncserver ($display)"
85                         export USER="${display##*:}"
86                         runuser ${USER} -c "vncserver -kill :${display%%:*}" >/dev/null 2>&1
87                         RETVAL=$?
88                         [ "$RETVAL" -eq 0 ] && ok && continue
89                         fail
90                         ERRDISP="$ERRDISP $display"
91                 done
92                 rm -f /var/lock/subsys/vncserver
93                 [ "x$ERRDISP" != "x" ] && echo "$ERRDISP" > /var/lock/subsys/vncserver
94         else
95                 msg_not_running vncserver
96         fi
97 }
98
99 RETVAL=0
100 # See how we were called.
101 case "$1" in
102   start)
103         start
104         ;;
105   stop)
106         stop
107         ;;
108   restart)
109         stop
110         sleep 3s
111         start
112         exit $?
113         ;;
114   status)
115         status Xvnc
116         RETVAL=$?
117         ;;
118   *)
119         msg_usage "$0 {start|stop|restart|status}"
120         exit 3
121 esac
122
123 exit $RETVAL
124
125 # This must be last line !
126 # vi:syntax=sh
This page took 0.047247 seconds and 4 git commands to generate.